Exemplo n.º 1
0
	def new_game(self, chargeneration=True):
		global rnd, message, player, char, game_state, gametime, worldmap, current_map, savefiles
		cardinal = [-(WORLDMAP_WIDTH - 1), -(WORLDMAP_WIDTH), -(WORLDMAP_WIDTH + 1), -1, 1, WORLDMAP_WIDTH - 1, WORLDMAP_WIDTH, WORLDMAP_WIDTH + 1]
		rnd = libtcod.random_new()
		message = messages.Message()
		player = Player()
		char = mapgen.Object(libtcod.random_get_int(rnd, 40, 80), libtcod.random_get_int(rnd, 26, 46), player.icon, 'player', player.icon_color, blocks=True)
		if chargeneration:
			game_state = chargen.create_character()
		else:
			game_state = chargen.quick_start()
		if game_state == 'playing':
			contents = ['Generating world map...']
			messages.box(None, None, 'center_screenx', 'center_screeny', len(max(contents, key=len)) + 16, len(contents) + 4, contents, input=False, align=libtcod.CENTER, nokeypress=True)
			gametime = Time()
			worldmap = worldgen.World()
			current_map = mapgen.Map('Wilderness', 'WD', 0, (worldmap.player_positiony * WORLDMAP_WIDTH) + worldmap.player_positionx, type=util.find_terrain_type((worldmap.player_positiony * WORLDMAP_WIDTH) + worldmap.player_positionx))
			for i in range(len(border_maps)):
				border_maps[i] = mapgen.Map('Wilderness', 'WD', 0, (worldmap.player_positiony * WORLDMAP_WIDTH) + worldmap.player_positionx + cardinal[i], type=util.find_terrain_type((worldmap.player_positiony * WORLDMAP_WIDTH) + worldmap.player_positionx + cardinal[i]))
			IO.save_game(True)
			savefiles = [f for f in os.listdir('saves') if os.path.isfile(os.path.join('saves', f))]
			util.combine_maps()
			message.new('Welcome to Immortal, ' + player.name + '!', turns, libtcod.Color(96, 212, 238))
			self.play_game()
Exemplo n.º 2
0
	def play_game(self):
		global wm, player_action, draw_gui, player_move
		wm = libtcod.console_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
		game.worldmap.create_map_legend(wm, 3)
		libtcod.console_clear(0)
		util.initialize_fov()
		player_action = ''
		while not libtcod.console_is_window_closed():
			if draw_gui:
				util.render_gui(libtcod.Color(70, 80, 90))
				util.render_message_panel()
				util.render_player_stats_panel()
				draw_gui = False
			util.render_map()
			libtcod.console_flush()

			# player movement
			if not player.is_disabled() and not ('overburdened' in player.flags and turns % 3 == 0):
				player_action = commands.keyboard_commands()
			else:
				player_move = True
			if player_action == 'save':
				IO.save_game()
				break
			if player_action == 'quit':
				death.death_screen(True)
				break
			if player_action == 'exit':
				break

			# let monsters take their turn
			if player_move:
				for obj in reversed(current_map.objects):
					if game_state != 'death':
						if obj.item:
							if obj.item.is_active():
								obj.delete()
							if obj.item.is_expired() or ((turns >= (obj.first_appearance + obj.item.expiration)) and obj.item.expiration > 0):
								obj.delete()
						if obj.entity:
							if not obj.entity.is_disabled():
								obj.x, obj.y = obj.entity.take_turn(obj.x, obj.y)
								if current_map.tile[obj.x][obj.y]['type'] == 'trap' and not obj.entity.is_above_ground() and obj.entity.can_move(obj.x, obj.y):
									if current_map.tile_is_invisible(obj.x, obj.y):
										util.trigger_trap(obj.x, obj.y, obj.entity.article.capitalize() + obj.entity.get_name())
									elif libtcod.map_is_in_fov(fov_map, obj.x, obj.y):
										message.new('The ' + obj.entity.get_name() + ' sidestep the ' + current_map.tile[obj.x][obj.y]['name'] + '.', turns)
							obj.entity.check_condition(obj.x, obj.y)
							if obj.entity.is_dead():
								if libtcod.map_is_in_fov(fov_map, obj.x, obj.y):
									message.new('The ' + obj.entity.get_name() + ' dies!', turns, libtcod.light_orange)
								else:
									message.new('You hear a dying scream.', turns)
								obj.entity.loot(obj.x, obj.y)
								obj.delete()
				if game_state != 'death':
					monsters.spawn()
					effects.check_active_effects()
					util.add_turn()
				player_move = False

			# death screen summary
			if game_state == 'death':
				key = libtcod.Key()
				util.render_map()
				libtcod.console_flush()
				while not key.vk == libtcod.KEY_SPACE:
					libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse(), True)
				death.death_screen()
				player_action = 'exit'
				break