From eda890d5e6c9524cb030d38c23f468b4e2eb00eb Mon Sep 17 00:00:00 2001 From: Arthur 'Grizzly' Grisel-Davy Date: Wed, 6 May 2020 21:52:10 -0400 Subject: [PATCH] Add text to pause screen and move code --- main.py | 12 +++++------- models.py | 8 ++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 59b5bfd..a3ab373 100644 --- a/main.py +++ b/main.py @@ -32,9 +32,7 @@ RED=(255,0,0) # print(up,right,down,left,pause) -pause_screen = pygame.Surface((screen_width,screen_height)) -pause_screen.set_alpha(128) -pause_screen.fill((255,255,255)) + carte = Carte(n=5) @@ -52,13 +50,13 @@ while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + game.pause = not game.pause keystate = pygame.key.get_pressed() + pygame.mouse.get_pressed() - if keystate[pygame.K_ESCAPE]: - game.pause = not game.pause - if not game.pause: player.check_keys(keystate,screen_width,screen_height,carte,camera) @@ -67,7 +65,7 @@ while not done: game.draw(screen) if game.pause: - screen.blit(pause_screen, (0,0)) + game.draw_pause(screen) pygame.display.flip() diff --git a/models.py b/models.py index d073f98..bd09482 100644 --- a/models.py +++ b/models.py @@ -55,6 +55,14 @@ class Game(): self.camera.draw(surface) self.hud.draw(surface) + def draw_pause(self,surface): + pause_screen = pygame.Surface((surface.get_width(),surface.get_height())) + pause_screen.set_alpha(128) + pause_screen.fill((255,255,255)) + surface.blit(pause_screen, (0,0)) + text = self.hud.font.render(str('...PAUSED...'), True, (255, 255, 255)) + surface.blit(text, (int(surface.get_width()/2-text.get_width()/2),int(0.3*surface.get_height()-text.get_height()/2))) + def get_offset(self): #Return the position of the elements on the screen (camera) return (self.player.posx-self.camera.posx,self.player.posy-self.camera.posy)