Skip to content

Instantly share code, notes, and snippets.

@neyer
Created September 8, 2014 01:13
Show Gist options
  • Select an option

  • Save neyer/c00ae9e11b530da02973 to your computer and use it in GitHub Desktop.

Select an option

Save neyer/c00ae9e11b530da02973 to your computer and use it in GitHub Desktop.
bad lava flow code
def check_for_flow(self):
if self.terrain_type == 'grass':
return False
neighbors = engine.metagrid.get_neighbors(self.pos)
did_flow = False
for direction in ORDINALS:
these_neighbors = neighbors.get(direction) or {}
ground_neighbor = these_neighbors.get(LAYER_GROUND)
block_neighbor = these_neighbors.get(LAYER_BLOCKS)
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:
did_flow = True
elif not isinstance(block_neighbor, LavaStopper):
did_flow = 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 did_flow:
if engine.game.stage == 'receding':
self.terrain_type = 'grass'
self.update_tex()
ground_neighbor.handle_lava_flow()
return did_flow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment