示例#1
0
	def create_map_images(self, mode=0):
		if mode == 0:
			print 'Creating images....'
			t0 = libtcod.sys_elapsed_seconds()
		con = libtcod.console_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
		self.map_image_small = libtcod.image_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
		self.create_map_legend(con, mode)
		libtcod.image_scale(self.map_image_small, (game.SCREEN_WIDTH - 2) * 2, (game.SCREEN_HEIGHT - 2) * 2)

		if mode == 0:
			while self.player_positionx == 0:
				start = self.randomize('int', 0, (game.WORLDMAP_WIDTH * game.WORLDMAP_HEIGHT) - 1, 3)
				if int(self.hm_list[start] * 1000) in range(int(game.terrain['Forest']['elevation'] * 1000), int(game.terrain['Forest']['maxelev'] * 1000)):
					self.player_positionx = start % game.WORLDMAP_WIDTH
					self.player_positiony = start / game.WORLDMAP_WIDTH
					self.originx = self.player_positionx
					self.originy = self.player_positiony

					path = self.set_dijkstra_map()
					for y in range(game.WORLDMAP_HEIGHT):
						for x in range(game.WORLDMAP_WIDTH):
							dist = libtcod.dijkstra_get_distance(path, x, y)
							if dist > self.max_distance:
								self.max_distance = int(round(dist))
					#libtcod.image_put_pixel(self.map_image_small, self.player_positionx, self.player_positiony, libtcod.white)

		if mode == 2:
			self.map_image_big = libtcod.image_from_console(con)
			libtcod.image_save(self.map_image_big, 'maps/worldmap-' + game.player.name + '.png')
			self.map_image_big = None
		libtcod.console_delete(con)
		if mode == 0:
			t1 = libtcod.sys_elapsed_seconds()
			print '    done! (%.3f seconds)' % (t1 - t0)
示例#2
0
def test_image(console, tmpdir):
    img = libtcodpy.image_new(16, 16)
    libtcodpy.image_clear(img, libtcodpy.Color(0, 0, 0))
    libtcodpy.image_invert(img)
    libtcodpy.image_hflip(img)
    libtcodpy.image_rotate90(img)
    libtcodpy.image_vflip(img)
    libtcodpy.image_scale(img, 24, 24)
    libtcodpy.image_set_key_color(img, libtcodpy.Color(255, 255, 255))
    libtcodpy.image_get_alpha(img, 0, 0)
    libtcodpy.image_is_pixel_transparent(img, 0, 0)
    libtcodpy.image_get_size(img)
    libtcodpy.image_get_pixel(img, 0, 0)
    libtcodpy.image_get_mipmap_pixel(img, 0, 0, 1, 1)
    libtcodpy.image_put_pixel(img, 0, 0, libtcodpy.Color(255, 255, 255))
    libtcodpy.image_blit(img, console, 0, 0, libtcodpy.BKGND_SET, 1, 1, 0)
    libtcodpy.image_blit_rect(img, console, 0, 0, 16, 16, libtcodpy.BKGND_SET)
    libtcodpy.image_blit_2x(img, console, 0, 0)
    libtcodpy.image_save(img, tmpdir.join('test.png').strpath)
    libtcodpy.image_delete(img)

    # Not portable.
    #img = libtcodpy.image_from_console(console)
    #libtcodpy.image_refresh_console(img, console)
    #libtcodpy.image_delete(img)

    libtcodpy.image_delete(libtcodpy.image_load('../data/img/circle.png'))
示例#3
0
 def export(self):
     
     print("Exporting world map with dimensions [" + 
             str(self.width) + ',' + str(self.height) + ']');
     con = tcod.console_new(self.width, self.height);
     
     con = self.render(con, True)
     
     bmp = tcod.image_from_console(con)
     tcod.console_delete(con)
     
     date = datetime.datetime.now()
     timestamp = date.strftime("%Y%m%d-%H%M%S")
     
     tcod.image_save(bmp, 'export/WorldMap'+ timestamp + '.png')
     print "Done."
