Add text to pause screen and move code

This commit is contained in:
grisel-davy 2020-05-06 21:52:10 -04:00
parent ca7d32cb3e
commit eda890d5e6
2 changed files with 13 additions and 7 deletions

12
main.py
View file

@ -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()

View file

@ -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)