Add text to pause screen and move code
This commit is contained in:
parent
ca7d32cb3e
commit
eda890d5e6
2 changed files with 13 additions and 7 deletions
12
main.py
12
main.py
|
@ -32,9 +32,7 @@ RED=(255,0,0)
|
||||||
# print(up,right,down,left,pause)
|
# 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)
|
carte = Carte(n=5)
|
||||||
|
@ -52,13 +50,13 @@ while not done:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
done = True
|
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()
|
keystate = pygame.key.get_pressed() + pygame.mouse.get_pressed()
|
||||||
|
|
||||||
if keystate[pygame.K_ESCAPE]:
|
|
||||||
game.pause = not game.pause
|
|
||||||
|
|
||||||
if not game.pause:
|
if not game.pause:
|
||||||
player.check_keys(keystate,screen_width,screen_height,carte,camera)
|
player.check_keys(keystate,screen_width,screen_height,carte,camera)
|
||||||
|
|
||||||
|
@ -67,7 +65,7 @@ while not done:
|
||||||
game.draw(screen)
|
game.draw(screen)
|
||||||
|
|
||||||
if game.pause:
|
if game.pause:
|
||||||
screen.blit(pause_screen, (0,0))
|
game.draw_pause(screen)
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,14 @@ class Game():
|
||||||
self.camera.draw(surface)
|
self.camera.draw(surface)
|
||||||
self.hud.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):
|
def get_offset(self):
|
||||||
#Return the position of the elements on the screen (camera)
|
#Return the position of the elements on the screen (camera)
|
||||||
return (self.player.posx-self.camera.posx,self.player.posy-self.camera.posy)
|
return (self.player.posx-self.camera.posx,self.player.posy-self.camera.posy)
|
||||||
|
|
Loading…
Reference in a new issue