Esempio n. 1
0
def ask_direction(action):
	#Ask the player in which direction they want to perform an action.
	render.info('Which direction do you want to ' + action + '?')

	x = data.player.x
	y = data.player.y

	choice_made = False

	while not libtcod.console_is_window_closed() and x == data.player.x and y == data.player.y :
		libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, mouse, True)
		if key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
			y -= 1
		elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
			y += 1
		elif key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_KP4:
			x -= 1
		elif key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_KP6:
			x += 1
		elif key.vk == libtcod.KEY_KP7:
			x -= 1
			y -= 1
		elif key.vk == libtcod.KEY_KP9:
			x += 1
			y -= 1
		elif key.vk == libtcod.KEY_KP1:
			x -= 1
			y += 1
		elif key.vk == libtcod.KEY_KP3:
			x += 1
			y += 1
		elif key.vk == libtcod.KEY_ESCAPE:
			render.message('No direction selected')
			break
	return (x, y)
Esempio n. 2
0
def player_death(mob):
    #Death function for the player.
    #This function ends the game.
    mob.char = '%'
    mob.color = libtcod.dark_red
    mob.blocks = False
    render.message('You have died!', libtcod.dark_red)
    mob.name = 'Remains of ' + mob.name
    data.game_state = 'dead'
Esempio n. 3
0
def player_death(mob):
	#Death function for the player.
	#This function ends the game.
	mob.char = '%'
	mob.color = libtcod.dark_red
	mob.blocks = False
	render.message('You have died!', libtcod.dark_red)
	mob.name = 'Remains of ' + mob.name
	data.game_state = 'dead'
Esempio n. 4
0
def mob_death(mob):
	#Death function for a generic mob.
	mob.char = '%'
	mob.color = libtcod.dark_red
	mob.blocks = False
	mob.creature = None
	mob.item = Item()
	mob.ai = None
	mob.item.owner = mob
	render.message('The ' + mob.name +' has died!')
	mob.name = 'Remains of ' + mob.name
Esempio n. 5
0
def mob_death(mob):
    #Death function for a generic mob.
    mob.char = '%'
    mob.color = libtcod.dark_red
    mob.blocks = False
    mob.creature = None
    mob.item = Item()
    mob.ai = None
    mob.item.owner = mob
    render.message('The ' + mob.name + ' has died!')
    mob.name = 'Remains of ' + mob.name
Esempio n. 6
0
	def drop(self, target):
		self.owner.x = target.x
		self.owner.y = target.y
		self.owner.X = target.X
		self.owner.Y = target.Y
		if self.owner.equipment and self.owner.equipment.is_equipped:
			self.owner.equipment.dequip()
		data.current_area.objects.append(self.owner)
		target.inventory.remove(self.owner)
		self.owner.send_to_back()
		if self.owner.light_map:
			render.initialise_fov()
		render.message('You dropped a ' + self.owner.name + '.', color=libtcod.desaturated_red)
Esempio n. 7
0
 def drop(self, target):
     self.owner.x = target.x
     self.owner.y = target.y
     self.owner.X = target.X
     self.owner.Y = target.Y
     if self.owner.equipment and self.owner.equipment.is_equipped:
         self.owner.equipment.dequip()
     data.current_area.objects.append(self.owner)
     target.inventory.remove(self.owner)
     self.owner.send_to_back()
     if self.owner.light_map:
         render.initialise_fov()
     render.message('You dropped a ' + self.owner.name + '.',
                    color=libtcod.desaturated_red)
Esempio n. 8
0
def ask_direction(action):
    #Ask the player in which direction they want to perform an action.
    render.info('Which direction do you want to ' + action + '?')

    x = data.player.x
    y = data.player.y

    choice_made = False

    while not libtcod.console_is_window_closed(
    ) and x == data.player.x and y == data.player.y:
        libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, mouse, True)
        if key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
            y -= 1
        elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
            y += 1
        elif key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_KP4:
            x -= 1
        elif key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_KP6:
            x += 1
        elif key.vk == libtcod.KEY_KP7:
            x -= 1
            y -= 1
        elif key.vk == libtcod.KEY_KP9:
            x += 1
            y -= 1
        elif key.vk == libtcod.KEY_KP1:
            x -= 1
            y += 1
        elif key.vk == libtcod.KEY_KP3:
            x += 1
            y += 1
        elif key.vk == libtcod.KEY_ESCAPE:
            render.message('No direction selected')
            break
    return (x, y)
Esempio n. 9
0
	def attack(self, target):
		if self.to_hit(target):
			damage = self.strength - target.creature.toughness - 2 + dice(2, 3)

			if damage > 0:
				#Make the target take damage.
				render.message('The ' + self.owner.name + ' attacks the ' + target.name + ' for ' + str(damage) + ' damage.', libtcod.light_green)
				target.creature.take_damage(damage)
			else:
				#Message to let the player know that no damage was done.
				render.message('The ' + self.owner.name + ' attacks the ' + target.name + ' but the blow glances away!', libtcod.light_red)
		else:
			#Message that the attack missed.
			render.message('The ' + self.owner.name + ' attacks the ' + target.name + ' but the shot is parried', libtcod.red)
Esempio n. 10
0
def pinkie_pie():
	img = 'pinkie50x50.png'
	i = talk('Hi there! I\'m Pinkie! What\'s your name?', ['Anon', 'Player', 'Why should I tell you?'], img)

	if i == 0:
		talk('Nice to meet you Anon!', [], img)
		render.message('Pinkie skips away, happily.')

	elif i == 1:
		talk('Tee-hee! That\'s a funny name!', [], img)
		render.message('Pinkie skips away, happily.')

	elif i == 2:
		talk('Why are you such a meanie-pants?', [], img)
		render.message('Pinkie walks away.')
Esempio n. 11
0
    def attack(self, target):
        if self.to_hit(target):
            damage = self.strength - target.creature.toughness - 2 + dice(2, 3)

            if damage > 0:
                #Make the target take damage.
                render.message(
                    'The ' + self.owner.name + ' attacks the ' + target.name +
                    ' for ' + str(damage) + ' damage.', libtcod.light_green)
                target.creature.take_damage(damage)
            else:
                #Message to let the player know that no damage was done.
                render.message(
                    'The ' + self.owner.name + ' attacks the ' + target.name +
                    ' but the blow glances away!', libtcod.light_red)
        else:
            #Message that the attack missed.
            render.message(
                'The ' + self.owner.name + ' attacks the ' + target.name +
                ' but the shot is parried', libtcod.red)
Esempio n. 12
0
def handle_keys():

    global key
    #	if key.vk == libtcod.KEY_ENTER and key.lalt:
    #		#Alt+Enter: toggle fullscreen
    #		libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
    if key.vk == libtcod.KEY_ESCAPE:
        return 'exit'  #exit game

    if data.game_state == 'playing':
        #movement keys
        if key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
            player_move_or_attack(0, -1)
        elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
            player_move_or_attack(0, 1)
        elif key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_KP4:
            player_move_or_attack(-1, 0)
        elif key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_KP6:
            player_move_or_attack(1, 0)
        elif key.vk == libtcod.KEY_KP7:
            player_move_or_attack(-1, -1)
        elif key.vk == libtcod.KEY_KP9:
            player_move_or_attack(1, -1)
        elif key.vk == libtcod.KEY_KP1:
            player_move_or_attack(-1, 1)
        elif key.vk == libtcod.KEY_KP3:
            player_move_or_attack(1, 1)
        elif key.vk == libtcod.KEY_KP5:
            pass  #wait a turn
        else:
            #test for other keys
            key_char = chr(key.c)

            if key_char == 't':
                #[t]est key, currently testing the menu function.
                #				options = multi_objects_menu('pony choice', ['Rarity', 'Applejack', 'Rainbow Dash'], 30)
                #				print options
                #				if option == 0:
                #					print 'Generosity'
                #				elif option == 1:
                #					print 'Honesty'
                #				elif option == 2:
                #					print 'Loyalty'
                #				else: print 'menu error'

                #				for object in data.current_areas.objects:
                #					print object.name + ':'
                #					if object.inventory and len(object.inventory) > 0:
                #						for item in object.inventory:
                #							equipped = ''
                #							if item.equipment and item.equipment.is_equipped:
                #								equipped = ' E'
                #							print item.name + equipped
                #					else:
                #						print object.inventory
                #					print ''

                coords = ask_direction('talk')

                for object in data.current_area.objects:
                    if object.x == coords[0] and object.y == coords[
                            1] and object.talk_function:
                        object.talk_function()

