From 73c4c183884830e34d3e14d782d0e7605740a884 Mon Sep 17 00:00:00 2001 From: christian Date: Tue, 26 Dec 2023 18:05:59 +0100 Subject: [PATCH] Added mass spawn of entities --- pygame-test.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pygame-test.py b/pygame-test.py index a96971b..9acece6 100644 --- a/pygame-test.py +++ b/pygame-test.py @@ -1,5 +1,6 @@ import pygame import pygame_menu +import random as rnd pygame.init() MAINSCREEN = pygame.display.set_mode((640,480)) @@ -85,7 +86,9 @@ class GameObject(): #print(GameObject.get_rect()) if(self.get_rect().x == GameObject.get_rect().x and self.get_rect().y == GameObject.get_rect().y): """TODO: Hitbox with Objectsize""" - print("Kollision") + + if(pygame.rect.Rect.colliderect(self.__rectobjekt, GameObject.get_rect())): + print("Kollision") pass def remove(self): @@ -94,6 +97,16 @@ class GameObject(): """TODO: Delete obeject function""" +def spawn_entities(x:int): + Objects = list() + for y in range(x): + Objects.append(GameObject("TEST", rnd.randint(1,640), rnd.randint(1,480))) + + for x in Objects: + print(x) + return tuple(Objects) + + object1 = GameObject("Testobject", 50, 50) object2 = GameObject("Testobject2", 100, 100) @@ -101,6 +114,7 @@ background = pygame.surface.Surface((640,480)) x = 360 invert = False +spawned_enteties = spawn_entities(10) #Fenster-Hauptschleife while active == True: MAINSCREEN.fill((255,255,255)) @@ -129,7 +143,11 @@ while active == True: #rect1.move(ballpos_x, ballpos_y) ballpos_x -= 10 - + for y in spawned_enteties: + print(y) + y.draw() + y.move(rnd.randint(1,15)) + object1.draw() object1.move(10) object2.draw()