--- /dev/null
+# A doors / keypads set
+
+from ..roaches import default_roaches, WorldRoach
+
+
+def get_friendly_roach(x, y):
+ roach = default_roaches.assemble(WorldRoach())
+ roach.anchor = (0, 0)
+ roach.game_pos = (x, y)
+ return roach
self.grates = []
self.tileset = None
self.start_pos = (0, 0)
+ self.enemies = []
+ self.friends = []
def get_neighbors(self, x, y):
# 4 -connected neighbors
for keypad in self.keypads:
if (x, y) == keypad.game_pos:
keypad.activate(roaches)
+
+ def get_friends(self):
+ return self._friends[:]
+
+ def is_on_friend(self, x, y):
+ return (x, y) in [x.game_pos for x in self.friends]
+
+ def remove_friend(self, x, y):
+ for friend in self.friends[:]:
+ if friend.game_pos == (x, y):
+ self.friends.remove(friend)
+ return friend
+ return None
]
],
"tileset": "bunker",
- "starting pos": [
- 5,
- 6
- ],
"door_info": [
{
"keypads": [
]
]
}
+ ],
+ "starting pos": [
+ 5,
+ 6
+ ],
+ "friendly roaches": [
+ [
+ 2,
+ 9
+ ],
+ [
+ 2,
+ 3
+ ],
+ [
+ 2,
+ 13
+ ],
+ [
+ 9,
+ 13
+ ],
+ [
+ 21,
+ 8
+ ]
]
}
from ..gamelib.level import Level
from ..gamelib.door import Door
from ..gamelib.keypad import Keypad
+from ..gamelib.friendlyroach import get_friendly_roach
self._level.tiles = level_data['tiles']
self._level.tileset = level_data['tileset']
self._level.start_pos = level_data["starting pos"]
+ self._level.enemies = []
+ self._level.friends = []
# Consistency check, so we can assume things are correct
# in the level renderer
for row, row_data in enumerate(self._level.tiles):
for keypad in door_info['keypads']:
new_keypad = Keypad(keypad[0], keypad[1], doors)
self._level.keypads.append(new_keypad)
+ for pos in level_data['friendly roaches']:
+ roach = get_friendly_roach(pos[0], pos[1])
+ self._level.friends.append(roach)
return self._level
def _load_tile_images(self):
self._app = app
self._scene = scene
self._world = world
+ self._update_vehicle = False
def _apply_events(self, events):
if not events:
def move_screen(self, offset):
self._scene.move_screen(offset)
+ def add_roach(self):
+ self._world.add_new_roach()
+
@apply_events
def update(self, dt):
return self._scene.update(self._world.proxy(), self, dt)
ENGINE_METHOD = "move_screen"
+class AddRoachEvent(Event):
+ """ Change to a new scene. """
+
+ ENGINE_METHOD = "add_roach"
+
class Layer:
""" A single layer of actors. """
from pygame import Surface
import pygame.locals as pgl
from ..loaders.levelloader import levels
-from .base import Scene, ChangeSceneEvent, MoveViewportEvent, defer_to_update
+from .base import Scene, ChangeSceneEvent, MoveViewportEvent, AddRoachEvent, defer_to_update
from ..constants import TILE_SIZE, WIDTH, HEIGHT
from ..vehicles.base import Vehicle
+from ..roaches import RoachFactory, WorldRoach
class BaseLevelScene(Scene):
return
super().enter(world)
self._roaches = self.actors.add_layer("roaches", level=10)
+ self._friends = self.actors.add_layer("friendly roaches", level=9)
self._vehicle = Vehicle.current(world)
self._mode = 'walk'
self._angle = 0
self._set_pos(x, y)
self._avatar.pos = (WIDTH // 2, HEIGHT // 2)
self._roaches.add(self._avatar)
+ for friend in self._level.friends:
+ self._friends.add(friend)
# Fix viewport offset
return [
MoveViewportEvent((
def _set_pos(self, x, y):
self._player_pos = (x, y)
+ #print('At ', (x, y))
def _can_move(self, x, y):
if self._mode == 'walk':
def update(self, world, engine, dt):
super().update(world, engine, dt)
events = world.pop_events()
+ for friend in self._friends:
+ friend.pos = self.calc_offset(
+ friend.game_pos[0] * TILE_SIZE, friend.game_pos[1] * TILE_SIZE)
return events
def on_key_down(self, key, mod, unicode):
self._mode = 'walk'
elif self._level.is_keypad(x, y):
self._level.press_keypad(x, y, self._roaches)
+ elif self._level.is_on_friend(x, y):
+ friend = self._level.remove_friend(x, y)
+ self._friends.remove(friend)
+ self._vehicle_changed()
+ return [AddRoachEvent()]
return
elif key == keys.X:
# Fire
from .scenes.base import WorldEvent
+NAMES =[
+ "roupert",
+ "roachel",
+ "roeginald",
+ "roichard",
+ "rory",
+ "roalph",
+ "roabia",
+ "roafi",
+ "roaman",
+ "roemus",
+ "roadley",
+ "roanaell",
+ "roashwan",
+ "roashid",
+ "roaphael",
+ "roenfield",
+ "roani",
+ "roaya",
+ "roaza",
+ "robekka",
+ "rogan",
+ "roiana",
+ "roberta",
+ ]
+
+
class World:
""" World and player state. """
def _build_initial_state(self):
state = {}
state["roaches"] = [
- self._build_roach("roachel", smart=True),
- self._build_roach("roeginald", strong=True),
- self._build_roach("roichard", fast=True),
+ #self._build_roach("roachel", smart=True),
+ #self._build_roach("roeginald", strong=True),
+ #self._build_roach("roichard", fast=True),
self._build_roach("roupert"),
]
state["serums"] = [
def proxy(self):
return WorldDictProxy(self._state)
+ def add_new_roach(self):
+ roach_names = [x['name'] for x in self.roaches]
+ for cand in NAMES:
+ if cand not in roach_names:
+ roach = self._build_roach(cand)
+ self._state['roaches'].append(roach)
+ break
+
def apply_event(self, action, *args, **kw):
if action == "set":
return self._apply_set(*args, **kw)