#				print 'Nothing to see here!'

            if key_char == 'g':
                #Picking up / [g]rabbing items.
                for object in data.current_areas.objects:
                    if object.x == data.player.x and object.y == data.player.y and object.item and object != data.player:
                        object.item.pick_up(data.player)

            if key_char == 'i':
                #Showing the inventory and using an item.
                if len(data.inv) > 0:
                    list = []
                    for object in data.inv:
                        equipped = ''
                        if object.equipment:
                            if object.equipment.is_equipped:
                                equipped = ' (Equipped)'
                        list.append(object.name + equipped)
                    to_use = render.menu('Inventory', list)
                    if to_use != None:
                        if data.inv[to_use].item.use_function:
                            data.inv[to_use].item.use_function()
                        else:
                            render.message('You can\'t use that item.')
                else:
                    render.message('You have nothing in your inventory.')

            if key_char == 'd':
                #[d]rop an item.
                if len(data.inv) > 0:
                    list = []
                    for object in data.inv:
                        equipped = ''
                        if object.equipment:
                            if object.equipment.is_equipped:
                                equipped = ' (Equipped)'
                        list.append(object.name + equipped)
                    to_drop = render.menu('Drop Item', list)
                    if to_drop != None:
                        data.inv[to_drop].item.drop(data.player)
                else:
                    render.message('You have nothing to drop.')

            #Multiple-item dropping is disabled until I find a consise and robust way of handling it.


#			if key_char == 'D':
#				#[D]rop multiple items.
#				if len(data.inv) > 0:
#					to_drop = multi_objects_menu('Drop Item', data.inv , 30)
#					if to_drop != None:
#						for object in to_drop:
#							object.item.drop(data.player)
#				else:
#					render.message('You have nothing to drop.')

            if key_char == '<':
                #Go up stairs.
                for object in data.current_areas.objects:
                    if object.stairs and object.x == data.player.x and object.y == data.player.y:
                        object.stairs.go_up(data.player)

            if key_char == '>':
                #Go up stairs.
                for object in data.current_areas.objects:
                    if object.stairs and object.x == data.player.x and object.y == data.player.y:
                        object.stairs.go_down(data.player)

            return 'didnt-take-turn'
Esempio n. 13
0
	def equip(self):
		self.is_equipped = True
		render.message('You equipped the ' + self.owner.name)
Esempio n. 14
0
def handle_keys():
	
	global key
#	if key.vk == libtcod.KEY_ENTER and key.lalt:
#		#Alt+Enter: toggle fullscreen
#		libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
	if key.vk ==libtcod.KEY_ESCAPE:
		return 'exit' #exit game

	if data.game_state == 'playing':
		#movement keys
		if key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
			player_move_or_attack(0, -1)
		elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
			player_move_or_attack(0, 1)
		elif key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_KP4:
			player_move_or_attack(-1, 0)
		elif key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_KP6:
			player_move_or_attack(1, 0)
		elif key.vk == libtcod.KEY_KP7:
			player_move_or_attack(-1, -1)
		elif key.vk == libtcod.KEY_KP9:
			player_move_or_attack(1, -1)
		elif key.vk == libtcod.KEY_KP1:
			player_move_or_attack(-1, 1)
		elif key.vk == libtcod.KEY_KP3:
			player_move_or_attack(1, 1)
		elif key.vk == libtcod.KEY_KP5:
			pass #wait a turn
		else:
			#test for other keys
			key_char = chr(key.c)

			if key_char == 't':
				#[t]est key, currently testing the menu function.
