Created
September 8, 2014 01:13
-
-
Save neyer/c00ae9e11b530da02973 to your computer and use it in GitHub Desktop.
bad lava flow code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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