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/game/game.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/sliceitoff/game') 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