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:
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)
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))