From: Simon Cross Date: Sat, 5 Mar 2016 21:34:08 +0000 (+0200) Subject: Bullets move. X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=ec6ffa9c6a998de15e5f856756a6efb04c00418b;p=koperkapel.git Bullets move. --- diff --git a/koperkapel/gamelib/level.py b/koperkapel/gamelib/level.py index 34487af..cfbf45e 100644 --- a/koperkapel/gamelib/level.py +++ b/koperkapel/gamelib/level.py @@ -46,6 +46,14 @@ class Level(object): def can_crawl(self, x, y, layer): return 'crawl' in self.tiles[y][x][layer]['behaviour'] + def can_bullet(self, x, y, layer): + if self.tiles[y][x][layer]['behaviour']: + for door in self.doors: + if (x, y) == door.game_pos and door.is_closed(): + return False + return True + return False + def is_keypad(self, x, y): for keypad in self.keypads: if (x, y) == keypad.game_pos: diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index 5db95bb..b17beb6 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -199,8 +199,21 @@ class GameLevelScene(BaseLevelScene): if len(self._bullets) >= 10: return bullet.game_pos = pos + bullet.game_dp = dp + bullet.dt = 0 + bullet.level_layer = self._level_layer self._bullets.add(bullet) + def _update_bullet(self, bullet, dt): + bullet.dt += dt + if bullet.dt > 0.1: + bullet.dt = 0 + bullet.game_pos = pos = ( + bullet.game_pos[0] + bullet.game_dp[0], + bullet.game_pos[1] + bullet.game_dp[1]) + if not self._level.can_bullet(pos[0], pos[1], bullet.level_layer): + self._bullets.remove(bullet) + @defer_to_update def _fire_weapon(self, world): weapon = weapon_by_name(world.weapons.current) @@ -235,7 +248,8 @@ class GameLevelScene(BaseLevelScene): for enemy in self._enemies: enemy.pos = self.calc_offset( enemy.game_pos[0] * TILE_SIZE, enemy.game_pos[1] * TILE_SIZE) - for bullet in self._bullets: + for bullet in list(self._bullets): + self._update_bullet(bullet, dt) bullet.pos = self.calc_offset( bullet.game_pos[0] * TILE_SIZE + (TILE_SIZE // 2), bullet.game_pos[1] * TILE_SIZE + (TILE_SIZE // 2))