Code cleanup

Added some todo's
This commit is contained in:
2024-01-28 21:50:11 +01:00
parent a824390566
commit a3269826bf
3 changed files with 19 additions and 33 deletions

BIN
data/models/player_test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

View File

@@ -2,6 +2,8 @@ import pygame
import random as rand import random as rand
class GameObject(): class GameObject():
"""TODO Install a body array with positions of mainbody and adders"""
_size_rect_x:int _size_rect_x:int
_size_rect_y:int _size_rect_y:int
__movespeed = int() __movespeed = int()

View File

@@ -9,6 +9,7 @@ pygame.init()
MAINSCREEN_SIZE = (1024,768) MAINSCREEN_SIZE = (1024,768)
MAINSCREEN = pygame.display.set_mode(MAINSCREEN_SIZE) MAINSCREEN = pygame.display.set_mode(MAINSCREEN_SIZE)
pygame.display.set_caption("Testgame") pygame.display.set_caption("Testgame")
my_font = pygame.font.SysFont('times new roman', 26)
WEISS = ( 255, 255, 255) WEISS = ( 255, 255, 255)
SCHWARZ = (0,0,0) SCHWARZ = (0,0,0)
@@ -21,6 +22,9 @@ clock = pygame.time.Clock()
#TODO: Make Grid for running Rect #TODO: Make Grid for running Rect
"""TODO: Add new controlstructure for User-class on first login """TODO: Add new controlstructure for User-class on first login
Actually buggy if player logsin the first time, because there is no playerselected before there was an insterquery!!! Actually buggy if player logsin the first time, because there is no playerselected before there was an insterquery!!!
Make a live scoreboard
""" """
#Behandelt später die Hauptschleife und Klassenobjekte #Behandelt später die Hauptschleife und Klassenobjekte
@@ -28,6 +32,8 @@ class Game():
__state = {"win":False, "lose":False, "paused":False} __state = {"win":False, "lose":False, "paused":False}
def __init__(self) -> None: def __init__(self) -> None:
pass pass
def scoreboard(self):
pass
#Handles all collided objects an adds it as playerfollower #Handles all collided objects an adds it as playerfollower
def start_game(): def start_game():
@@ -65,23 +71,21 @@ menu.add.button('Play', start_game)
menu.add.button('Quit', pygame_menu.events.EXIT) menu.add.button('Quit', pygame_menu.events.EXIT)
menu.mainloop(MAINSCREEN) 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))
def spawn_entities(x:int, list_of_objects:list): def spawn_entities(x:int, list_of_objects:list):
count = 0 count = 0
for y in range(x): for y in range(x):
rect_size = 80 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 = 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) 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) list_of_objects.append(Entity)
else:
print("Object zu nach an Spieler")
count += 1 count += 1
player = Player("Player", MAINSCREEN, MAINSCREEN_SIZE, 10, 10, 10, is_player=False, is_rect=True, color=(0,255,0) ,rect_size=(80,80))
goo = GOIMAGE("TESTOBJEKT", MAINSCREEN, MAINSCREEN_SIZE, 0,0,0,image="data/models/testmodel.bmp")
testlist = list()
for y in range(10):
Entity = GOIMAGE("Testobject", MAINSCREEN, MAINSCREEN_SIZE, posx_init=rand.randint(10, 600), posy_init=rand.randint(10, 600), image="data/models/testmodel.bmp")
testlist.append(Entity)
background = pygame.surface.Surface((640,480)) background = pygame.surface.Surface((640,480))
@@ -89,7 +93,7 @@ x = 3600
invert = False invert = False
colided_objects = list() colided_objects = list()
spawned_entities = list() spawned_entities = list()
spawn_entities(150, spawned_entities) spawn_entities(20, spawned_entities)
count_hidden_entities = 0 count_hidden_entities = 0
count_spawend_enities = len(spawned_entities) count_spawend_enities = len(spawned_entities)
print("Es wurden " + str(count_spawend_enities)+ " Objekte gespawnt") print("Es wurden " + str(count_spawend_enities)+ " Objekte gespawnt")
@@ -119,7 +123,8 @@ while active == True:
#print("Keydown") #print("Keydown")
player.change_direction("left") player.change_direction("left")
goo.draw() text_surface = my_font.render('Score: '+str(player.get_player_score()), False, (0, 0, 0))
MAINSCREEN.blit(text_surface, (0,0))
player.draw() player.draw()
player.update_pos_lastframe(player.get_position()[0], player.get_position()[1], False) player.update_pos_lastframe(player.get_position()[0], player.get_position()[1], False)
@@ -144,10 +149,6 @@ while active == True:
append_follwer(xy[0], xy[1]) append_follwer(xy[0], xy[1])
count_follower += 1 count_follower += 1
for t in testlist:
t:GOIMAGE
t.draw()
#Zeichnet alle Verfolgerobjekte, sofern sie vorliegend sind #Zeichnet alle Verfolgerobjekte, sofern sie vorliegend sind
#TODO: Follower sollen ab dem zweiten Objekt dem vorangegangenen Objekt folgen und nicht dem player #TODO: Follower sollen ab dem zweiten Objekt dem vorangegangenen Objekt folgen und nicht dem player
@@ -155,23 +156,6 @@ while active == True:
# colided_objects[0].set_position_player(player.get_position(), player.get_playermovedirection(), True) # colided_objects[0].set_position_player(player.get_position(), player.get_playermovedirection(), True)
i=0 i=0
if(colided_objects):
pass
"""
#TODO:Berechne Position follower Objekte anhand Position aus letztem Frame
for follower in colided_objects:
follower:Block
if(i >= 0):
colided_objects[0].set_position_player(player.get_position(), player.get_playermovedirection(), True)
pass
if(i > 0 and i <= len(colided_objects)):
#colided_objects[i].set_position_player(follower.set_position(colided_objects[i-1].get_position()), player.get_playermovedirection(), True)
pass
follower.draw()
i += 1"""
if(count_hidden_entities == count_spawend_enities): if(count_hidden_entities == count_spawend_enities):
print("WIN!!!") print("WIN!!!")
if(player.get_player_score() > User.gethighscore()): if(player.get_player_score() > User.gethighscore()):
@@ -184,7 +168,7 @@ while active == True:
if(x == 0): if(x == 0):
for y in spawned_entities: for y in spawned_entities:
y.hide() #y.hide()
pass pass
x -= 1 x -= 1
#print("Objekt-Koordinaten= X: "+str(rect1.x)+" Y: "+str(rect1.y)+"", end="\r") #print("Objekt-Koordinaten= X: "+str(rect1.x)+" Y: "+str(rect1.y)+"", end="\r")