From 98d91824cacec97c581ae0a4f1efd9fa3faa18ab Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Sat, 23 Mar 2024 22:19:00 +0200 Subject: player through SingleGroup --- src/sliceitoff/game/gameplay.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/sliceitoff/game/gameplay.py') diff --git a/src/sliceitoff/game/gameplay.py b/src/sliceitoff/game/gameplay.py index e691b84..12daeaf 100644 --- a/src/sliceitoff/game/gameplay.py +++ b/src/sliceitoff/game/gameplay.py @@ -17,7 +17,18 @@ class Gameplay: self.enemies = enemies def fire(self): - if self.player.fire_lazer(): + hitbox = self.field.slice( + self.player.position, + self.player.direction, + 4_500) + hit = False + if hitbox is not None: + for enemy in self.enemies.sprites(): + if hitbox.colliderect(enemy.rect): + hit = True + break + + if hit: if Stats.lose_life(): return True self.field.kill_if_not_colliding(self.enemies.sprites()) @@ -33,14 +44,14 @@ class Gameplay: for event in pygame.event.get(): match event.type: case pygame.MOUSEMOTION: - self.player.set_position(pygame.mouse.get_pos()) + self.player.update(pos = pygame.mouse.get_pos()) case pygame.MOUSEBUTTONDOWN: - self.player.set_position(pygame.mouse.get_pos()) + self.player.update(pos = pygame.mouse.get_pos()) if event.button == 1: if self.fire(): return True if event.button == 3: - self.player.set_direction() + self.player.update(direction = True) case pygame.KEYDOWN: match event.key: case pygame.K_ESCAPE | pygame.K_q: -- cgit v1.2.3