From 0442a8e0836c57418375a1f1f923ba4b9f84d01e Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Mon, 18 Mar 2024 12:21:08 +0200 Subject: quit with escape and Q --- src/sliceitoff/display/static.py | 4 ++-- src/sliceitoff/game/game.py | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/sliceitoff/display/static.py b/src/sliceitoff/display/static.py index 6e5d0dc..1678994 100644 --- a/src/sliceitoff/display/static.py +++ b/src/sliceitoff/display/static.py @@ -1,2 +1,2 @@ -INTERNAL_WIDTH = 40000 -INTERNAL_HEIGHT = 30000 +INTERNAL_WIDTH = 40_000 +INTERNAL_HEIGHT = 30_000 diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py index 4bce0f0..4a4722b 100644 --- a/src/sliceitoff/game/game.py +++ b/src/sliceitoff/game/game.py @@ -1,4 +1,5 @@ import pygame +from pygame.locals import * class Game: def __init__(self, player = None, field = None): @@ -7,15 +8,20 @@ class Game: def step(self): for event in pygame.event.get(): - if event.type == pygame.QUIT: - return True - if event.type == pygame.MOUSEMOTION: - self.player.set_position(pygame.mouse.get_pos()) - if event.type == pygame.MOUSEBUTTONDOWN: - self.player.set_position(pygame.mouse.get_pos()) - if event.button == 1: - if self.player.fire_lazer(): - return True - if event.button == 3: - self.player.set_direction() + match event.type: + case pygame.KEYDOWN: + match event.key: + case pygame.K_ESCAPE | pygame.K_q: + return True + case pygame.QUIT: + return True + case pygame.MOUSEMOTION: + self.player.set_position(pygame.mouse.get_pos()) + case pygame.MOUSEBUTTONDOWN: + self.player.set_position(pygame.mouse.get_pos()) + if event.button == 1: + if self.player.fire_lazer(): + return True + if event.button == 3: + self.player.set_direction() return False -- cgit v1.2.3