def move_back(self): x_delta, y_delta = directions.delta(directions.reverse(self.facing)) self.x += x_delta self.y += y_delta
def move(self, direction): self.facing = direction x_delta, y_delta = directions.delta(direction) self.x += x_delta self.y += y_delta
def update(self, display, key): if key == 'RESIZE': display.clear() self.draw_frame(display) self.draw_view(display) return if key == 'DROP': self.log('Drop what? (Directional keys to select.)') self.print_log(display) item = self.player.drop(self.select_item(display)) self.entities.insert(0, item) self.log('You drop the ' + item.name + '.') self.draw_inventory(display) self.print_log(display) return if key == 'EAT': self.log('Eat what? (Directional keys to select.)') self.print_log(display) item = self.select_item(display) if self.player.inventory[item].edible: self.log('You eat the ' + self.player.inventory[item].name + '.') self.player.drop(item) else: self.log('That doesn\'t look very tasty.') self.draw_inventory(display) self.print_log(display) return if key == 'SELECT': tile = self.tilemap.get(self.player.x, self.player.y) for i in self.entities: if i.x == tile.x and i.y == tile.y and i.name != 'player': self.log('You pick up the ' + i.name + '.') self.print_log(display) self.player.pickup(self.entities.pop(self.entities.index(i))) self.draw_inventory(display) return if type(tile) == Wheat: wheat = tile.pick() if wheat != None: self.log('You pick some wheat.') self.print_log(display) self.player.pickup(wheat) self.draw_inventory(display) return self.log('There\'s nothing here to pickup.') self.print_log(display) return if key == 'APPLY': self.log('Apply what? (Directional keys to select.)') self.print_log(display) item = self.player.inventory[self.select_item(display)] self.log('Apply ' + item.name + ' in which direction?') self.print_log(display) direction = directions.from_key(display.get_input()) if direction != directions.INVALID: delta_x, delta_y = directions.delta(direction) tile_x = self.player.x + delta_x tile_y = self.player.y + delta_y for i in self.entities: if i.x == tile_x and i.y == tile_y: if type(i) == Log and type(item) == TinderBox: self.entities.remove(i) self.tilemap.set(tile_x, tile_y, Fire(tile_x, tile_y)) self.draw_tile(tile_x, tile_y, display) self.log('You make a fire') self.print_log(display) break if type(i) == Chicken: if type(item) == Wheat: i.owner = self.player self.log('The chicken happily eats the wheat ' + 'and decides to join you in your ' + 'adventures.') self.print_log(display) else: self.log('The chicken doesn\'t seem to want ' + 'that.') break if type(self.tilemap.get(tile_x, tile_y)) == Fire: if type(item) == Fish: old_name = item.name if item.cook(): self.log('You cook the ' + old_name + ' into ' + item.name) self.draw_inventory(display) else: self.log('Uh, don\'t cook that') self.print_log(display) else: self.log('Uh, that\'s not a direction') self.print_log(display) return direction = directions.from_key(key) if direction != directions.INVALID: self.player.move(direction) tile = self.tilemap.get(self.player.x, self.player.y) if tile.solid: self.player.move_back() if type(tile) == Water: fish = None for i in self.player.inventory: if type(i) == FishingRod: fish = tile.fish() break if fish != None: self.log('You catch a fish!') self.player.inventory.append(fish) else: tile.disturb() self.log('You disturb the water.') if type(tile) == Tree: if tile.chopped == False: has_axe = False log = None for i in self.player.inventory: if type(i) == Axe: has_axe = True break if has_axe: log = tile.chop() self.log('You cut down the tree, and aquire some logs') self.player.pickup(log) else: self.log('It would be very painful to chop down a ' + 'tree with your fist') self.camera.center_on(self.player.x, self.player.y) self.update_and_draw_view(display) self.draw_inventory(display) self.print_log(display) display.flush()
def update(self, display, key): if key == 'RESIZE': display.clear() self.draw_frame(display) self.draw_view(display) return if key == 'DROP': self.log('Drop what? (Directional keys to select.)') self.print_log(display) item = self.player.drop(self.select_item(display)) self.entities.insert(0, item) self.log('You drop the ' + item.name + '.') self.draw_inventory(display) self.print_log(display) return if key == 'EAT': self.log('Eat what? (Directional keys to select.)') self.print_log(display) item = self.select_item(display) if self.player.inventory[item].edible: self.log('You eat the ' + self.player.inventory[item].name + '.') self.player.drop(item) else: self.log('That doesn\'t look very tasty.') self.draw_inventory(display) self.print_log(display) return if key == 'SELECT': tile = self.tilemap.get(self.player.x, self.player.y) for i in self.entities: if i.x == tile.x and i.y == tile.y and i.name != 'player': self.log('You pick up the ' + i.name + '.') self.print_log(display) self.player.pickup( self.entities.pop(self.entities.index(i))) self.draw_inventory(display) return if type(tile) == Wheat: wheat = tile.pick() if wheat != None: self.log('You pick some wheat.') self.print_log(display) self.player.pickup(wheat) self.draw_inventory(display) return self.log('There\'s nothing here to pickup.') self.print_log(display) return if key == 'APPLY': self.log('Apply what? (Directional keys to select.)') self.print_log(display) item = self.player.inventory[self.select_item(display)] self.log('Apply ' + item.name + ' in which direction?') self.print_log(display) direction = directions.from_key(display.get_input()) if direction != directions.INVALID: delta_x, delta_y = directions.delta(direction) tile_x = self.player.x + delta_x tile_y = self.player.y + delta_y for i in self.entities: if i.x == tile_x and i.y == tile_y: if type(i) == Log and type(item) == TinderBox: self.entities.remove(i) self.tilemap.set(tile_x, tile_y, Fire(tile_x, tile_y)) self.draw_tile(tile_x, tile_y, display) self.log('You make a fire') self.print_log(display) break if type(i) == Chicken: if type(item) == Wheat: i.owner = self.player self.log( 'The chicken happily eats the wheat ' + 'and decides to join you in your ' + 'adventures.') self.print_log(display) else: self.log('The chicken doesn\'t seem to want ' + 'that.') break if type(self.tilemap.get(tile_x, tile_y)) == Fire: if type(item) == Fish: old_name = item.name if item.cook(): self.log('You cook the ' + old_name + ' into ' + item.name) self.draw_inventory(display) else: self.log('Uh, don\'t cook that') self.print_log(display) else: self.log('Uh, that\'s not a direction') self.print_log(display) return direction = directions.from_key(key) if direction != directions.INVALID: self.player.move(direction) tile = self.tilemap.get(self.player.x, self.player.y) if tile.solid: self.player.move_back() if type(tile) == Water: fish = None for i in self.player.inventory: if type(i) == FishingRod: fish = tile.fish() break if fish != None: self.log('You catch a fish!') self.player.inventory.append(fish) else: tile.disturb() self.log('You disturb the water.') if type(tile) == Tree: if tile.chopped == False: has_axe = False log = None for i in self.player.inventory: if type(i) == Axe: has_axe = True break if has_axe: log = tile.chop() self.log('You cut down the tree, and aquire some logs') self.player.pickup(log) else: self.log('It would be very painful to chop down a ' + 'tree with your fist') self.camera.center_on(self.player.x, self.player.y) self.update_and_draw_view(display) self.draw_inventory(display) self.print_log(display) display.flush()