Changeset 281:9b56e954c674
- Timestamp:
- 09/05/13 13:58:24 (9 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
data/levels/level1
r263 r281 31 31 name: both_switches 32 32 - args: 33 - [400, 400]34 - level235 - [900, 200]36 - 037 classname: Door38 - args:39 - [600, 200]40 - level141 - [600, 700]42 - 043 - door_switch44 classname: Door45 name: switch_door46 - args:47 33 - [620, 220] 48 34 - door_switch … … 59 45 classname: Bulkhead 60 46 name: switch_bulkhead 47 - args: 48 - [410, 400] 49 - level2 50 - [900, 200] 51 - 0 52 classname: Door 53 - args: 54 - [561, 250] 55 - level1 56 - [600, 700] 57 - 0 58 - door_switch 59 classname: Door 60 name: switch_door 61 61 lines: 62 62 - - [750, 680] -
nagslang/constants.py
r269 r281 36 36 ] 37 37 38 NON_GAME_OBJECT_COLLIDERS = [ 39 # These collision types are excluded from action checks, etc. 40 COLLISION_TYPE_WALL, 41 COLLISION_TYPE_PROJECTILE, 42 COLLISION_TYPE_WEREWOLF_ATTACK, 43 ] 44 38 45 ZORDER_FLOOR = 0 39 46 ZORDER_LOW = 1 -
nagslang/environment.py
r32 r281 75 75 76 76 77 class PuzzleStateCondition(ProtagonistCondition): 78 """Condition that is met if the provided function returns `True`. 79 """ 80 def __init__(self, puzzler): 81 self.puzzler = puzzler 82 83 def check(self, protagonist): 84 return self.puzzler.get_state() 85 86 77 87 class Action(object): 78 88 """Representation of an action that can be performed. 79 89 80 90 If the (optional) condition is met, the provided function will be called 81 with the protagonist and the target as parameters. 91 with the protagonist as a parameter. It is assumed that the function 92 already knows about the target. 82 93 """ 83 94 def __init__(self, func, condition=None): … … 90 101 return self.condition.check(protagonist) 91 102 92 def perform(self, protagonist , target):103 def perform(self, protagonist): 93 104 if not self.check(protagonist): 94 105 raise ValueError("Attempt to perform invalid action.") 95 return self.func(protagonist , target)106 return self.func(protagonist) 96 107 97 108 … … 103 114 self.actions = actions 104 115 116 def set_game_object(self, game_object): 117 self.game_object = game_object 118 105 119 def select_action(self, protagonist): 106 120 """Select a possible action given the protagonist's state. -
nagslang/game_object.py
r276 r281 4 4 import math 5 5 6 from nagslang import environment 6 7 from nagslang import puzzle 7 8 from nagslang import render … … 106 107 is_moving = False # `True` if a movement animation should play. 107 108 108 def __init__(self, physicser, renderer, puzzler=None, overlay=None): 109 def __init__(self, physicser, renderer, puzzler=None, overlay=None, 110 interactible=None): 109 111 self.physicser = physicser 110 112 physicser.set_game_object(self) … … 118 120 if overlay is not None: 119 121 self.overlay.set_game_object(self) 122 self.interactible = interactible 123 if interactible is not None: 124 self.interactible.set_game_object(self) 120 125 121 126 def get_space(self): … … 245 250 key_state=None): 246 251 body = make_body(pymunk.inf, pymunk.inf, position, damping=0.5) 247 self.shape = pymunk.Poly( 248 body, [(-4, -30), (4, -30), (4, 30), (-4, 30)]) 252 self.shape = pymunk.Circle(body, 30) 249 253 self.shape.collision_type = COLLISION_TYPE_DOOR 250 254 self.shape.body.angle = float(angle) / 180 * math.pi … … 252 256 self.destination = destination 253 257 self.dest_pos = tuple(dest_pos) 254 if key_state is None:255 puzzler = puzzle.YesPuzzler()256 else:258 puzzler = None 259 action = environment.Action(self._post_door_event) 260 if key_state is not None: 257 261 puzzler = puzzle.StateProxyPuzzler(key_state) 262 action.condition = environment.PuzzleStateCondition(puzzler) 258 263 super(Door, self).__init__( 259 264 SingleShapePhysicser(space, self.shape), 260 265 render.ImageRenderer(resources.get_image('objects', 'door.png')), 261 266 puzzler, 262 )263 264 def collide_with_protagonist(self, protagonist): 265 if self.puzzler.get_state():266 267 interactible=environment.Interactible(action), 268 ) 269 270 def _post_door_event(self, protagonist): 271 DoorEvent.post(self.destination, self.dest_pos) 267 272 268 273 @classmethod -
nagslang/protagonist.py
r277 r281 4 4 5 5 from nagslang import render 6 from nagslang.constants import COLLISION_TYPE_PLAYER, ZORDER_MID, \ 7 WEREWOLF_SOAK_FACTOR, PROTAGONIST_HEALTH_MIN_LEVEL, \ 8 PROTAGONIST_HEALTH_MAX_LEVEL 6 from nagslang.constants import ( 7 COLLISION_TYPE_PLAYER, ZORDER_MID, WEREWOLF_SOAK_FACTOR, 8 PROTAGONIST_HEALTH_MIN_LEVEL, PROTAGONIST_HEALTH_MAX_LEVEL, 9 NON_GAME_OBJECT_COLLIDERS) 9 10 from nagslang.events import FireEvent 10 11 from nagslang.game_object import GameObject, Physicser, make_body … … 217 218 self.go_werewolf() 218 219 219 def act_on(self, target): 220 def get_current_interactible(self): 221 for shape in self.get_space().shape_query(self.get_shape()): 222 if shape.collision_type in NON_GAME_OBJECT_COLLIDERS: 223 # No game object here. 224 continue 225 interactible = shape.physicser.game_object.interactible 226 if interactible is not None: 227 return interactible 228 return None 229 230 def perform_action(self): 220 231 """Perform an action on the target. 221 232 """ 222 # TODO: Decide how best to do this. 223 pass 233 interactible = self.get_current_interactible() 234 if interactible is None: 235 # Nothing to interact with. 236 return 237 action = interactible.select_action(self) 238 if action is None: 239 # Nothing to do with it. 240 return 241 return action.perform(self) 224 242 225 243 def attack(self): -
nagslang/screens/area.py
r279 r281 130 130 self.protagonist.toggle_form() 131 131 self.world.transformations += 1 132 if ev.key == pygame.locals.K_ SPACE:132 if ev.key == pygame.locals.K_z: 133 133 self.world.attacks += 1 134 134 self.protagonist.attack() 135 if ev.key == pygame.locals.K_SPACE: 136 self.protagonist.perform_action() 135 137 elif DoorEvent.matches(ev): 136 138 self.protagonist.set_position(ev.dest_pos)
Note:
See TracChangeset
for help on using the changeset viewer.