Code cleanup

Update GameObject class
Added some functions to User class
Updated gameending highscore upload to database
This commit is contained in:
2024-01-07 21:33:13 +01:00
parent 17e258f408
commit c146a58904
3 changed files with 52 additions and 11 deletions

View File

@@ -52,7 +52,7 @@ count_follower = 0
def append_follwer(x,y):
print("x: "+str(x), "y: "+str(y))
newfollower = Follower("Follower "+str(count_follower), MAINSCREEN, MAINSCREEN_SIZE, is_rect=True, rect_size=(x,y))
newfollower = Block("Follower "+str(count_follower), MAINSCREEN, MAINSCREEN_SIZE, is_rect=True, rect_size=(x,y))
colided_objects.append(newfollower)
User = User.User()
@@ -67,7 +67,7 @@ def spawn_entities(x:int, list_of_objects:list):
count = 0
for y in range(x):
rect_size = 60
Entity = GameObject("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)
list_of_objects.append(Entity)
count += 1
@@ -109,13 +109,13 @@ while active == True:
Player.change_direction("left")
Player.draw()
Player.update_pos_lastframe(Player.get_position()[0], Player.get_position()[1], True)
Player.update_pos_lastframe(Player.get_position()[0], Player.get_position()[1], False)
Player.move(5)
print("Aktuelle Position: " + str(Player.get_position()))
#print("Aktuelle Position: " + str(Player.get_position()))
#print("Aktuell kollidierte Objekte: ", str(count_hidden_entities))
#Spawns the Entities
for y in spawned_entities:
y:GameObject
y:Block
y.draw()
if(y.is_collided() == True):
#Der erste Follower folgt dem Spieler, alle übrigen folgen den vorherien Verfolgern
@@ -123,6 +123,9 @@ while active == True:
pass
if(y.is_collided() == False):
if(y.collide(Player)):
print(F"Score: {y.get_score()}")
Player.update_player_score(y.get_score())
print(F"Aktueller Playerscore: {Player.get_player_score()}")
count_hidden_entities += 1
xy = y.get_rect_size()
append_follwer(xy[0], xy[1])
@@ -137,10 +140,10 @@ while active == True:
if(colided_objects):
pass
"""
#TODO:Berechne Position follower Objekte anhand Position aus letztem Frame
for follower in colided_objects:
follower:Follower
follower:Block
if(i >= 0):
colided_objects[0].set_position_player(Player.get_position(), Player.get_playermovedirection(), True)
pass
@@ -148,12 +151,15 @@ while active == True:
#colided_objects[i].set_position_player(follower.set_position(colided_objects[i-1].get_position()), Player.get_playermovedirection(), True)
pass
follower.draw()
i += 1
i += 1"""
if(count_hidden_entities == count_spawend_enities):
print("WIN!!!")
if(Player.get_player_score() > User.gethighscore()):
print("Neuner Highscore!!!")
User.update_user_highscore(Player.get_player_score())
menu.enable()
menu.add.label("WIN", "win", 10)
menu.mainloop(MAINSCREEN)