Esempio n. 1
0
def see_message_log(up=False, down=False):
	if up:
		if game.old_msg < len(game.message.log) - game.MESSAGE_HEIGHT:
			game.old_msg += 1
	if down:
		if game.old_msg > 0:
			game.old_msg -= 1
	util.render_message_panel()
	libtcod.console_flush()
Esempio n. 2
0
	def new(self, new_msg, turn, color=libtcod.white):
		#split the message if necessary, among multiple lines
		new_msg_lines = textwrap.wrap(new_msg, game.MESSAGE_WIDTH - 2)

		for line in new_msg_lines:
			#if the buffer is full, remove the first line to make room for the new one
			if len(self.log) == 15:  # game.MESSAGE_HEIGHT:
				del self.log[0]

			#add the new line as a tuple, with the text and the color
			self.log.append((line, color, turn))
			if len(self.history) == game.setting_history:
				del self.history[0]
			self.history.append((line, color, turn))
		game.old_msg = 0
		util.render_message_panel()
Esempio n. 3
0
def look():
	game.message.new('Looking... (Arrow keys to move cursor, ESC to exit)', game.turns)
	util.render_map()
	dx = game.char.x - game.curx
	dy = game.char.y - game.cury
	key = libtcod.Key()

	while not libtcod.console_is_window_closed():
		libtcod.console_set_default_background(0, libtcod.white)
		libtcod.console_rect(0, game.MAP_X + dx, dy + 1, 1, 1, False, libtcod.BKGND_SET)
		libtcod.console_flush()
		text = ""

		libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse(), True)
		dx, dy = key_check(key, dx, dy)
		if key.vk == libtcod.KEY_ESCAPE:
			del game.message.log[len(game.message.log) - 1]
			util.render_message_panel()
			break

		if dx < 0:
			dx = 0
		if dy < 0:
			dy = 0
		if dx == game.MAP_WIDTH:
			dx -= 1
		if dy == game.MAP_HEIGHT:
			dy -= 1
		px = dx + game.curx
		py = dy + game.cury

		# create a list with the names of all objects at the cursor coordinates
		if dx in range(game.MAP_WIDTH - 1) and dy in range(game.MAP_HEIGHT - 1) and game.current_map.tile_is_explored(px, py):
			names = [obj for obj in game.current_map.objects if obj.x == px and obj.y == py]
			prefix = 'you see '
			if not libtcod.map_is_in_fov(game.fov_map, px, py):
				prefix = 'you remember seeing '
				for i in range(len(names) - 1, -1, -1):
					if names[i].entity is not None:
						names.pop(i)
			if (px, py) == (game.char.x, game.char.y):
				text = 'you see yourself'
			elif names == []:
				if game.current_map.tile_is_invisible(px, py):
					text = prefix + 'a floor'
				else:
					text = prefix + game.current_map.tile[px][py]['article'] + game.current_map.tile[px][py]['name']
			elif len(names) > 1:
				text = prefix
				for i in range(len(names)):
					if i == len(names) - 1:
						text += ' and '
					elif i > 0:
						text += ', '
					if names[i].item is not None:
						text += names[i].item.get_name(True)
					if names[i].entity is not None:
						text += names[i].entity.get_name(True)
			else:
				if names[0].item is not None:
					text = prefix + names[0].item.get_name(True)
				if names[0].entity is not None:
					text = prefix + names[0].entity.get_name(True)

		libtcod.console_set_default_foreground(game.con, libtcod.light_yellow)
		libtcod.console_rect(game.con, 0, 0, game.MAP_WIDTH, 2, True, libtcod.BKGND_NONE)
		libtcod.console_print_rect(game.con, 0, 0, game.MAP_WIDTH - 18, game.MAP_HEIGHT, text)
		libtcod.console_blit(game.con, 0, 0, game.MAP_WIDTH, game.MAP_HEIGHT, 0, game.MAP_X, game.MAP_Y)
	game.draw_map = True
Esempio n. 4
0
def attack():
	game.message.new('Attack... (Arrow keys to move cursor, TAB to cycle targets, ENTER to attack, ESC to exit)', game.turns)
	util.render_map()
	key = libtcod.Key()
	dx = game.char.x - game.curx
	dy = game.char.y - game.cury
	possible_targets = [obj for obj in game.current_map.objects if libtcod.map_is_in_fov(game.fov_map, obj.x, obj.y) and obj.entity]
	target = None
	ranged = False
	pt = 0

	while not libtcod.console_is_window_closed():
		libtcod.console_set_default_background(0, libtcod.white)
		libtcod.console_rect(0, game.MAP_X + dx, dy + 1, 1, 1, False, libtcod.BKGND_SET)
		libtcod.console_flush()
		libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse(), True)
		dx, dy = key_check(key, dx, dy)
		if key.vk == libtcod.KEY_ESCAPE:
			del game.message.log[len(game.message.log) - 1]
			del game.message.log[len(game.message.log) - 1]
			util.render_message_panel()
			break

		if dx < 0:
			dx = 0
		if dy < 0:
			dy = 0
		if dx == game.MAP_WIDTH:
			dx -= 1
		if dy == game.MAP_HEIGHT:
			dy -= 1
		px = dx + game.curx
		py = dy + game.cury

		if key.vk == libtcod.KEY_ENTER:
			if not game.current_map.tile_is_explored(px, py):
				game.message.new("You can't fight darkness.", game.turns)
			else:
				target = [obj for obj in game.current_map.objects if obj.y == py and obj.x == px and obj.entity]
				if not target:
					game.message.new('There is no one here.', game.turns)
				elif abs(px - game.char.x) > 1 or abs(py - game.char.y) > 1:
					if (abs(px - game.char.x) == 2 and abs(py - game.char.y) <= 2) or (abs(py - game.char.y) == 2 and abs(px - game.char.x) <= 2) and game.player.skills[game.player.find_weapon_type()].name == 'Polearm':
						break
					elif game.player.skills[game.player.find_weapon_type()].name not in ['Bow', 'Missile']:
						game.message.new('Target is out of range.', game.turns)
						target = []
					else:
						ranged = True
			break

		if key.vk == libtcod.KEY_TAB:
			if possible_targets:
				pt += 1
				if pt == len(possible_targets):
					pt = 0
				dx = possible_targets[pt].x - game.curx
				dy = possible_targets[pt].y - game.cury

		libtcod.console_set_default_foreground(game.con, libtcod.white)
		libtcod.console_set_default_background(game.con, libtcod.black)
		libtcod.console_rect(game.con, 0, 0, game.MAP_WIDTH, 1, True, libtcod.BKGND_SET)
		libtcod.console_blit(game.con, 0, 0, game.MAP_WIDTH, game.MAP_HEIGHT, 0, game.MAP_X, game.MAP_Y)
	if target:
		game.player.attack(target[0], ranged)
Esempio n. 5
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