From 48f534a2be7df6ebeef92b37b055fdaf0077fed6 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 5 Mar 2016 23:54:27 +0200 Subject: [PATCH] Bullets now hit things. --- koperkapel/gamelib/enemy_roach.py | 2 +- koperkapel/scenes/level.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/koperkapel/gamelib/enemy_roach.py b/koperkapel/gamelib/enemy_roach.py index 2e51ef0..90695b3 100644 --- a/koperkapel/gamelib/enemy_roach.py +++ b/koperkapel/gamelib/enemy_roach.py @@ -10,7 +10,7 @@ from ..roaches import t32_roaches, WorldRoach def get_enemy_roach(level): roach = t32_roaches.assemble(WorldRoach(), color=(255, 0, 0, 255)) - roach.anchor = (0, 0) + roach.anchor = (-16, -16) # this should center them on the tile roach.game_pos = (0, 0) roach.health = 5 roach.level = level diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index b17beb6..73573ac 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -204,6 +204,13 @@ class GameLevelScene(BaseLevelScene): bullet.level_layer = self._level_layer self._bullets.add(bullet) + def _check_for_bullet_hits(self): + for bullet in list(self._bullets): + for enemy in list(self._enemies): + if enemy.collidepoint(bullet.pos): + self._hit_enemy(enemy, bullet.weapon) + self._bullets.remove(bullet) + def _update_bullet(self, bullet, dt): bullet.dt += dt if bullet.dt > 0.1: @@ -253,6 +260,7 @@ class GameLevelScene(BaseLevelScene): bullet.pos = self.calc_offset( bullet.game_pos[0] * TILE_SIZE + (TILE_SIZE // 2), bullet.game_pos[1] * TILE_SIZE + (TILE_SIZE // 2)) + self._check_for_bullet_hits() more = self._check_held_keys(dt) if more: events.extend(more) -- 2.34.1