示例#4
0
    def export(self):

        print("Exporting world map with dimensions [" + str(self.width) + ',' +
              str(self.height) + ']')
        con = tcod.console_new(self.width, self.height)

        con = self.render(con, True)

        bmp = tcod.image_from_console(con)
        tcod.console_delete(con)

        date = datetime.datetime.now()
        timestamp = date.strftime("%Y%m%d-%H%M%S")

        tcod.image_save(bmp, 'export/WorldMap' + timestamp + '.png')
        print "Done."
示例#5
0
def on_turn(player):
	key = libtcod.console_wait_for_keypress(True)
	
	# exit the game
	if key.vk == libtcod.KEY_ESCAPE:
		if config.QUICK_START:
			raise game.SetState('quit')
		
		elif ask_confirmation(player, 'Are you sure you want to quit?'):
			if ask_confirmation(player, 'Save the game?  Your old save will be lost.'):
				raise game.SetState(game.save_game)
			
			else:
				raise game.SetState('quit')
		
		else:
			return False
	
	# Move, attack, or interact with a feature
	elif key.vk in DIRECTION_KEYS:
		dx, dy = DIRECTION_KEYS[key.vk]
		i, j = player.x + dx, player.y + dy
		
		feature = player.map.feature_at(i, j)
		actor = player.map.actor_at(i, j)
		
		if player.map.can_place_actor(i, j):
			player.move_to(i, j)
			
			return True
		
		elif actor and actor.faction in ['enemy', 'neutral']:
			return player.melee_attack(actor)
		
		else:
			return feature.interact(player)
	
	# Do nothing for a turn
	elif key.c == ord('.') or key.vk == libtcod.KEY_KP5:
		
		player.energy = min(player.energy + 1, player.max_energy)
		
		return True
	
	# Pick up an item
	elif key.c == ord('g'):
		item = player.map.item_at(player.x, player.y)
		if item is None:
			messages.Basic('There is nothing to pick up here.', '?')
			
			return False
		
		elif len(player.inventory) >= player.inventory_size:
			messages.Basic("You can't pick up the {:s}; your inventory is full.".format(item.name), '?', item)
			
			return False
		
		else:
			player.inventory.add(item)
			player.map.items.remove(item)
			
			item.x, item.y, item.map = None, None, None
			
			# if/when npcs can pick up items, generalize this message
			messages.Basic('You pick up the {:s}.'.format(item.name), player, item)
			
			return True
	
	# Open the inventory
	elif key.c == ord('i'):
		return display_inventory(player)
	
	# Close a door
	elif key.c == ord('c'):
		can_close = []
		
		for (dx, dy) in ADJACENT:
			feature = player.map.feature_at(player.x + dx, player.y + dy)
			
			if feature.is_door and feature.open:
				can_close.append((dx, dy))
		
		if len(can_close) == 0:
			messages.Basic('There is nothing to close here.', '?')
			
			return False
		
		else:
			choice = ask_which_direction(player, 'Close in what direction?', can_close)
			
			if choice is not None:
				return player.map.feature_at(player.x + choice[0], player.y + choice[1]).interact(player)
	
	elif key.c == ord('>'):
		feature = player.map.feature_at(player.x, player.y)
		
		if feature.is_stairs:
			raise game.SetState(game.change_level)
		
		else:
			messages.Basic("There are no stairs here.", '?')
			return False
	
	# Look at the map
	elif key.c == ord('l'):
		look(player)
		
		return False
	
	# Show the help menu
	elif key.c == ord('?'):
		display_help()
		
		return False
	
	# Show the message log
	elif key.c == ord('m'):
		display_message_log(player)
		
		return False
	
	# Save a screenshot
	elif key.c == ord('P'):
		pic = libtcod.image_from_console(0)
		libtcod.image_save(pic, 'screenshots/{}.bmp'.format(time_as_string(file_safe = True)))
		
		messages.Basic('Screenshot saved.', '?')
		
		return False
	
	elif key.c == ord('D') and config.DEBUG_KEYS:
		debug(player)
		
		return False