Code cleanup
Update GameObject class Added some functions to User class Updated gameending highscore upload to database
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import pygame
|
||||
import random as rand
|
||||
|
||||
class GameObject():
|
||||
__color = (0,0,0)
|
||||
@@ -13,6 +14,7 @@ class GameObject():
|
||||
__is_player = False
|
||||
__is_rect = False
|
||||
__has_follower = False
|
||||
__score:int
|
||||
count = 0
|
||||
|
||||
__movedirection = {"up":False, "down":False, "left":False, "right":False}
|
||||
@@ -34,6 +36,7 @@ class GameObject():
|
||||
self.__pos_lf_y = 0
|
||||
self.__surface = surface
|
||||
self.__mainscreensize = mainscreensize
|
||||
self.__score = 0
|
||||
|
||||
#self.__rectobjekt = rect
|
||||
|
||||
@@ -133,6 +136,9 @@ class GameObject():
|
||||
def get_playermovedirection(self):
|
||||
return self.__movedirection
|
||||
|
||||
def get_player_score(self) -> int:
|
||||
return self.__score
|
||||
|
||||
def has_follower(self):
|
||||
return self.__has_follower
|
||||
|
||||
@@ -155,6 +161,11 @@ class GameObject():
|
||||
self.__pos_lf_x = x
|
||||
self.__pos_lf_y = y
|
||||
|
||||
def update_player_score(self, score_from_entity):
|
||||
if(score_from_entity > 0):
|
||||
self.__score += score_from_entity
|
||||
|
||||
|
||||
def collide(self, GameObject) -> bool:
|
||||
#print(GameObject)
|
||||
#print(GameObject.get_rect())
|
||||
@@ -175,9 +186,11 @@ class GameObject():
|
||||
|
||||
|
||||
|
||||
class Follower(GameObject):
|
||||
class Block(GameObject):
|
||||
__score = int()
|
||||
def __init__(self, name: str, surface, mainscreensize: tuple, posx_init: int = 0, posy_init: int = 0, move_speed: int = 0, is_player: bool = False, is_rect: bool = True, rect_size: tuple = ...) -> None:
|
||||
super().__init__(name, surface, mainscreensize, posx_init, posy_init, move_speed, is_player, is_rect, rect_size)
|
||||
self.__score = rand.randint(5, 50)
|
||||
|
||||
def set_position_player(self, pos:tuple, playermovedirection:list, debug=False):
|
||||
if(playermovedirection["up"]):
|
||||
@@ -193,4 +206,7 @@ class Follower(GameObject):
|
||||
super().set_position((pos[0]-super().get_rect_size()[0],pos[1]))
|
||||
print(pos)
|
||||
def test(self):
|
||||
print(super().get_position())
|
||||
print(super().get_position())
|
||||
|
||||
def get_score(self) -> int:
|
||||
return self.__score
|
||||
Reference in New Issue
Block a user