Skip to content

Instantly share code, notes, and snippets.

@neyer
Last active August 29, 2015 14:06
Show Gist options
  • Save neyer/91bf250037ae218aec29 to your computer and use it in GitHub Desktop.
Save neyer/91bf250037ae218aec29 to your computer and use it in GitHub Desktop.
fixed lava flow check
# fixed way
def check_for_flow(self):
if self.terrain_type == 'grass':
return False
neighbors = engine.metagrid.get_neighbors(self.pos)
flow_dirs = []
for direction in ORDINALS:
these_neighbors = neighbors.get(direction) or {}
ground_neighbor = these_neighbors.get(LAYER_GROUND)
block_neighbor = these_neighbors.get(LAYER_BLOCKS)
flow_this_dir = False
if ground_neighbor and\
ground_neighbor.terrain_type == 'grass' and\
(ground_neighbor.land_height < self.land_height or\
ground_neighbor.land_height <= engine.game.lava_height):
# there is a neighbor next to you, you can pour into them
if not block_neighbor:
flow_this_dir = True
elif not isinstance(block_neighbor, LavaStopper):
flow_this_dir = True
# you can flow!
# kill any player on top
if isinstance(block_neighbor, Player):
block_neighbor.freeze_from_lava()
elif isinstance(block_neighbor, Flammable):
block_neighbor.die()
if flow_this_dir:
if engine.game.stage == 'receding':
self.terrain_type = 'grass'
self.update_tex()
ground_neighbor.handle_lava_flow()
flow_dirs.append(direction)
return flow_dirs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment