Skip to content

Instantly share code, notes, and snippets.

@gulnara
Last active December 14, 2015 22:29
Show Gist options
  • Save gulnara/5158829 to your computer and use it in GitHub Desktop.
Save gulnara/5158829 to your computer and use it in GitHub Desktop.
push rocks in the princess_game
class Rock(GameElement):
IMAGE = "Rock"
SOLID = True
def interact(self, player):
del_x = player.x - self.x
del_y = player.y - self.y
next_x = self.x - del_x
next_y = self.y - del_y
existing_el = GAME_BOARD.get_el(next_x, next_y)
if next_x > GAME_WIDTH - 1 or next_x < 1:
return
if next_y > GAME_HEIGHT - 1 or next_y < 1:
return
if existing_el:
existing_el.interact(PLAYER)
if existing_el is None or not existing_el.SOLID:
GAME_BOARD.del_el(self.x, self.y)
GAME_BOARD.set_el(next_x, next_y, self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment