Do some changes and tests
This commit is contained in:
@@ -8,7 +8,7 @@ WEISS = ( 255, 255, 255)
|
|||||||
active = True
|
active = True
|
||||||
|
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
#screen.fill(WEISS)
|
|
||||||
|
|
||||||
Testobjekt = {"name":"testobjekt",
|
Testobjekt = {"name":"testobjekt",
|
||||||
"posx":0,
|
"posx":0,
|
||||||
@@ -17,8 +17,33 @@ Testobjekt = {"name":"testobjekt",
|
|||||||
|
|
||||||
# Definieren der Variablen
|
# Definieren der Variablen
|
||||||
ballpos_x = 10
|
ballpos_x = 10
|
||||||
ballpos_y = 30
|
ballpos_y = 10
|
||||||
|
|
||||||
|
class GameObjekt():
|
||||||
|
__name = str()
|
||||||
|
__pos_x = int()
|
||||||
|
__pos_y = int()
|
||||||
|
__rectobjekt = pygame.Rect
|
||||||
|
|
||||||
|
def __init__(self, name:str, posx:int, posy:int, *rect:pygame.Rect) -> None:
|
||||||
|
self.__name = name
|
||||||
|
self.__pos_x = posx
|
||||||
|
self.__pos_y = posy
|
||||||
|
self.__rectobjekt = rect
|
||||||
|
pass
|
||||||
|
|
||||||
|
def move(self, x):
|
||||||
|
MOVE_SPEED = 5
|
||||||
|
#self.__rectobjekt.x += MOVE_SPEED
|
||||||
|
print(self.__rectobjekt)
|
||||||
|
|
||||||
|
|
||||||
|
background = pygame.Surface((640,480)) #Erstellt eine Obfläche mit der Größe des Fensters
|
||||||
|
rect2 = pygame.draw.rect(background,(0,255,255),(20,20,40,40))
|
||||||
|
|
||||||
|
rect1 = pygame.draw.ellipse(screen, (0,0,0), [ballpos_x, ballpos_y, 20, 20])
|
||||||
|
Player = GameObjekt("Test", 0,0,rect1)
|
||||||
|
|
||||||
|
|
||||||
#Fenster-Hauptschleife
|
#Fenster-Hauptschleife
|
||||||
while active == True:
|
while active == True:
|
||||||
@@ -28,29 +53,33 @@ while active == True:
|
|||||||
active = False
|
active = False
|
||||||
elif (event.type == pygame.KEYDOWN):
|
elif (event.type == pygame.KEYDOWN):
|
||||||
if (event.key == pygame.K_UP):
|
if (event.key == pygame.K_UP):
|
||||||
#pygame.draw.rect(screen, (0,0,0), [180,20,100,100],1)
|
|
||||||
#Testobjekt["posx"] +=1
|
|
||||||
print("Keydown")
|
print("Keydown")
|
||||||
|
print(rect2.x)
|
||||||
|
background.get_rect()
|
||||||
|
#rect1.move(ballpos_x, ballpos_y)
|
||||||
|
Player.move(5)
|
||||||
|
ballpos_y -= 10
|
||||||
elif (event.key == pygame.K_DOWN):
|
elif (event.key == pygame.K_DOWN):
|
||||||
print("Keydown")
|
print("Keydown")
|
||||||
|
#rect1.move(ballpos_x, ballpos_y)
|
||||||
|
ballpos_y += 10
|
||||||
elif (event.key == pygame.K_RIGHT):
|
elif (event.key == pygame.K_RIGHT):
|
||||||
print("Keydown")
|
print("Keydown")
|
||||||
|
#rect1.move(ballpos_x, ballpos_y)
|
||||||
|
ballpos_x += 10
|
||||||
elif (event.key == pygame.K_LEFT):
|
elif (event.key == pygame.K_LEFT):
|
||||||
print("Keydown")
|
print("Keydown")
|
||||||
|
#rect1.move(ballpos_x, ballpos_y)
|
||||||
|
ballpos_x -= 10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pygame.draw.ellipse(screen, WEISS, [ballpos_x, ballpos_y, 20, 20])
|
|
||||||
|
|
||||||
# bewegen unseres Kreises
|
|
||||||
ballpos_x += 4
|
|
||||||
ballpos_y += 4
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Displayflip sorgt dafür, dass das Fenster entsprechend der Tickrate aktualisiert wird
|
#Displayflip sorgt dafür, dass das Fenster entsprechend der Tickrate aktualisiert wird
|
||||||
|
#pygame.display.flip()
|
||||||
|
rect2.move(100, 10)
|
||||||
|
screen.blit(background,(0,0))
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
Reference in New Issue
Block a user