Example #1
0
	def remove_headlamps(self):
		#check for equipped headlamps and remove them
		for i in config.inventory:
			if i.item.headlamp and i.item.equipped:
				i.item.equipped = False
				i.name = i.name.replace(' (equipped)', '')
				config.fov_radius = config.TORCH_RADIUS
				config.beast_fov_radius = config.BEAST_SIGHT_RADIUS
				gfx.render_all()
Example #2
0
	def close_door(self):
		
		self.open = False
		gfx.message('You close the door.', libtcod.white)
		self.owner.char = '+'
		config.map[self.owner.x][self.owner.y].blocked = True
		config.map[self.owner.x][self.owner.y].block_sight = True
		self.owner.name = 'A closed door'
		config.fov_recompute = True
		gfx.render_all()
Example #3
0
	def drop_flare(self):

		flare_component = DroppedFlare()
		dropped_flare = Object(config.player.x, config.player.y, 'f', 'lit signal flare', libtcod.light_blue, flare = flare_component)

		config.objects.append(dropped_flare)
		config.flares.append(dropped_flare)
		config.inventory.remove(self.owner)

		gfx.render_all()
Example #4
0
	def open_door(self):
		
		self.open = True
		gfx.message('You open the door.', libtcod.white)
		self.owner.char = '/'
		config.map[self.owner.x][self.owner.y].blocked = False
		config.map[self.owner.x][self.owner.y].block_sight = False
		self.owner.name = 'An open door'
		self.owner.send_to_back()
		config.fov_recompute = True
		gfx.render_all()
Example #5
0
	def equip_headlamp(self):
		#check for equipped headlamp

		if not self.equipped:
			self.remove_headlamps()
			self.equipped = True
			self.owner.name = self.owner.name + ' (equipped)'
			config.player.fighter.equipheadlamp = self.owner
			config.fov_radius = config.TORCH_RADIUS + 5
			config.beast_fov_radius = config.BEAST_SIGHT_RADIUS + 2
			gfx.render_all()
		else:
			# self.equipped = False
			# self.owner.name = self.owner.name.replace(' (equipped)', '')
			# config.player.fighter.equipheadlamp = None
			self.remove_headlamps()
Example #6
0
	def plant_node(self):
		#drop a node and remove a charge
		#if last charge, remove and destroy item
		
		node_component = PlantedNode()
		planted_node = Object(config.player.x, config.player.y, 'n', 'deployed scanner node', libtcod.light_blue, node = node_component)

		config.objects.append(planted_node)
		config.nodes.append(planted_node)
		
		self.node.charges -= 1
		self.owner.name = 'remote scanner nodes (' + str(self.node.charges) + ')'

		if self.node.charges == 0:
			config.inventory.remove(self.owner)

		gfx.render_all()
Example #7
0
def target_tile(max_range=None):
	global key, mouse
	#return the position of a tile libtcod.LEFT-clicked in config.player's FOV (optionally in a range), or (None, None) if right-clicked.
	while True:
		#render the screen. this erases the config.inventory and shows the names of config.objects under the mouse.
		gfx.render_all()
		libtcod.console_flush()
		
		key = libtcod.console_check_for_keypress()
		mouse = libtcod.mouse_get_status() #get mouse position and click status
		(x, y) = (mouse.cx, mouse.cy)
		
		if (mouse.lbutton_pressed and libtcod.map_is_in_fov(config.fov_map, x, y) and
			(max_range is None or config.player.distance(x, y) <= max_range)):
			return (x, y)
		
		if mouse.rbutton_pressed or key.vk == libtcod.KEY_ESCAPE:
			return (None, None) #cancel if the config.player right-clicked or pressed escape
Example #8
0
def play_game():
	
	player_action = None
	
	key = libtcod.Key()
	mouse = libtcod.Mouse()
	
	while not libtcod.console_is_window_closed():																#MAIN LOOP

		libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS|libtcod.EVENT_MOUSE,key,mouse)
		
		gfx.render_all()
		
		#flush console to screen
		libtcod.console_flush()
		
		#clear object positions
		for object in config.objects:
			object.clear()
		
		player_action = game.handle_keys(key)
		
		if player_action == 'exit':
			save_game()
			break

		if player_action == 'win':
			win_game()
			break

		#let monsters take their turn
		if config.game_state == 'playing' and player_action != 'didnt-take-turn':
			game.handle_time()
			for object in config.objects:
				if object.ai:
					object.ai.take_turn()
