Changeset 351:50fce787ae17
- Timestamp:
- 09/06/13 14:13:43 (9 years ago)
- Branch:
- default
- Phase:
- public
- Rebase:
- 62303062623930633863396262326362653038643037653233383765386265366137656566626266
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nagslang/game_object.py
r346 r351 481 481 self.physicser.remove_from_space() 482 482 self.remove = True 483 484 485 class HostileTerrain(GameObject): 486 zorder = ZORDER_FLOOR 487 damage = None 488 tile = None 489 # How often to hit the player 490 rate = 5 491 492 def __init__(self, space, position, outline): 493 body = make_body(10, pymunk.inf, position) 494 # Adjust shape relative to position 495 shape_outline = [(p[0] - position[0], p[1] - position[1]) for 496 p in outline] 497 self.shape = pymunk.Poly(body, shape_outline) 498 self._ticks = 0 499 self.shape.collision_type = COLLISION_TYPE_SWITCH 500 self.shape.sensor = True 501 super(HostileTerrain, self).__init__( 502 SingleShapePhysicser(space, self.shape), 503 render.TiledRenderer(outline, 504 resources.get_image('tiles', self.tile))) 505 506 def collide_with_protagonist(self, protagonist): 507 # We're called every frame we're colliding, so 508 # There are timing issues with stepping on and 509 # off terrian, but as long as the rate is reasonably 510 # low, they shouldn't impact gameplay 511 if self._ticks == 0: 512 protagonist.lose_health(self.damage) 513 self._ticks += 1 514 if self._ticks > self.rate: 515 self._ticks = 0 516 517 @classmethod 518 def requires(cls): 519 return [("name", "string"), ("position", "coordinates"), 520 ("outline", "polygon")] 521 522 523 class AcidFloor(HostileTerrain): 524 damage = 1 525 tile = 'acid.png'
Note:
See TracChangeset
for help on using the changeset viewer.