diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-23 22:19:00 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-23 22:19:00 +0200 |
commit | 98d91824cacec97c581ae0a4f1efd9fa3faa18ab (patch) | |
tree | 88396d13a6d8449968e305bae443d8f2c5b61cfb /src/sliceitoff/game | |
parent | 947df85053af2704ce1a17daf1fab13e273f0cc5 (diff) |
player through SingleGroup
Diffstat (limited to 'src/sliceitoff/game')
-rw-r--r-- | src/sliceitoff/game/gameplay.py | 19 | ||||
-rw-r--r-- | src/sliceitoff/game/level.py | 19 | ||||
-rw-r--r-- | src/sliceitoff/game/show.py | 2 |
3 files changed, 30 insertions, 10 deletions
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: diff --git a/src/sliceitoff/game/level.py b/src/sliceitoff/game/level.py index 7c58b86..25c34b9 100644 --- a/src/sliceitoff/game/level.py +++ b/src/sliceitoff/game/level.py @@ -1,3 +1,5 @@ +import pygame + from display import Display from status import Status from player import Player @@ -13,9 +15,13 @@ class Level: self.display = display self.status = Status() self.field = Field() - self.enemies = Enemies(field = self.field) - self.player = Player(field = self.field, enemies = self.enemies) - self.gameplay = Gameplay(player = self.player, status = self.status, field = self.field, enemies = self.enemies) + self.enemies = Enemies() + self.player = Player() + self.gameplay = Gameplay( + player = self.player, + status = self.status, + field = self.field, + enemies = self.enemies) self.obj_classes = ( self.status, self.field, @@ -31,10 +37,13 @@ class Level: Stats.update_bonus(dt) self.display.update( ( - self.status.sprites, + self.status, self.field, self.enemies, - self.player.sprites) ) + pygame.sprite.GroupSingle( + sprite = self.player.get_top_sprite()))) + + if self.gameplay.step(): return False diff --git a/src/sliceitoff/game/show.py b/src/sliceitoff/game/show.py index f81c211..c3fe436 100644 --- a/src/sliceitoff/game/show.py +++ b/src/sliceitoff/game/show.py @@ -5,7 +5,7 @@ class Show: """ To show some sprites and quit on any key """ def __init__(self, sprites = []): self.sprites = sprites - self.fadeout = 500 + self.fadeout = 1_000 self.timeout = 5_000 def step(self, dt): |