Code cleanup
Repositioning Scoreboard to center of top
This commit is contained in:
@@ -171,11 +171,13 @@ class Player(GameObject_new):
|
|||||||
) -> None:
|
) -> None:
|
||||||
self._size = size
|
self._size = size
|
||||||
self._score = 0
|
self._score = 0
|
||||||
|
self._rect:pygame.Rect
|
||||||
super().__init__(name, surface, surface_size, init_pos_x, init_pos_y, visibility)
|
super().__init__(name, surface, surface_size, init_pos_x, init_pos_y, visibility)
|
||||||
|
|
||||||
__movedirection = {"up":False, "down":False, "left":False, "right":False}
|
__movedirection = {"up":False, "down":False, "left":False, "right":False}
|
||||||
__snake_body = [[100,100], [100,140], [100,180], [100,220]]
|
__snake_body = [[100,100], [100,140], [100,180], [100,220]]
|
||||||
__test_counter = 0
|
__test_counter = 0
|
||||||
|
|
||||||
|
|
||||||
def user_test_func(self):
|
def user_test_func(self):
|
||||||
pass
|
pass
|
||||||
@@ -231,6 +233,9 @@ class Player(GameObject_new):
|
|||||||
def get_rect_size(self):
|
def get_rect_size(self):
|
||||||
return self._size
|
return self._size
|
||||||
|
|
||||||
|
def get_rect(self) -> pygame.Rect:
|
||||||
|
return self._rect
|
||||||
|
|
||||||
def get_player_score(self) -> int:
|
def get_player_score(self) -> int:
|
||||||
return self._score
|
return self._score
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +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)
|
my_font = pygame.font.SysFont('arial', 26)
|
||||||
|
|
||||||
WEISS = ( 255, 255, 255)
|
WEISS = ( 255, 255, 255)
|
||||||
SCHWARZ = (0,0,0)
|
SCHWARZ = (0,0,0)
|
||||||
@@ -100,11 +100,16 @@ testy = 10
|
|||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
|
|
||||||
|
fruit = GameObject("Fruit", MAINSCREEN, MAINSCREEN_SIZE, posx_init=rand.randint(0, MAINSCREEN_SIZE[0]), posy_init=rand.randint(0, MAINSCREEN_SIZE[1]))
|
||||||
|
|
||||||
#TESTOBJECT = GameObject_new("Testobjekt", MAINSCREEN, MAINSCREEN_SIZE, 0, 0)
|
#TESTOBJECT = GameObject_new("Testobjekt", MAINSCREEN, MAINSCREEN_SIZE, 0, 0)
|
||||||
#print(help(TESTOBJECT))
|
#print(help(TESTOBJECT))
|
||||||
#TESTOBJECT.printall_attributes()
|
#TESTOBJECT.printall_attributes()
|
||||||
|
|
||||||
#Fenster-Hauptschleife+
|
#Fenster-Hauptschleife+
|
||||||
|
|
||||||
|
spawn_fruit = True
|
||||||
|
|
||||||
while active == True:
|
while active == True:
|
||||||
MAINSCREEN.fill((255,255,255))
|
MAINSCREEN.fill((255,255,255))
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
@@ -127,15 +132,21 @@ while active == True:
|
|||||||
player.change_direction("left")
|
player.change_direction("left")
|
||||||
|
|
||||||
text_surface = my_font.render('Score: '+str(player.get_player_score()), False, (0, 0, 0))
|
text_surface = my_font.render('Score: '+str(player.get_player_score()), False, (0, 0, 0))
|
||||||
MAINSCREEN.blit(text_surface, (0,0))
|
MAINSCREEN.blit(text_surface, (MAINSCREEN_SIZE[0]/2-text_surface.get_size()[0]/2,0)) #Paints the Scoreboard in Top/Center
|
||||||
|
|
||||||
|
|
||||||
player.draw()
|
|
||||||
player.move(40)
|
|
||||||
if(counter == 300):
|
if(counter == 300):
|
||||||
player.add_body()
|
player.add_body()
|
||||||
counter = 0
|
counter = 0
|
||||||
|
|
||||||
|
if(fruit.is_collided() == False):
|
||||||
|
fruit.draw()
|
||||||
|
|
||||||
|
|
||||||
|
player.draw()
|
||||||
|
player.move(40)
|
||||||
|
|
||||||
counter += 1
|
counter += 1
|
||||||
#print("Aktuelle Position: " + str(player.get_position()))
|
#print("Aktuelle Position: " + str(player.get_position()))
|
||||||
#print("Aktuell kollidierte Objekte: ", str(count_hidden_entities))
|
#print("Aktuell kollidierte Objekte: ", str(count_hidden_entities))
|
||||||
|
|||||||
Reference in New Issue
Block a user