Add new Surface / movementarea for Snake
This commit is contained in:
@@ -8,6 +8,9 @@ from modules.GameObject import *
|
||||
pygame.init()
|
||||
MAINSCREEN_SIZE = (1024,768)
|
||||
MAINSCREEN = pygame.display.set_mode(MAINSCREEN_SIZE)
|
||||
|
||||
PLAYGROUND = pygame.Surface((1024,728))
|
||||
|
||||
pygame.display.set_caption("Snake_v1")
|
||||
my_font = pygame.font.SysFont('times new roman', 26)
|
||||
my_font2 = pygame.font.SysFont('times new roman', 32)
|
||||
@@ -75,7 +78,7 @@ menu.add.button('Play', start_game)
|
||||
menu.add.button('Quit', pygame_menu.events.EXIT)
|
||||
menu.mainloop(MAINSCREEN)
|
||||
|
||||
player = Player("Player", MAINSCREEN, MAINSCREEN_SIZE, 100, 100, size=40)
|
||||
player = Player("Player", PLAYGROUND, PLAYGROUND.get_size(), 100, 100, size=40)
|
||||
|
||||
def spawn_entities(x:int, list_of_objects:list):
|
||||
count = 0
|
||||
@@ -124,15 +127,16 @@ while active == True:
|
||||
elif (event.key == pygame.K_LEFT):
|
||||
game_started = True
|
||||
player.change_direction("left")
|
||||
|
||||
|
||||
text_surface_score = my_font.render('Score: '+str(player.get_player_score()), True, (0, 0, 0))
|
||||
text_surface_player = my_font.render("Player: " + User.getusername(), True, SCHWARZ, None)
|
||||
|
||||
PLAYGROUND.fill((255,255,255))
|
||||
|
||||
MAINSCREEN.blit(text_surface_score, (MAINSCREEN_SIZE[0]/2-text_surface_score.get_size()[0]/2,0)) #Paints the Scoreboard in Top/Center
|
||||
MAINSCREEN.blit(text_surface_player, (10, 0))
|
||||
|
||||
if(spawn_fruit == True):
|
||||
fruit = Fruit("Fruit", MAINSCREEN, MAINSCREEN_SIZE, init_pos_x=rand.randint(0, MAINSCREEN_SIZE[0]-40), init_pos_y=rand.randint(0, MAINSCREEN_SIZE[1]-40), color=ROT, rect_size=40, score_points=10)
|
||||
fruit = Fruit("Fruit", PLAYGROUND, PLAYGROUND.get_size(), init_pos_x=rand.randint(0, PLAYGROUND.get_size()[0]-40), init_pos_y=rand.randint(0, PLAYGROUND.get_size()[1]-40), color=ROT, rect_size=40, score_points=10)
|
||||
spawn_fruit = False
|
||||
|
||||
if(fruit):
|
||||
@@ -148,7 +152,7 @@ while active == True:
|
||||
gameovertext = my_font2.render("Game Over!", True, SCHWARZ)
|
||||
if(player.get_player_score() > User.gethighscore()):
|
||||
User.update_user_highscore(player.get_player_score())
|
||||
MAINSCREEN.blit(gameovertext, (MAINSCREEN_SIZE[0]/2-gameovertext.get_size()[0]/2, MAINSCREEN_SIZE[1]/2-gameovertext.get_size()[1]/2))
|
||||
PLAYGROUND.blit(gameovertext, (MAINSCREEN_SIZE[0]/2-gameovertext.get_size()[0]/2, MAINSCREEN_SIZE[1]/2-gameovertext.get_size()[1]/2))
|
||||
|
||||
|
||||
if(player.collide_fruit(fruit.get_rect()) == True and fruit):
|
||||
@@ -167,7 +171,9 @@ while active == True:
|
||||
|
||||
#Displayflip sorgt dafür, dass das Fenster entsprechend der Tickrate aktualisiert wird
|
||||
#pygame.display.flip()
|
||||
|
||||
|
||||
MAINSCREEN.blit(PLAYGROUND, (0,40))
|
||||
pygame.display.flip()
|
||||
clock.tick(60)
|
||||
pygame.quit()
|
||||
Reference in New Issue
Block a user