Esempio n. 1
0
def fireball(x, y, radius):
	path = util.set_full_explore_map(game.current_map)
	libtcod.dijkstra_compute(path, x, y)
	for step in range(0, radius + 1):
		player_fov = False
		for i in range(-radius, radius + 1):
			for j in range(-radius, radius + 1):
				if libtcod.map_is_in_fov(game.fov_map, x + i, y + j) and libtcod.dijkstra_get_distance(path, x + i, y + j) <= step and libtcod.dijkstra_get_distance(path, x + i, y + j) >= 0:
					(front, back, lerp) = util.render_tiles_animations(x + i, y + j, libtcod.Color(160, 0, 0), libtcod.Color(64, 0, 0), libtcod.Color(0, 0, 0), round(libtcod.random_get_float(game.rnd, 0, 1), 1))
					libtcod.console_put_char_ex(0, game.MAP_X + x - game.curx + i, game.MAP_Y + y - game.cury + j, '*', front, back)
					player_fov = True
		if player_fov:
			libtcod.console_flush()
			time.sleep(0.05)
			player_fov = False

	for obj in game.current_map.objects:
		damage = util.roll_dice(1, 10)
		if obj.name == 'player':
			if libtcod.dijkstra_get_distance(path, game.char.x, game.char.y) <= radius:
				game.message.new('You are hit by a fireball for ' + str(damage) + ' pts of damage!', game.turns, libtcod.Color(160, 0, 0))
				game.player.take_damage(damage, 'a fireball')
		elif obj.entity:
			if libtcod.dijkstra_get_distance(path, obj.x, obj.y) <= radius:
				obj.entity.take_damage(obj.x, obj.y, damage, 'a fireball', True)
Esempio n. 2
0
def missile_attack(sx, sy, dx, dy, trap=False):
	cx, cy = sx, sy
	if sx == dx:
		char = '|'
	if sy == dy:
		char = chr(196)
	if (sx < dx and sy > dy) or (sx > dx and sy < dy):
		char = '/'
	if (sx < dx and sy < dy) or (sx > dx and sy > dy):
		char = '\\'
	path = util.set_full_explore_map(game.current_map, False)
	libtcod.path_compute(path, sx, sy, dx, dy)
	while not libtcod.path_is_empty(path):
		cx, cy = libtcod.path_walk(path, False)
		libtcod.console_blit(game.con, 0, 0, game.MAP_WIDTH, game.MAP_HEIGHT, 0, game.MAP_X, game.MAP_Y)
		libtcod.console_put_char_ex(0, game.MAP_X + cx - game.curx, game.MAP_Y + cy - game.cury, char, libtcod.light_gray, libtcod.black)
		libtcod.console_flush()
		time.sleep(0.05)

	if trap:
		for obj in game.current_map.objects:
			if obj.x == dx and obj.y == dy and not obj.item:
				damage = util.roll_dice(1, 6)
				if obj.name == 'player':
					game.message.new('You are hit by an arrow for ' + str(damage) + ' pts of damage!', game.turns, libtcod.Color(160, 0, 0))
					game.player.take_damage(damage, 'an arrow trap')
				else:
					obj.entity.take_damage(obj.x, obj.y, damage, 'an arrow', True)
Esempio n. 3
0
def sleeping_gas(x, y, radius, duration):
	path = util.set_full_explore_map(game.current_map)
	libtcod.dijkstra_compute(path, x, y)
	for i in range(-radius, radius + 1):
		for j in range(-radius, radius + 1):
			if libtcod.dijkstra_get_distance(path, x + i, y + j) <= radius and libtcod.dijkstra_get_distance(path, x + i, y + j) >= 0:
				game.current_map.tile[x + i][y + j].update({'icon': game.current_map.tile[x + i][y + j]['icon'], 'back_light_color': libtcod.Color(115, 220, 225), 'back_dark_color': libtcod.Color(0, 143, 189), 'lerp': round(libtcod.random_get_float(game.rnd, 0, 1), 1), 'duration': game.turns + duration, 'type': 'sleep_gas'})
				for obj in game.current_map.objects:
					if obj.item is None:
						if obj.x == x + i and obj.y == y + j:
							if obj.name == 'player':
								game.message.new('You are caught in a sleeping cloud!', game.turns)
								if 'sleep' not in game.player.flags:
									dice = util.roll_dice(1, 50)
									if dice > game.player.wisdom + (game.player.karma / 2):
										game.message.new('You fall asleep!', game.turns, libtcod.Color(0, 143, 189))
										game.player.flags.append('sleep')
							else:
								if libtcod.map_is_in_fov(game.fov_map, obj.x, obj.y):
									game.message.new(obj.entity.article.capitalize() + obj.entity.get_name() + ' is caught in a sleeping cloud!', game.turns)
								if 'sleep' not in obj.entity.flags:
									dice = util.roll_dice(1, 3)
									if dice == 3:
										if libtcod.map_is_in_fov(game.fov_map, obj.x, obj.y):
											game.message.new(obj.entity.article.capitalize() + obj.entity.get_name() + ' falls asleep!', game.turns)
										obj.entity.flags.append('sleep')
Esempio n. 4
0
	def create_cave_maze(self, type, floor, wall, prob, oper):
		rooms = [0] * 2
		for x in range(1, self.map_width - 1):
			for y in range(1, self.map_height - 1):
				if util.roll_dice(1, 100) < prob:
					self.set_tile_values(floor, x, y)
		for i in range(self.map_width * self.map_height * 5):
			x = libtcod.random_get_int(game.rnd, 1, self.map_width - 2)
			y = libtcod.random_get_int(game.rnd, 1, self.map_height - 2)
			if oper:
				if self.check_cell_neighbours(x, y) > 4:
					self.set_tile_values(wall, x, y)
				else:
					self.set_tile_values(floor, x, y)
			else:
				if self.check_cell_neighbours(x, y) > 4:
					self.set_tile_values(floor, x, y)
				else:
					self.set_tile_values(wall, x, y)

		# create rooms with up and down stairs
		x = libtcod.random_get_int(game.rnd, 2, self.map_width - 6)
		y = libtcod.random_get_int(game.rnd, 2, self.map_height - 6)
		rooms[0] = Rect(x, y, 5, 5)
		self.create_room(rooms[0], floor)
		(new_x1, new_y1) = rooms[0].center()
		game.char.x = new_x1
		game.char.y = new_y1

		count = 0
		while (abs(x - new_x1) < 25) or (abs(y - new_y1) < 12):
			x = libtcod.random_get_int(game.rnd, 2, self.map_width - 6)
			y = libtcod.random_get_int(game.rnd, 2, self.map_height - 6)
			count += 1
			if count == 50:
				return False
		rooms[1] = Rect(x, y, 5, 5)
		self.create_room(rooms[1], floor)
		(new_x2, new_y2) = rooms[1].center()

		# check if path to stairs is blocked if yes dig a tunnel
		path = util.set_full_explore_map(self, False)
		if not libtcod.path_compute(path, game.char.x, game.char.y, new_x2, new_y2):
			return False

		self.set_tile_values('stairs going up', game.char.x, game.char.y)
		self.up_staircase = (game.char.x, game.char.y)
		self.set_tile_values('stairs going down', new_x2, new_y2)
		self.down_staircase = (new_x2, new_y2)
		return True