diff options
| author | Viljami Ilola <+@hix.fi> | 2024-03-18 12:21:08 +0200 | 
|---|---|---|
| committer | Viljami Ilola <+@hix.fi> | 2024-03-18 12:21:08 +0200 | 
| commit | 0442a8e0836c57418375a1f1f923ba4b9f84d01e (patch) | |
| tree | 79b5521315b198e9a3d0563d16af1e885880f11a /src/sliceitoff | |
| parent | f813de372fe89ff3bc9c34803b99e19cf0de4aac (diff) | |
quit with escape and Q
Diffstat (limited to 'src/sliceitoff')
| -rw-r--r-- | src/sliceitoff/display/static.py | 4 | ||||
| -rw-r--r-- | 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 |