from ..gamelib.items import clone_old_item
from ..roaches import build_roach
from ..vehicles.base import Vehicle
+from ..weapons import weapon_by_name
class BaseLevelScene(Scene):
self._enemies = self.actors.add_layer("enemies", level=7)
self._vehicle = Vehicle.current(world)
self._mode = 'walk'
- self._angle = 0
+ self._angle = 0 # up
+ self._angle_dp = (0, -1) # up
self._init_items()
self._init_friendly_roaches()
self._init_generators()
elif self._mode == 'crawl':
return self._level.can_crawl(x, y, self._level_layer)
- def _set_angle(self, angle):
+ def _set_angle(self, angle, dp):
self._angle = angle
+ self._angle_dp = dp
self._avatar.angle = angle
@defer_to_update
self._avatar = self._vehicle.get_avatar(world)
self._avatar.pos = (WIDTH // 2, HEIGHT // 2)
self._roaches.add(self._avatar)
- self._set_angle(self._angle)
+ self._set_angle(self._angle, self._angle_dp)
@defer_to_update
def _add_roach(self, world):
self._items.add(clone)
self._vehicle_changed()
+ def _hit_enemy(self, enemy, weapon):
+ enemy.health -= weapon.damage
+ if enemy.health <= 0:
+ self._level.remove_enemy(enemy)
+ self._enemies.remove(enemy)
+
+ @defer_to_update
+ def _fire_weapon(self, world):
+ weapon = weapon_by_name(world.weapons.current)
+ if weapon.bullet_range > 0:
+ # ranged, fire bullet
+ print("Pew.")
+ else:
+ # melee
+ pos, dp = self._player_pos, self._angle_dp
+ pos = (pos[0] + dp[0], pos[1] + dp[1])
+ enemy = self._level.get_enemy(pos[0], pos[1])
+ if enemy:
+ self._hit_enemy(enemy, weapon)
+
@defer_to_update
def _change_vehicle(self, world):
vehicle = Vehicle.random()
if self._can_move(nx, ny):
self._set_pos(nx, ny)
offset = (TILE_SIZE * dp[0], TILE_SIZE * dp[1])
- self._set_angle(angle)
+ self._set_angle(angle, dp)
self._last_key_down = 0
return [MoveViewportEvent(offset)]
else:
# just turn
- self._set_angle(angle)
+ self._set_angle(angle, dp)
def _activate_key(self):
x, y = self._player_pos
def _fire_key(self, dt):
if self._last_key_down > self._key_rate:
self._last_key_down = 0
- print('Boom')
+ self._fire_weapon()
def _vehicle_management_key(self):
from .roach_management import RoachesScene
WEAPON_LOOKUP = {w.name: w for w in WEAPONS}
+def weapon_by_name(weapon_name):
+ return WEAPON_LOOKUP[weapon_name]
+
+
class WeaponActor(AnimatedSurfActor):
def __init__(self, weapon, **kw):
super().__init__(**kw)
def assemble_frame(self, suffix, weapon, tape):
surf = images.load(safepath("weapons/%s%s")
- % (weapon.image_name, suffix))
+ % (weapon.image_name, suffix))
frame = surf.copy()
if tape:
tape_surf = images.load(safepath("weapons/tape"))
return frame
def assemble(self, weapon_name, tape=False):
- weapon = WEAPON_LOOKUP[weapon_name]
+ weapon = weapon_by_name(weapon_name)
tape = tape and weapon.can_tape
frames = [
self.assemble_frame(suffix, weapon, tape)