#				options = multi_objects_menu('pony choice', ['Rarity', 'Applejack', 'Rainbow Dash'], 30)
#				print options
#				if option == 0:
#					print 'Generosity'
#				elif option == 1:
#					print 'Honesty'
#				elif option == 2:
#					print 'Loyalty'
#				else: print 'menu error'

#				for object in data.current_areas.objects:
#					print object.name + ':'
#					if object.inventory and len(object.inventory) > 0:
#						for item in object.inventory:
#							equipped = ''
#							if item.equipment and item.equipment.is_equipped:
#								equipped = ' E'
#							print item.name + equipped
#					else:
#						print object.inventory
#					print ''

				coords = ask_direction('talk')

				for object in data.current_area.objects:
					if object.x == coords[0] and object.y == coords[1] and object.talk_function:
						object.talk_function()

#				print 'Nothing to see here!'
	
			if key_char == 'g':
				#Picking up / [g]rabbing items.
				for object in data.current_areas.objects:
					if object.x == data.player.x and object.y == data.player.y and object.item and object != data.player:
						object.item.pick_up(data.player)

			if key_char == 'i':
				#Showing the inventory and using an item.
				if len (data.inv) > 0:
					list = []
					for object in data.inv:
						equipped = ''
						if object.equipment:
							if object.equipment.is_equipped:
								equipped = ' (Equipped)'
						list.append(object.name + equipped)
					to_use = render.menu('Inventory', list)
					if to_use != None:
						if data.inv[to_use].item.use_function:
							data.inv[to_use].item.use_function()
						else:
							render.message('You can\'t use that item.')
				else:
					render.message('You have nothing in your inventory.')

			if key_char == 'd':
				#[d]rop an item.
				if len(data.inv) > 0:
					list = []
					for object in data.inv:
						equipped = ''
						if object.equipment:
							if object.equipment.is_equipped:
								equipped = ' (Equipped)'
						list.append(object.name + equipped)
					to_drop = render.menu('Drop Item', list)
					if to_drop != None:
						data.inv[to_drop].item.drop(data.player)
				else:
					render.message('You have nothing to drop.')

			#Multiple-item dropping is disabled until I find a consise and robust way of handling it.
#			if key_char == 'D':
#				#[D]rop multiple items.
#				if len(data.inv) > 0:
#					to_drop = multi_objects_menu('Drop Item', data.inv , 30)
#					if to_drop != None:
#						for object in to_drop:
#							object.item.drop(data.player)
#				else:
#					render.message('You have nothing to drop.')

			if key_char == '<':
				#Go up stairs.
				for object in data.current_areas.objects:
					if object.stairs and object.x == data.player.x and object.y == data.player.y:
						object.stairs.go_up(data.player)

			if key_char == '>':
				#Go up stairs.
				for object in data.current_areas.objects:
					if object.stairs and object.x == data.player.x and object.y == data.player.y:
						object.stairs.go_down(data.player)

			return 'didnt-take-turn'
Esempio n. 15
0
	def dequip(self):
		self.is_equipped = False
		render.message('You dequipped the ' + self.owner.name)
Esempio n. 16
0
 def pick_up(self, target):
     #Picking up the object.
     target.inventory.append(self.owner)
     data.current_area.objects.remove(self.owner)
     render.message(target.name + ' picked up a ' + self.owner.name + '.',
                    color=libtcod.desaturated_green)
Esempio n. 17
0
 def dequip(self):
     self.is_equipped = False
     render.message('You dequipped the ' + self.owner.name)
Esempio n. 18
0
 def equip(self):
     self.is_equipped = True
     render.message('You equipped the ' + self.owner.name)
Esempio n. 19
0
	def pick_up(self, target):
		#Picking up the object.
		target.inventory.append(self.owner)
		data.current_area.objects.remove(self.owner)
		render.message(target.name + ' picked up a ' + self.owner.name + '.', color=libtcod.desaturated_green)