from pygame.constants import BLEND_RGBA_MULT
from .actors.animsurf import AnimatedSurfActor
from .serums import roach_serum_color
+from .util import safepath
NAMES = [
"roupert",
self.frames = 4
def assemble_frame(self, i, color, roach_data, weapon=None):
- roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
- eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
+ roach = images.load(safepath("roach%s/roach_%d") % (self.suffix, i + 1))
+ eyes = images.load(safepath("roach%s/eyes_%d") % (self.suffix, i + 1))
if weapon is None:
frame = roach.copy()
frame.fill(color, None, BLEND_RGBA_MULT)
from ..serums import big_serums, roach_is_serumless, SERUMS
from ..vehicles.base import Vehicle
from .base import Scene, ChangeSceneEvent, defer_to_update
+from ..util import safepath
TOOLBAR_LEFT_X = WIDTH * 3 // 4
def _init_pads(self):
self._roach_pad = self._pad_layer.add(
- Actor("roach_management/roach_pad", anchor=("left", "bottom")))
+ Actor(safepath("roach_management/roach_pad"), anchor=("left", "bottom")))
self._roach_pad.pos = (TOOLBAR_LEFT_X, TOOLBAR_MID_Y)
self._inventory_pad = self._pad_layer.add(
- Actor("roach_management/inventory_pad", anchor=("left", "top")))
+ Actor(safepath("roach_management/inventory_pad"), anchor=("left", "top")))
self._inventory_pad.pos = (TOOLBAR_LEFT_X, TOOLBAR_MID_Y)
def _add_button(self, name, anchor, inset, pos, action):
def _init_buttons(self):
self._button_layer.clear()
self._add_button(
- "roach_management/left_button", ("left", "bottom"), (1, -1),
+ safepath("roach_management/left_button"), ("left", "bottom"), (1, -1),
self._roach_pad.bottomleft, self._roach_left)
self._add_button(
- "roach_management/right_button", ("right", "bottom"), (-1, -1),
+ safepath("roach_management/right_button"), ("right", "bottom"), (-1, -1),
self._roach_pad.bottomright, self._roach_right)
self._add_button(
- "roach_management/left_button", ("left", "bottom"), (1, -1),
+ safepath("roach_management/left_button"), ("left", "bottom"), (1, -1),
self._inventory_pad.bottomleft, self._inventory_left)
self._add_button(
- "roach_management/right_button", ("right", "bottom"), (-1, -1),
+ safepath("roach_management/right_button"), ("right", "bottom"), (-1, -1),
self._inventory_pad.bottomright, self._inventory_right)
self._add_button(
- "roach_management/eject_button", ("right", "top"), (-1, 1),
+ safepath("roach_management/eject_button"), ("right", "top"), (-1, 1),
(TOOLBAR_LEFT_X, TOOLBAR_TOP_Y), self._eject_roach)
def _roach_left(self):
"""Render a level and allow moving the scene"""
-import os
-
from pygame.constants import BLEND_RGBA_MULT
from pgzero.constants import keys
from pgzero.loaders import images
from .level import BaseLevelScene
from .base import MoveViewportEvent
from ..constants import TILE_SIZE
+from ..util import safepath
class ViewLevelScene(BaseLevelScene):
def enter(self, world):
super().enter(world)
# Mark starting position
- self._roach = images.load(os.path.join("roach/roach_1")).copy()
+ self._roach = images.load(safepath("roach/roach_1")).copy()
self._roach.fill((255, 0, 0, 255), None, BLEND_RGBA_MULT)
x = self._level.start_pos[0] * TILE_SIZE
y = self._level.start_pos[1] * TILE_SIZE
from pygame.constants import BLEND_RGBA_MULT
from pygame.transform import rotate
from .actors.surf import SurfActor
+from .util import safepath
SERUMS = ["smart", "fast", "strong"]
def assemble(self, name):
assert name in SERUMS
- puddle = images.load("serum%s/serum" % (self.suffix,))
+ puddle = images.load(safepath("serum%s/serum") % (self.suffix,))
puddle = rotate(puddle, 90 * random.randint(0, 3))
- serum_icon = images.load("serum%s/%s" % (
+ serum_icon = images.load(safepath("serum%s/%s") % (
self.suffix, SERUM_TILENAME_MAP[name],))
frame = puddle.copy()
frame.fill(SERUM_OVERLAY_COLORS[name], None, BLEND_RGBA_MULT)
--- /dev/null
+"""Utility functions"""
+
+import os
+
+def safepath(path):
+ return os.path.join(*path.split("/"))
from ..actors.orientatedsurf import OrientatedSurfActor
from ..actors.animsurf import AnimatedSurfActor
from ..weapons import default_weapons
+from ..util import safepath
class Vehicle:
self.game_pos = (0, 0)
def roach_management_overlay(self):
- return images.load("vehicles/walking/background")
+ return images.load(safepath("vehicles/walking/background"))
def roach_management_frame(self):
if self.overlay_frame_no is None:
return None
- return images.load("vehicle_big/%s_%d" % (
+ return images.load(safepath("vehicle_big/%s_%d") % (
self.vehicle_type, self.overlay_frame_no))
def init_seats(self):
cls.register(Roomba)
def _avatar_frame(self, i, weapon, suffix="_tiles"):
- vehicle = images.load("vehicle%s/%s_%d" % (
+ vehicle = images.load(safepath("vehicle%s/%s_%d") % (
suffix, self.vehicle_type, i + 1))
frame = vehicle.copy()
frame.blit(weapon.surf, (0, 0))
self.vehicle_pos = (pos[0] * vrad, pos[1] * vrad)
def actor(self):
- seat = images.load("vehicles/walking/seat")
+ seat = images.load(safepath("vehicles/walking/seat"))
selected_seat = seat.copy()
selected_seat.fill(
self.vehicle.selected_seat_overlay_color, None, BLEND_RGBA_MULT)
from pgzero.loaders import images
from .actors.animsurf import AnimatedSurfActor
+from .util import safepath
class Weapon:
class WeaponFactory:
def assemble_frame(self, suffix, weapon, tape):
- surf = images.load("weapons/%s%s" % (weapon.image_name, suffix))
+ surf = images.load(safepath("weapons/%s%s")
+ % (weapon.image_name, suffix))
frame = surf.copy()
if tape:
- tape_surf = images.load("weapons/tape")
+ tape_surf = images.load(safepath("weapons/tape"))
frame.blit(tape_surf, (0, 0))
return frame