Example #9
0
def handle_keys(key):	#handle keyboard commands
	global playerx, playery

	#other functions
	if key.vk == libtcod.KEY_ENTER and key.lalt:
		#Alt+Enter: toggle fullscreen
		libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
	
	elif key.vk == libtcod.KEY_ESCAPE:
		#Escape: exit game
		return 'exit'
	
	#movement keys
	if config.game_state == 'playing':
		
		if key.vk == libtcod.KEY_UP:
			player_move_or_attack(0, -1)
		
		elif key.vk == libtcod.KEY_DOWN:
			player_move_or_attack(0, 1)
		
		elif key.vk == libtcod.KEY_LEFT:
			player_move_or_attack(-1, 0)
		
		elif key.vk == libtcod.KEY_RIGHT:
			player_move_or_attack(1, 0)
		else:
			#test for other keys
			key_char = chr(key.c)
			
			if key_char == 'g':
				#pick up an item
				for object in config.objects: #look for an item in the config.player's tile
					if object.x == config.player.x and object.y == config.player.y:
						if object.item:
							object.item.pick_up()
						elif object.corpse:
							object.corpse.pick_up()
						elif object.bombpart:
							object.bombpart.pick_up()
						break
			
			if key_char == 'i':
				#show the config.inventory
				chosen_item = gfx.inventory_menu('Press the key next to an item to use it, or any other to cancel.\n')
				if chosen_item is not None:
					if chosen_item.armor:
						chosen_item.equip_armor()
					elif chosen_item.weapon:
						chosen_item.equip_weapon()
					elif chosen_item.tank:
						chosen_item.equip_tank()
					elif chosen_item.headlamp:
						chosen_item.equip_headlamp()
					elif chosen_item.camo:
						chosen_item.equip_camo()
					elif chosen_item.node:
						chosen_item.plant_node()
					elif chosen_item.flare:
						chosen_item.drop_flare()
					elif chosen_item.bomb:
						chosen_item.bomb.plant_bomb()
						return 'win'
			
			if key_char == 'd':
				#show the config.inventory; if an item is selected, drop it
				chosen_item = gfx.inventory_menu('Press the key next to an item to (d)rop it, or any other to cancel.\n')
				if chosen_item is not None:
					chosen_item.drop()
			
			if key_char == 'c':
				#show the config.player card until config.player presses 'c' or 'esc'
				gfx.player_card()
			
			if key_char == 'o':
				#search for adjacent doors and open/close them
				for object in config.objects:
					if object.door and object.x <= config.player.x+1 and object.x >= config.player.x-1 and object.y <= config.player.y+1 and object.y >= config.player.y-1:
						if object.door.open:
							object.door.close_door()
						else:
							object.door.open_door()
			
			if key_char == 'p':
				#ping map using scanner
				for i in config.inventory:
					if i.item.scanner and i.item.equipped:
						i.item.scanner.ping(True)
						gfx.message('You pinged the map.', libtcod.white)
						config.fov_recompute = True
						gfx.render_all()
						i.item.scanner.ping(False)
				
			#ascending
			if key_char == ',' or key_char == '<':
				#move up a floor
				#check if on staircase
				for object in config.objects:
					if object.stairs and config.player.x == object.x and config.player.y == object.y:
						#config.player is on stairs
						if object.stairs.direction == "up":
							if config.current_floor==0:
								gfx.message('There is no escape.', libtcod.red)
							else:
								#there's a floor above, so let him ascend
								go_to_floor(config.current_floor-1)
								break
						elif object.stairs.direction == "down":
							#config.player is on downward stairs
							gfx.message('These stairs lead down!', libtcod.red)
							break
			
			#descending
			if key_char == '.' or key_char == '>':
				#move down a floor
				#check if on staircase
				for object in config.objects:
					if object.stairs and config.player.x == object.x and config.player.y == object.y:
						#config.player is on stairs
						if object.stairs.direction == "down":
								go_to_floor(config.current_floor+1)
								break
						elif object.stairs.direction == "up":
							#config.player is on downward stairs
							gfx.message('These stairs lead up!', libtcod.red)
							break
			
			return 'didnt-take-turn'