From: Simon Cross Date: Sat, 5 Mar 2016 21:54:27 +0000 (+0200) Subject: Bullets now hit things. X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=48f534a2be7df6ebeef92b37b055fdaf0077fed6;p=koperkapel.git Bullets now hit things. --- 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)