def change_floor(self, amount): global game_state, level, actors, game_log, player, stairs_up, stairs_down self.store_map() level = level + amount actors = [] actors.append(player) actors.append(stairs_up) actors.append(stairs_down) if not os.path.isfile('l'+str(level)+'.s'): #if new floor is new, make it map.make_map() else: self.restore_map() #else load it if amount > 0: #down player.x = stairs_up.x player.y = stairs_up.y else: player.x = stairs_down.x player.y = stairs_down.y log("you are now at floor", level) log_turn() map.fov_recompute(player.x, player.y) game_state = enum.GameS.IDLE tcod.console_flush()
def load_game(self, file_name='save'): global game_state, actors, game_log, player, stairs_up, stairs_down, level file = shelve.open(file_name, 'r') game_state = file['game_state'] level = file['level'] actors = file['actors'] player = actors[file['player_index']] stairs_up = actors[file['stairs_u_index']] stairs_down = actors[file['stairs_d_index']] game_log = file['game_log'] map.map = file['map'] file.close() map.fov_init() map.fov_recompute(player.x, player.y)
def use(self, wearer, target): d = game.player.ai.choose_direction() if d is None: return False target_x = wearer.x + (d[0] * self.throw) target_y = wearer.y + (d[1] * self.throw) for x in range(target_x-self.radius+1, target_x+self.radius): for y in range(target_y-self.radius+1, target_y+self.radius): if not map.is_wall(x, y) and map.get_distance_coord(target_x, target_y, x, y) < self.radius: s = ent.Smoke(x, y, tcod.random_get_int(0, 0, game.NORMAL_SPEED*5)) game.actors.append(s) map.fov_recompute(game.player.x, game.player.y) game.log(wearer.name,"threw the", self.owner.name) game.log("a really dense gas expands quickly! vision is difficult") if wearer and wearer.container: wearer.container.inventory.remove(self.owner) return True
def use(self, wearer, target): d = game.player.ai.choose_direction() if d is None: return False dist = self.length + wearer.power / 3 tx = wearer.x# + d[0] ty = wearer.y# + d[1] while dist: dist -= 1 tx += d[0] ty += d[1] a = map.get_actor_alive(tx, ty) if (a and a is not wearer) or map.is_blocked(tx, ty): dist = 0 target_x = tx#wearer.x + (d[0] * self.throw) target_y = ty#wearer.y + (d[1] * self.throw) game.log(wearer.name,"threw the", self.owner.name+'!') game.log_turn() game.log('BOOOM!!') game.log_turn() did_hole = False for x in range(target_x-self.radius+1, target_x+self.radius): for y in range(target_y-self.radius+1, target_y+self.radius): if map.is_diggable(x, y): map.set_wall(x, y, False, False) did_hole = True if not map.is_wall(x, y): if map.get_distance_coord(target_x, target_y, x, y) < self.radius: s = ent.Smoke(x, y, tcod.random_get_int(0, 0, game.NORMAL_SPEED*5), was_visible=not map.is_wall(x,y)) game.actors.append(s) s = ent.Projectile(x, y, self.damage, wearer, name='explosion', self_remove=True) game.actors.append(s) if did_hole: game.log("the", self.owner.name, 'made a huge hole in the walls!') map.fov_recompute(game.player.x, game.player.y) if wearer and wearer.container: wearer.container.inventory.remove(self.owner) pass return True
def loop(self): global game_state, key, actors while not tcod.console_is_window_closed(): if game_state == enum.GameS.NEW_TURN: game_state = enum.GameS.IDLE key = tcod.console_check_for_keypress(True) player.take_turn() #different actions will trigger the new turn if game_state == enum.GameS.STAIRS_DOWN: self.change_floor(+1) elif game_state == enum.GameS.STAIRS_UP: self.change_floor(-1) ### turn loop if game_state == enum.GameS.NEW_TURN: player.action_points -= NORMAL_SPEED #player pays its movement while player.action_points < NORMAL_SPEED: #player can't move, party time for object in actors: object.action_points += object.speed while object.action_points >= NORMAL_SPEED: object.update() object.action_points -= NORMAL_SPEED player.action_points += player.speed #refresh actors removing dead things ol = [object for object in actors if not object.remove] actors = ol map.fov_recompute(player.x, player.y) log_turn() if game_state == enum.GameS.DEFEAT: if os.path.isfile('save'): os.remove('save') self.clean_stored_maps() ### end of turn loop draw_all() tcod.console_flush() if key.vk == tcod.KEY_ESCAPE: self.end() if key.vk == tcod.KEY_F5: #debug-quit break
def new_game(self): global game_state, actors, game_log, player, stairs_up, stairs_down, level self.clean_stored_maps() game_state = enum.GameS.STARTUP actors = [] game_log = [] level = 1 player = ent.Player(0,0) stairs_up = ent.Entity(1,2,"<", "upward staircase", blocks=False) stairs_down = ent.Entity(1,2,">", "downward staircase", blocks=False) actors.append(stairs_up) actors.append(stairs_down) actors.append(player) map.make_map() map.fov_recompute(player.x, player.y) stairs_up.x, stairs_up.y = (-1, -1) game_state = enum.GameS.IDLE tcod.console_flush()