diff --git a/pygame-test.py b/pygame-test.py index 9acece6..ed636ea 100644 --- a/pygame-test.py +++ b/pygame-test.py @@ -20,16 +20,18 @@ class GameObject(): __pos_x = int() __pos_y = int() __color = (0,0,0) + __movespeed = int() __rectobjekt = pygame.Rect __surface = MAINSCREEN __removed = False __movedirection = {"up":False, "down":False, "left":False, "right":False} - def __init__(self, name:str, posx_init:int=0, posy_init:int=0) -> None: + def __init__(self, name:str, posx_init:int=0, posy_init:int=0, move_speed:int=0) -> None: self.__name = name self.__pos_x = posx_init self.__pos_y = posy_init + self.__movespeed = move_speed #self.__rectobjekt = rect def __del__(self): @@ -81,6 +83,9 @@ class GameObject(): def get_rect(self): return self.__rectobjekt + def get_movespeed(self): + return self.__movespeed + def collide(self, GameObject): #print(GameObject) #print(GameObject.get_rect()) @@ -100,7 +105,7 @@ class GameObject(): def spawn_entities(x:int): Objects = list() for y in range(x): - Objects.append(GameObject("TEST", rnd.randint(1,640), rnd.randint(1,480))) + Objects.append(GameObject("TEST", rnd.randint(1,640), rnd.randint(1,480), rnd.randint(1,10))) for x in Objects: print(x) @@ -112,9 +117,9 @@ object2 = GameObject("Testobject2", 100, 100) background = pygame.surface.Surface((640,480)) -x = 360 +x = 3600 invert = False -spawned_enteties = spawn_entities(10) +spawned_enteties = spawn_entities(5) #Fenster-Hauptschleife while active == True: MAINSCREEN.fill((255,255,255)) @@ -144,9 +149,8 @@ while active == True: ballpos_x -= 10 for y in spawned_enteties: - print(y) y.draw() - y.move(rnd.randint(1,15)) + y.move(y.get_movespeed()) object1.draw() object1.move(10) @@ -155,7 +159,8 @@ while active == True: object2.collide(object1) if(x == 0): - #object2.remove() + for y in spawned_enteties: + y.remove() pass x -= 1