Rewrite Gameobjects

Added new movementfunction
Code cleanup

Todo: Remove old class and update code for new one
This commit is contained in:
2024-01-29 21:47:43 +01:00
parent a3269826bf
commit 92fd4a4cb2
2 changed files with 96 additions and 49 deletions

View File

@@ -71,7 +71,7 @@ menu.add.button('Play', start_game)
menu.add.button('Quit', pygame_menu.events.EXIT)
menu.mainloop(MAINSCREEN)
player = Player("Player", MAINSCREEN, MAINSCREEN_SIZE, 10, 10, 10, is_player=False, is_rect=True, color=(0,255,0) ,rect_size=(80,80))
player = Player("Player", MAINSCREEN, MAINSCREEN_SIZE, 100, 100, size=40)
def spawn_entities(x:int, list_of_objects:list):
count = 0
@@ -79,10 +79,7 @@ def spawn_entities(x:int, list_of_objects:list):
rect_size = 80
Entity = Block("Entitiy-"+str(count), MAINSCREEN, MAINSCREEN_SIZE, rand.randint(1,MAINSCREEN_SIZE[0]), rand.randint(1,MAINSCREEN_SIZE[1]), rand.randint(1,15), is_rect=True, rect_size=(rect_size,rect_size))
Entity.get_name(True)
if(Entity.get_position() > player.get_position() + player.get_rect_size() or Entity.get_position() < player.get_position() + player.get_rect_size()):
list_of_objects.append(Entity)
else:
print("Object zu nach an Spieler")
list_of_objects.append(Entity)
count += 1
@@ -93,7 +90,7 @@ x = 3600
invert = False
colided_objects = list()
spawned_entities = list()
spawn_entities(20, spawned_entities)
spawn_entities(2, spawned_entities)
count_hidden_entities = 0
count_spawend_enities = len(spawned_entities)
print("Es wurden " + str(count_spawend_enities)+ " Objekte gespawnt")
@@ -101,6 +98,12 @@ print("Es wurden " + str(count_spawend_enities)+ " Objekte gespawnt")
testx = 10
testy = 10
counter = 0
#TESTOBJECT = GameObject_new("Testobjekt", MAINSCREEN, MAINSCREEN_SIZE, 0, 0)
#print(help(TESTOBJECT))
#TESTOBJECT.printall_attributes()
#Fenster-Hauptschleife+
while active == True:
MAINSCREEN.fill((255,255,255))
@@ -126,12 +129,18 @@ while active == True:
text_surface = my_font.render('Score: '+str(player.get_player_score()), False, (0, 0, 0))
MAINSCREEN.blit(text_surface, (0,0))
player.draw()
player.update_pos_lastframe(player.get_position()[0], player.get_position()[1], False)
player.move(5)
player.move(40)
if(counter == 300):
player.add_body()
counter = 0
counter += 1
#print("Aktuelle Position: " + str(player.get_position()))
#print("Aktuell kollidierte Objekte: ", str(count_hidden_entities))
#Spawns the Entities
"""
for y in spawned_entities:
y:Block
y.draw()
@@ -147,7 +156,7 @@ while active == True:
count_hidden_entities += 1
xy = y.get_rect_size()
append_follwer(xy[0], xy[1])
count_follower += 1
count_follower += 1"""
#Zeichnet alle Verfolgerobjekte, sofern sie vorliegend sind
#TODO: Follower sollen ab dem zweiten Objekt dem vorangegangenen Objekt folgen und nicht dem player