Some changes in spawn mechanics

This commit is contained in:
2023-12-26 19:55:24 +01:00
parent 73c4c18388
commit 25068cbb2b

View File

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