Changeset 186:d63c19003aec
- Timestamp:
- 09/03/13 18:06:12 (9 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- nagslang
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
nagslang/constants.py
r176 r186 19 19 SWITCH_PUSHERS = [COLLISION_TYPE_PLAYER, COLLISION_TYPE_BOX] 20 20 21 CALLBACK_COLLIDERS = [ 22 # Collisions between the player and shapes with these collision types will 23 # fire callbacks on the game object associated with the shape. 24 COLLISION_TYPE_SWITCH, 25 COLLISION_TYPE_BOX, 26 COLLISION_TYPE_ENEMY, 27 COLLISION_TYPE_DOOR, 28 ] 29 21 30 ZORDER_FLOOR = 0 22 31 ZORDER_LOW = 1 -
nagslang/events.py
r180 r186 2 2 3 3 import pygame 4 import pygame.locals 4 5 5 6 -
nagslang/game_object.py
r185 r186 42 42 43 43 44 class YesPuzzler(Puzzler): 45 """Yes sir, I'm always on. 46 """ 47 def get_state(self): 48 return True 49 50 51 class NoPuzzler(Puzzler): 52 """No sir, I'm always off. 53 """ 54 def get_state(self): 55 return False 56 57 44 58 class CollidePuzzler(Puzzler): 45 59 def __init__(self, *collision_types): … … 108 122 super(SingleShapePhysicser, self).__init__(space) 109 123 self._shape = shape 124 shape.physicser = self 110 125 111 126 def get_shape(self): … … 342 357 self.renderer.animate() 343 358 359 def collide_with_protagonist(self): 360 """Called as a `pre_solve` collision callback with the protagonist. 361 362 You can return `False` to ignore the collision, anything else 363 (including `None`) to process the collision as normal. 364 """ 365 pass 366 344 367 345 368 class FloorSwitch(GameObject): … … 394 417 zorder = ZORDER_FLOOR 395 418 396 def __init__(self, space, position, destination, dest_pos ):419 def __init__(self, space, position, destination, dest_pos, key_state=None): 397 420 body = make_body(pymunk.inf, pymunk.inf, position, damping=0.5) 398 421 self.shape = pymunk.Poly( … … 402 425 self.destination = destination 403 426 self.dest_pos = tuple(dest_pos) 427 if key_state is None: 428 puzzler = YesPuzzler() 429 else: 430 puzzler = StateProxyPuzzler(key_state) 404 431 super(Door, self).__init__( 405 432 SingleShapePhysicser(space, self.shape), 406 433 ImageRenderer(resources.get_image('objects', 'door.png')), 434 puzzler, 407 435 ) 408 436 -
nagslang/tests/test_game_object.py
r145 r186 44 44 return puzzler 45 45 46 def assert_ floor_switch(self, expected, shapes):46 def assert_collide_state(self, expected, shapes, collision_types): 47 47 gobj = FakeGameObject(None, FakeSpace(*shapes)) 48 puzzler = self.mkpuzzler(gobj, game_object.FloorSwitchPuzzler) 48 puzzler = self.mkpuzzler( 49 gobj, game_object.CollidePuzzler, *collision_types) 49 50 self.assertEqual(expected, puzzler.get_state()) 50 51 51 def test_ floor_switch_puzzler(self):52 self.assert_ floor_switch(False, [])53 self.assert_ floor_switch(False, [FakeShape()])52 def test_collide_puzzler(self): 53 self.assert_collide_state(False, [], []) 54 self.assert_collide_state(False, [FakeShape()], SWITCH_PUSHERS) 54 55 55 56 for collision_type in SWITCH_PUSHERS: 56 self.assert_floor_switch(True, [FakeShape(collision_type)]) 57 self.assert_floor_switch( 58 True, [FakeShape(), FakeShape(collision_type)]) 57 self.assert_collide_state( 58 True, [FakeShape(collision_type)], SWITCH_PUSHERS) 59 self.assert_collide_state( 60 True, [FakeShape(), FakeShape(collision_type)], SWITCH_PUSHERS) 59 61 60 62 def test_state_proxy_puzzler(self): -
nagslang/tests/test_level.py
r164 r186 79 79 isinstance(puzzle_bits['foo_proxy'], go.StateProxyPuzzler)) 80 80 self.assertEqual('foo', puzzle_bits['foo_proxy']._state_source) 81 self.assertTrue(isinstance(puzzle_bits['foo'], 82 go.FloorSwitchPuzzler)) 81 self.assertTrue(isinstance(puzzle_bits['foo'], go.CollidePuzzler)) 83 82 84 83 level = self.make_level('foo', {
Note:
See TracChangeset
for help on using the changeset viewer.