コード例 #1
0
ファイル: worldMap.py プロジェクト: Lemmily/py-shopRL
 def __init__(self,x,y, level=1):
     POI.__init__(self,x,y,libtcod.Color(libtcod.random_get_int(0,50,255),libtcod.random_get_int(0,0,100),libtcod.random_get_int(0,100,150)), "#")
     self.level = level
     self.exp = 0           
     self.floors = []     
     self.generate_floors()
     print "dungeon!"
コード例 #2
0
ファイル: city.py プロジェクト: Lemmily/py-shopRL
    def pickGeneratedResources(self, resource_list):

        limit = len(resource_list) - 1
        #selections = {}

        print self.name
        quantity_resources = libtcod.random_get_int(0, 2, 6)
        temp = []
        for n in range(quantity_resources):
            resource = resource_list[libtcod.random_get_int(0, 0, limit)]

            temp.append(resource)

        #now consolidate so there is just one instance of a resource.
        for resource in resource_list:
            count = 0
            for test_for in temp:
                if test_for == resource:
                    count += 1

            self.producing[resource] = [resource, count]

        print "produces:-"
        for resource in self.producing:
            if self.producing[resource][1] > 0:
                print resource + str(self.producing[resource][1])
        print "\n"

        self.findDesiredResources()
コード例 #3
0
ファイル: object.py プロジェクト: cecilycarver/playground
def place_monsters(room):
	#choose random number of monsters
	num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)
 
	for i in range(num_monsters):
		#choose random spot for this monster
		x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1)
		y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1)
 
		if not is_blocked(x, y):
			i = libtcod.random_get_int(0, 0, 100)
			if i < 20:
				#create a teacher
				teacher_ai = mods.Teacher()
				monster = Object(x, y, 'T', 'teacher', libtcod.light_blue, blocks=True, ai=teacher_ai)
			elif i < 80:  #80% chance of getting a child
				#create a child
				child_fighter = mods.Fighter(hp=3, defense=0, power=1, on_death=mods.monster_death)
				child_ai = mods.BasicMonster()
				monster = Object(x, y, 't', 'toddler', libtcod.light_pink, blocks=True, fighter=child_fighter, ai=child_ai)
			elif i < 90:
				#create a bully
				bully_fighter = mods.Fighter(hp=5, defense=1, power=2, on_death=mods.monster_death)
				bully_ai = mods.BasicMonster()
				monster = Object(x, y, 'B', 'bully', libtcod.light_green, blocks=True, fighter=bully_fighter, ai=bully_ai)
			else:
				#create a smart bully
				bully_fighter = mods.Fighter(hp=5, defense=1, power=3, on_death=mods.monster_death)
				bully_ai = mods.SmartMonster()
				monster = Object(x, y, 'B', 'smart bully', libtcod.dark_green, blocks=True, fighter=bully_fighter, ai=bully_ai)				
			
			things.append(monster)	
コード例 #4
0
ファイル: main.py プロジェクト: SilverWingedSeraph/RaptorDown
    def interact(self, interlocutor):
	if self.dead is True:
		return
	if self.hp <= 0:
		self.dead = True
		return
        if interlocutor.name != "You":
            return #We're not interacting with the player for some reason. This is not good.
        #See if we hit the enemy
        attacker_hit_try = libtcod.random_get_int(0, 0, interlocutor.attack) + interlocutor.attack
        defender_dodge_try = libtcod.random_get_int(0, 0, self.defense) + self.defense
        hit_enemy = False
        damage_enemy = 0
        if (attacker_hit_try > defender_dodge_try):
            hit_enemy = True
            #See how much we damage the enemy
            damage_enemy = (attacker_hit_try - defender_dodge_try) + libtcod.random_get_int(0,0,interlocutor.attack)
        else:
            hit_enemy = False

        #Deal the damage and report
        if hit_enemy:
            self.hp -= damage_enemy
            message(interlocutor.name + " hit " + self.name + " for " + str(damage_enemy) + " hit points.", libtcod.green)
        else:
            message(interlocutor.name + " missed " + self.name + ".", color_ui_text)
コード例 #5
0
ファイル: firstrl.py プロジェクト: chrisdcoe/py_rogue
def make_map():
    global map, player

    # fill map with blocked tiles
    map = [[Tile(True) for y in range(MAP_HEIGHT)] for x in range(MAP_WIDTH)]

    # iterate until max number of rooms, assigning random coordinates and size
    rooms = []
    num_rooms = 0

    for r in range(MAX_ROOMS):
        # random width and height
        w = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        # random position without going out of bounds of the map
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)

        new_room = Rect(x, y, w, h)

        # check if other rooms intersect with this one
        failed = False
        for other_room in rooms:
            if new_room.intersect(other_room):
                failed = True
                break
        if not failed:
            # there are no intersections, this room is valid
            # draw room to map tiles
            create_room(new_room)

            # find center coordinates of room
            (new_x, new_y) = new_room.center()

            if num_rooms == 0:
                # the first room, where player starts
                player.x = new_x
                player.y = new_y
            else:
                # for all rooms after the first
                # connect it to previous room with a tunnel
                # center coords of previous room
                (prev_x, prev_y) = rooms[num_rooms - 1].center()

                # coin toss: horizontal or vertical first?
                if libtcod.random_get_int(0, 0, 1) == 1:
                    # horizontal, then vertical
                    create_h_tunnel(prev_x, new_x, prev_y)
                    create_v_tunnel(prev_y, new_y, new_x)
                else:
                    # vertical, then horizontal
                    create_v_tunnel(prev_y, new_y, prev_x)
                    create_h_tunnel(prev_x, new_x, new_y)

            # add contents to room (monsters etc)
            place_objects(new_room)

            # append new rooms to list
            rooms.append(new_room)
            num_rooms += 1
コード例 #6
0
ファイル: regolith.py プロジェクト: phaethonfire/regolith
def make_map():
    global map, objects
 
    #the list of objects with just the player
    objects = [player]
    player.x = MAP_WIDTH / 2
    player.y = MAP_HEIGHT / 2
 
    myrng = libtcod.random_new(123)
    noise2d = libtcod.noise_new(2,libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY, myrng)
    libtcod.noise_set_type(noise2d, libtcod.NOISE_PERLIN)

    #fill map with "normal" tiles
    map = [[Tile(False, libtcod.light_gray)
        for y in range(MAP_HEIGHT)]
            for x in range(MAP_WIDTH)]

    #add color
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            value = int((libtcod.noise_get_fbm(noise2d,[x/float(MAP_WIDTH),y/float(MAP_HEIGHT)],32) + 1) * 96 )
            map[x][y] = Tile(False, libtcod.Color(value,value,value))

    r = [libtcod.random_get_int(0, CRATER_MIN_SIZE, (CRATER_MIN_SIZE + (CRATER_MAX_SIZE - CRATER_MIN_SIZE) * (MAX_CRATERS - i)**2/(MAX_CRATERS**2)) ) for i in range(MAX_CRATERS)]
    r.sort(reverse=True)
    for i in range(MAX_CRATERS):
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - 1)
        # r = libtcod.random_get_int(0, CRATER_MIN_SIZE, (CRATER_MIN_SIZE + (CRATER_MAX_SIZE - CRATER_MIN_SIZE) * (MAX_CRATERS - i)/MAX_CRATERS) )
        make_crater(x, y, r[i])

    spawn_silicon(noise2d)
コード例 #7
0
ファイル: combat.py プロジェクト: tichenor/tombkings
    def melee_attack(attacker, defender):
        # miss chance
        if Combat.melee_hit_roll(attacker, defender):
            if Combat.melee_block_roll(attacker, defender):
                # damage spread
                i, d = divmod(attacker.fighter.power / 3, 1)
                # raw damage
                attacker_power = attacker.fighter.power * (
                    0.8 + 0.05 * attacker.fighter.power)
                raw_damage = attacker_power + libtcod.random_get_int(
                    0, int(-i), int(i))
                # amplification sources
                amp = 0
                # armor reduction
                die = libtcod.random_get_int(0, 0, 20)
                if die + defender.fighter.fighting > 2 * attacker.fighter.power:
                    # target is strong defender
                    reduction = 0.6 * defender.fighter.armor + 0.03 * defender.fighter.shielding
                else:
                    reduction = 0.35 * defender.fighter.armor + 0.03 * defender.fighter.shielding
                # damage after modifiers
                damage = int(round(raw_damage - reduction) * (1 + amp))
                if damage > 0:
                    defender.fighter.take_damage(damage)
                    if attacker.fighter.lifesteal > 0:
                        attacker.fighter.heal(attacker.fighter.lifesteal)
                    return CombatResults.HIT
                else:
                    return CombatResults.ARMOR

            else:
                return CombatResults.BLOCK
        else:
            return CombatResults.MISS
コード例 #8
0
ファイル: mapgen.py プロジェクト: nrberens/Purge
def make_rivers():
	starty = libtcod.random_get_int(0, 1, config.MAP_HEIGHT-1)
	startx = 0
		
	#Drunkard's Walk with double weight to move east
	
	x = startx
	y = starty

	while 1 <= x <= config.MAP_WIDTH-1 and 1 <= y <= config.MAP_HEIGHT-1:
		#place water tile
		if not config.map[x][y].water:
			pool_component = Pool(water=True)
			pool_instance = game.Object(x, y, 'w', 'a pool of water', libtcod.Color(52,108,105), pool=pool_component)
			config.objects.append(pool_instance)
			config.map[x][y].blocked = False
			config.map[x][y].block_sight = False
			config.map[x][y].water = True
		
		walk = libtcod.random_get_int(0, 0, 5)
		if walk == 0: #go north
			y -= 1
		elif walk == 1: #go south
			y += 1
		elif walk == 2: #go west
			x -= 1
		else:			#go east, 2x chance
			x += 1
コード例 #9
0
    def attack(self, target):
        #a simple formula for attack damage
        hit_power = libtcod.random_get_int(0, 0, self.power)
        hit_defense = libtcod.random_get_int(0, 0, target.fighter.defense)

        damage = hit_power - hit_defense
        if (self.owner.is_player):
            attack_word = libtcod.random_get_int(0, 0, len(player_attacks) - 1)
        else:
            attack_word = libtcod.random_get_int(0, 0, len(enemy_attacks) - 1)

        if damage > 0:
            #make the target take some damage
            if (self.owner.is_player):
                draw.message('You ' + player_attacks[attack_word] + ' the ' +
                             target.name + '.')
            else:
                draw.message('The ' + self.owner.name + ' ' +
                             enemy_attacks[attack_word] + ' you. It hurts.')
            target.fighter.take_damage(damage)
            # notify other visible objects about attack
            if (self.owner.visible):
                self.owner.notify_visible('damage')
        else:
            if (self.owner.is_player):
                draw.message('You ' + player_attacks[attack_word] + ' the ' +
                             target.name + ' but it has no effect!')
            else:
                draw.message('The ' + self.owner.name + ' ' +
                             enemy_attacks[attack_word] +
                             ' you but it has no effect!')

            # notify other visible objects about attack
            if (self.owner.visible):
                self.owner.notify_visible('attack')
コード例 #10
0
ファイル: combat.py プロジェクト: tichenor/tombkings
 def ranged_attack(attacker, defender):
     if Combat.ranged_hit_roll(attacker, defender):
         if Combat.ranged_block_roll(attacker, defender):
             # damage spread
             i, d = divmod(attacker.fighter.power / 3, 1)
             # raw damage
             attacker_power = attacker.fighter.power * (0.7 + 0.07*attacker.fighter.archery) + \
                              attacker.fighter.archery/2
             raw_damage = attacker_power + libtcod.random_get_int(0, -i, i)
             # amplification sources
             amp = sum(equipment.damage_amp_bonus
                       for equipment in get_all_equipped(attacker))
             # armor reduction
             die = libtcod.random_get_int(0, 0, 20)
             if die + defender.fighter.shielding > attacker.fighter.archery + attacker.fighter.power:
                 # target is strong defender
                 reduction = 0.5 * defender.fighter.armor + 0.03 * defender.fighter.shielding
             else:
                 reduction = 0.2 * defender.fighter.armor + 0.03 * defender.fighter.shielding
             # damage after modifiers
             damage = int(round(raw_damage - reduction) * (1 + amp))
             if damage > 0:
                 defender.fighter.take_damage(damage)
                 return CombatResults.HIT
             else:
                 return CombatResults.ARMOR
         else:
             return CombatResults.BLOCK
     else:
         return CombatResults.MISS
コード例 #11
0
def rand_gaussian_d20(rerolls = 0):
    rollResult = 0
    rollNo = 0

    if rerolls >= 0:
        while rollNo < rerolls + 1:
            roll1 = libtcod.random_get_int(0, 1, 20)
            roll2 = libtcod.random_get_int(0, 1, 20)
            result = (roll1 + roll2) / 2

            if result > rollResult:
                rollResult = result
            rollNo += 1
    else:
        while rollNo < abs(rerolls) + 1:
            roll1 = libtcod.random_get_int(0, 1, 20)
            roll2 = libtcod.random_get_int(0, 1, 20)
            result = (roll1 + roll2) / 2

            if rollNo == 0:
                rollResult = result
            elif result < rollResult:
                rollResult = result
            rollNo += 1

    return rollResult
コード例 #12
0
def place_objects(room):
    # choose random number of monsters
    num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)

    for i in range(num_monsters):
        #choose random spot for this monster
        x = libtcod.random_get_int(0, room.x1, room.x2)
        y = libtcod.random_get_int(0, room.y1, room.y2)

        #only place it if the tile is not blocked
        if not is_blocked(x, y):
            choice = libtcod.random_get_int(0, 0, 100)
            if choice < 20:
                # create a bat
                fighter_component = Fighter(hp=4, defense=1, power=1)
                ai_component = BasicMonster()

                monster = Object(x, y, 'w', 'bat', libtcod.light_yellow, blocks=True, fighter=fighter_component, ai=ai_component)

            elif choice < 20 + 40:
                # create a troll
                fighter_component = Fighter(hp=12, defense=1, power=4)
                ai_component = BasicMonster()

                monster = Object(x, y, 'T', 'troll', libtcod.dark_violet, blocks=True, fighter=fighter_component, ai=ai_component)

            else:
                # create a zombie
                fighter_component = Fighter(hp=5, defense=0, power=3)
                ai_component = BasicMonster()

                monster = Object(x, y, 'Z', 'zombie', libtcod.desaturated_green, blocks=True, fighter=fighter_component, ai=ai_component)

            objects.append(monster)
コード例 #13
0
def place_objects(room):
    # maximum number of monsters per room
    max_monsters = from_dungeon_level([[2, 1], [3, 4], [5, 6]])

    # chance of each monster
    monster_chances = {
        'orc': 80,
        'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]])
    }

    # monster_chances = {'orc': 80, 'troll': 20}
    monster_creators = {'orc': o.create_orc, 'troll': o.create_troll}

    # choose random number of monsters
    num_monsters = libtcod.random_get_int(0, 0, max_monsters)

    for i in range(num_monsters):
        # choose random spot for this monster
        x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1)
        y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1)

        choice = random_choice(monster_chances)
        monster = monster_creators[choice](x, y)

        # only place it if the tile is not blocked
        if not o.is_blocked(x, y, tile_map, objects):
            objects.append(monster)
    # place the items
    place_items(room)
コード例 #14
0
def place_objects(zone, room, max_monsters, objects):
  """Places a random number n monsters (0 < n < max_monsters) in the provided room, appending them to objects.

  Modifies objects. Returns nothing.
  """
  # Choose a random number of monsters
  num_monsters = libtcod.random_get_int(0, 0, max_monsters )

  for i in range(num_monsters):
    # Choose random spot for monster
    x = libtcod.random_get_int(0, room.x1, room.x2)
    y = libtcod.random_get_int(0, room.y1, room.y2)

    # Only place if the location isn't blocked
    if not classes.is_blocked(zone, objects, x, y):
      if libtcod.random_get_int(0, 0, 100) < 80:  #80% Chance of Orc
        # Create an Orc
        fighter_comp = classes.Fighter(hp=10, defense=0, power=3, death_func=partial(monster_death, obj_list=objects))
        ai_comp = classes.MonsterBasic()
        monster = classes.Object("Orc", x, y, 'o', libtcod.desaturated_green, fighter=fighter_comp, ai=ai_comp)
      else:
        #create a Troll
        fighter_comp = classes.Fighter(hp=16, defense=1, power=4, death_func=partial(monster_death, obj_list=objects))
        ai_comp = classes.MonsterBasic()
        monster = classes.Object("Troll", x, y, 'T', libtcod.darker_green, fighter=fighter_comp, ai=ai_comp)
      objects.append(monster)
コード例 #15
0
ファイル: firstrl1.py プロジェクト: smkmth/examplerouglike
def make_map():
    global map

    #fill map with unblocked tiles
    map = [[ Tile(True)
        for y in range(MAP_HEIGHT)]
           for x in range(MAP_WIDTH)]

    rooms = []
    num_rooms = 0

    for r in range(MAX_ROOMS):
        #random widths and heights
        w = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        #random postion within the  map
        x = libtcod.random_get_int(0,0,MAP_WIDTH - w - 1)
        y = libtcod.random_get_int(0,0, MAP_HEIGHT - h - 1)

        new_room = Rect(x, y, w, h)

        failed = False
        for other_room in rooms:
            if new_room.intersect(other_room):
                failed =True
                break
        if not failed:
            #this means their is no intersections so the room  is valid

            #'paint it' to the new maps tiles
            create_room(new_room)
            #center coordinates of new room, will be useful later
            (new_x, new_y) = new_room.center()

            room_no = Object(new_x, new_y, chr(65+num_rooms), libtcod.white)
            objects.insert(0, room_no)
            
            if num_rooms == 0:
                #this is the first room where the player starts
                player.x = new_x
                player.y = new_y
            else:
                #all rooms after the first
                #conect it to the previous room with a tunnel

                #center coodinates of previous room
                (prev_x, prev_y) =rooms[num_rooms-1].center()

                if libtcod.random_get_int(0, 0, 1) == 1:
                    #first move horizontally then vertiacally
                    create_h_tunnel(prev_x, new_x, prev_y)
                    create_v_tunnel(prev_y, new_y, new_x)
                else:
                    #first move vertically then horzontally
                    create_v_tunnel(prev_y, new_y, prev_x)
                    create_h_tunnel(prev_x, new_x, new_y)

            #finally append new room to list
            rooms.append(new_room)
            num_rooms += 1
コード例 #16
0
ファイル: second.py プロジェクト: tthhmm/pyrgl
def make_pool():
    w = libtcod.random_get_int(0, 10, 16)
    h = libtcod.random_get_int(0, 10, 16)
    x = libtcod.random_get_int(0, 0, MAP_WIDTH - w)
    y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h)
    new_room = Rect(x, y, w, h)
    create_pool(new_room)
コード例 #17
0
def generate_level_map():

    levelmap = [[ tile.Tile(True)
        for y in xrange(MAP_HEIGHT) ]
            for x in xrange(MAP_WIDTH) ]

    levelmapobjs = []

    num_generated = 0
    rects = []

    for x in xrange(MAX_GENERATIONS):

        w = libtcod.random_get_int(0, GEN_MIN_SIZE, GEN_MAX_SIZE)
        h = libtcod.random_get_int(0, GEN_MIN_SIZE, GEN_MAX_SIZE)

        x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)

        new_rect = rect.Rect(x, y, w, h)
        draw_rect(new_rect, levelmap)

        num_generated += 1

        """ Chance of generating an overworld object. pretty low odds. """
        chance = libtcod.random_get_int(0, 0, 100)
        if chance > 85:
            obj = generate_overworld_object(x, y)
            obj.blocked = True
            levelmapobjs.append(obj)

    return levelmap, levelmapobjs
コード例 #18
0
ファイル: pyPython.py プロジェクト: kBeezee/pyPython
def restart_game():
    global snake
    while True:
        startX = libtcod.random_get_int(0, 5, SCREEN_WIDTH - 5)
        startY = libtcod.random_get_int(0, 5, SCREEN_HEIGHT - 5)
        if not gamemap[startY][startX].blocked:
            break

    #make the snake
    snake = []
    obj = snake_parts(startX, startY, '@', 'head', libtcod.white, True)
    snake.append(obj)

    for i in range(initSnakeLen):
        obj = snake_parts(startX, startY, '#', 'body', libtcod.white, True)
        snake.append(obj)

    food = []
    obj = mob(40, 40, '%', food, libtcod.dark_yellow)
    food.append(obj)

    define_map()
    status = 'newgame'
    oldX = 0
    oldY = 0
コード例 #19
0
def _place_random_creatures(new_map, player):
    for r_count in range(0, RUSALKA_GOAL):
        while True:
            r_pos = algebra.Location(
                libtcod.random_get_int(new_map.rng, new_map.pool_x,
                                       new_map.width - 3),
                libtcod.random_get_int(new_map.rng, 3, new_map.height - 3))
            if new_map.terrain[r_pos.x][r_pos.y] != map.TERRAIN_WALL:
                break
        # TODO: can we ensure this doesn't block the passage?
        #for x in range(r_pos.x-2, r_pos.x+3):
        #    for y in range(r_pos.y-2, r_pos.y+3):
        #        if new_map.terrain[x][y] == map.TERRAIN_FLOOR:
        #            new_map.terrain[x][y] = map.TERRAIN_WATER
        mob = bestiary.rusalka(new_map, r_pos, player)
        _new_equipment(mob, miscellany.tortoiseshell_comb())

    for vc_count in range(0, VODANYOI_CLUSTER_GOAL):
        while True:
            vc_pos = algebra.Location(
                libtcod.random_get_int(new_map.rng, new_map.pool_x,
                                       new_map.width - 3),
                libtcod.random_get_int(new_map.rng, 3, new_map.height - 3))
            if new_map.terrain[vc_pos.x][vc_pos.y] == map.TERRAIN_FLOOR:
                break
        _place_vodanyoi_cluster(new_map, player, vc_pos)
コード例 #20
0
def mpd_setCornerAltitudes(_map, minAlt, maxAlt):
    print('Map w', _map.width, 'h', _map.height)
    
    _map.setHeight(0, 0, tcod.random_get_int(0,minAlt, maxAlt))
    _map.setHeight(_map.width - 1, 0, tcod.random_get_int(0,minAlt, maxAlt))
    _map.setHeight(_map.width - 1, _map.height - 1, tcod.random_get_int(0,minAlt, maxAlt))
    _map.setHeight(0, _map.height - 1, tcod.random_get_int(0,minAlt, maxAlt))
コード例 #21
0
def place_objects(room):
    """
    Places objects within the specified room. 
    TODO: Add generic support for which objects.
    """
    # Init a random number of monsters in the room from 0 to MAX_ROOM_MONSTERS (3)
    num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)

    for i in range(num_monsters):
        x = libtcod.random_get_int(0, room.x1, room.x2)
        y = libtcod.random_get_int(0, room.y1, room.y2)

        if not is_blocked(x, y):
            # the likely hood of this is 80%
            if libtcod.random_get_int(0, 0, 100) < 80:
                # creates an orc object monster
                monster = Object(x,
                                 y,
                                 'o',
                                 'orc',
                                 libtcod.desaturated_green,
                                 blocks=True)
            else:
                # create a troll
                monster = Object(x,
                                 y,
                                 'T',
                                 'troll',
                                 libtcod.darker_green,
                                 blocks=True)

            #append monsters generated to list
            objects.append(monster)
コード例 #22
0
def generate_random_item(x, y):
    item = None
    if libtcod.random_get_int(0, 0, 100) < 65:
        #create candy
        item_comp = mods.Item('candy')
        item = Object(
            x,
            y,
            '!',
            candy_names[libtcod.random_get_int(0, 0, len(candy_names)) - 1],
            libtcod.violet,
            item=item_comp)
    else:
        #create toy
        item_comp = mods.Item('toy')
        item = Object(x,
                      y,
                      ':',
                      toy_names[libtcod.random_get_int(0, 0, len(toy_names)) -
                                1],
                      libtcod.blue,
                      item=item_comp)

    things.append(item)
    item.send_to_back()  #items appear below other objects
コード例 #23
0
def spawn_mobs(map):
	""" |  Spawns randomly distributed mobs. Mobs spawn in packs.
		|  The count and type of mobs is determined by the dungeon level.
	"""

	numberMobs = []
	for moblevel in range(7):
		numberMobs.append(chances(moblevel, map.owner.maps.index(map)+1))
	#Eliminate level 0 Mobs
	numberMobs.pop(0)
	#go through all the mob levels
	for mobcount in numberMobs:
		currentLevelMobs = gvar.mobdb[str(numberMobs.index(mobcount)+1)]
		#Mob Count is +-2 of function value
		mobcount = libtcod.random_get_int(0, mobcount-2, mobcount+2)
		#spawn packs of mobs until the count is depleted
		while mobcount != 0:
			#get random mob of this level
			mobToSpawn = currentLevelMobs[libtcod.random_get_int(0, 0, len(currentLevelMobs)-1)]

			packSize = libtcod.random_get_int(0,mobToSpawn["packsize"][0], mobToSpawn["packsize"][1])
			if packSize > mobcount:
				packSize = mobcount
 			#choose random room
 			room = map.random_room()
			#choose random spot for this pack
			(x, y) = room.random_spot()
			while map.is_blocked(x, y, ai=True):
				(x, y) = room.random_spot()
			place_mob_pack(map, x, y, mobToSpawn, packSize)
			mobcount -= packSize
コード例 #24
0
ファイル: dungeon.py プロジェクト: Lemmily/py-shopRL
    def new_split(self, rect):
        if rect.w > MIN_BSP_SIZE * 2 and rect.h > MIN_BSP_SIZE * 2:
            if utils.flip() and rect.x + rect.w / 2 + MIN_BSP_SIZE < len(
                    self.map) and rect.y + rect.h / 2 + MIN_BSP_SIZE < len(self.map[0]):

                x = libtcod.random_get_int(0, rect.x + MIN_BSP_SIZE, rect.x + rect.w - MIN_BSP_SIZE)
                w = (rect.x + rect.w) - x

                baby = Rect(rect.w - w, rect.h, rect.x, rect.y)
                baby.bsp(rect)
                baby_2 = Rect(w - 1, rect.h, x, rect.y)
                baby_2.bsp(rect)

                rect.babies.append(baby)
                rect.babies.append(baby_2)
            else:
                y = libtcod.random_get_int(0, rect.y + MIN_BSP_SIZE, rect.y + rect.h - MIN_BSP_SIZE)

                h = (rect.y + rect.h) - y

                baby = Rect(rect.w, rect.h - h, rect.x, rect.y)
                baby.bsp(rect)
                baby_2 = Rect(rect.w, h - 1, rect.x, y)
                baby_2.bsp(rect)

                rect.babies.append(baby)
                rect.babies.append(baby_2)
        else:
            rect.end = True

        for baby in rect.babies:
            if baby.end != True:
                self.new_split(baby)
コード例 #25
0
 def generate_room(self, map_x_length, map_y_length, no_of_intersects, room_min_size, room_max_size):  #chooses random coords for the room and defines the shape of the room
     global current_rooms
     #random width and height
     w = libtcod.random_get_int(0,room_min_size, room_max_size)
     h = libtcod.random_get_int(0,room_min_size, room_max_size)
     #random position in bounds on the map
     x = libtcod.random_get_int(0,0,map_x_length - w - 1)
     y = libtcod.random_get_int(0,0,map_y_length - h - 1)
     #makes the room
     new_room = Rect(x,y,w,h)
     #check other rooms for an intersection
     failed = False
     
     
     room_intersects = 0
     for other_room in current_rooms:
         if new_room.intersect(other_room):
             room_intersects +=1
             if room_intersects >= no_of_intersects:
                 failed = True
                 break
             break
     if not failed:  #not over max number of intersections, so clear to build
         self.create_room(new_room)
         return new_room
コード例 #26
0
ファイル: rogue6.py プロジェクト: aldantefax/pythonrogue
def place_objects(room):
    num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)
    
    for i in range(num_monsters):
        #pick a random location for object generation
        x = libtcod.random_get_int(0, room.x1, room.x2)
        y = libtcod.random_get_int(0, room.y1, room.y2)
        
        #uses option b to create 4 monster entities based on 20/40/10/30% distribution
        #checks to see if a tile is blocked. if not, step into these choices:
        if not is_blocked(x, y):
            choice = libtcod.random_get_int(0, 0, 100)
            if choice < 20:
                fighter_component = Fighter(hp=10, defense=0, power=3, death_function=monster_death)
                ai_component = BasicMonster()
                monster = Object(x, y, 'h', 'human', libtcod.desaturated_green, blocks=True, fighter=fighter_component, ai=ai_component)
            elif choice < 20+40:
                fighter_component = Fighter(hp=15, defense=0, power=4, death_function=monster_death)
                ai_component = BasicMonster()
                monster = Object(x, y, 'o', 'orc', libtcod.orange, blocks=True, fighter=fighter_component, ai=ai_component)
            elif choice < 20+40+10:
                fighter_component = Fighter(hp=20, defense=0, power=5, death_function=monster_death)
                ai_component = BasicMonster()
                monster = Object(x, y, 'd', 'dragon', libtcod.red, blocks=True, fighter=fighter_component, ai=ai_component)
            else:
                fighter_component = Fighter(hp=25, defense=0, power=6, death_function=monster_death)
                ai_component = BasicMonster()
                monster = Object(x, y, 'T', 'troll', libtcod.green, blocks=True, fighter=fighter_component, ai=ai_component)
                            
            objects.append(monster)
コード例 #27
0
 def moveai (self):
     #behavior for monster movement when a direct line to the player is not available
     not_moved = True
     while not_moved:
         direction = libtcod.random_get_int(0,1,5)   #pick a random direction
         if direction == 1:  #north
             if not is_blocked(self.x, self.y - 1) and (player.distance(self.x, self.y - 1) <= self.distance_to(player)):
                 self.y -= 1
                 not_moved = False
         elif direction == 2:    #east
             if not is_blocked(self.x + 1, self.y) and (player.distance(self.x + 1, self.y) <= self.distance_to(player)):
                 self.x += 1
                 not_moved = False
         elif direction == 3:    #south
             if not is_blocked(self.x, self.y + 1) and (player.distance(self.x, self.y + 1) <= self.distance_to(player)):
                 self.y += 1
                 not_moved = False
         elif direction == 4:    #west
             if not is_blocked(self.x - 1, self.y) and (player.distance(self.x - 1, self.y) <= self.distance_to(player)):
                 self.x -= 1
                 not_moved = False
         else:   #randomly move in some direction if the space is clear, or else wait a turn if it is not.
             dx = libtcod.random_get_int(0, -1, 1)
             dy = libtcod.random_get_int(0, -1, 1)
             if not is_blocked(self.x + dx, self.y):
                 self.x = self.x + dx
             if not is_blocked(self.x, self.y + dy):
                 self.y = self.y + dy
             not_moved = False
コード例 #28
0
 def takeTurn(self, sightedCreatures):
     targetCreature = None
     for creature in sightedCreatures:
         if self.owner.isHostile(creature):
             targetCreature = creature
             if self.owner.canAttack(creature):
                 self.owner.attack(creature, self.owner.weapon)
                 return 
             else:
                 self.owner.chase(targetCreature.x, targetCreature.y, self.theMap)
                 return
     #if targetCreature:
         #if self.owner.canAttack(targetCreature):
         #    self.owner.attack(targetCreature, self.owner.weapon)
         #    return
         #else:
         #    self.owner.chase(targetCreature.x, targetCreature.y)
         #    return
     # no hostile creature found; wander around
     #50% chance of not moving anywhere
     if libtcod.random_get_int(0, 0, 100) > 50:
         return
     else:
         self.owner.moveOrAttack(libtcod.random_get_int(0,0,1), libtcod.random_get_int(0,0,1), self.theMap)
         return
コード例 #29
0
 def attack(self, targetCreature, weapon):
     attack = libtcod.random_get_int(0, 1, 20)
     damage = 0
     if attack == 0:
         #TODO: handle critical miss
         pass
     elif attack >= 20 - weapon.criticalThreat:
         #TODO: handle critical hit
         pass
     else:
         attack = attack + weapon.attackBonus + self.stats.getStrBonus()
         if attack >= targetCreature.armorClass:
             #hit!
             damage=libtcod.random_get_int(0, weapon.minDamage, weapon.maxDamage)
             damage=damage + self.stats.getStrBonus()
             print ('The '+ self.name+' hits the '+ targetCreature.name+' for '+str(damage))
         else:
             #TODO: handle miss
             pass
     targetCreature.hp = targetCreature.hp - damage
     if targetCreature.hp < 1:
         targetCreature.blocks = False
         targetCreature.isDead = True
         targetCreature.color = DEAD_COLOR
         print("The "+targetCreature.name+" died!")
コード例 #30
0
ファイル: dungeon.py プロジェクト: Lemmily/py-shopRL
    def construct_objects(self):
        stair = entities.Object(self.up[0],
                                self.up[1],
                                char="<",
                                name="stair",
                                colour=libtcod.purple,
                                blocks=False,
                                always_visible=False)
        self.objects.append(stair)
        stair = entities.Object(self.down[0],
                                self.down[1],
                                char=">",
                                name="stair",
                                colour=libtcod.red,
                                blocks=False,
                                always_visible=False)
        self.objects.append(stair)

        if len(self.rects) > 0:
            room = self.rects[libtcod.random_get_int(0, 0,
                                                     len(self.rects) - 1)]
            item = entities.Item()
            potion = entities.Object(
                libtcod.random_get_int(0, room.x, room.x + room.w - 2),
                libtcod.random_get_int(0, room.y, room.y + room.h - 2),
                char="!",
                name="potion",
                colour=libtcod.orange,
                blocks=False,
                always_visible=False,
                item=item)
            self.objects.append(potion)
コード例 #31
0
def make_sanctum():
	#create a predefined level, which we will call the sanctum
	global map, player, objects, stairs, up_stairs, floors, boss
	objects = [player]
	map = [[Tile(True) for y in range(MAP_HEIGHT)] for x in range(MAP_WIDTH)]
	broom = Rect(20, 20, 40, 10)
	create_room(broom)
	#placing the player
	player.x = 40
	player.y = 25
	#let the player know that shit's getting real
	message("Welcome to the Sanctum! The Amulet is here somewhere...", libtcod.yellow)
	#the stairs
	up_stairs = Object(player.x, player.y, "<", "up stairs", libtcod.white, always_visible = True)
	stairs = Object(0, 0, ">", "TEEHEE", libtcod.black, always_visible = True)
	objects.append(up_stairs)
	objects.append(stairs)
	send_to_back(up_stairs)
	altar_x = libtcod.random_get_int(0, 21, 59)
	altar_y = libtcod.random_get_int(0, 21, 29)
	#the boss
	ai_component = BasicMonster()
	fighter_component = Fighter(hp = 100, defense = 5, power = 15, xp = 300, death_function = monster_death)
	monster = Object(altar_x, altar_y, '&', "sanctum guardian", libtcod.dark_flame, blocks = True, fighter = fighter_component, ai = ai_component)
	objects.append(monster)
	#the Amulet
	equipment_component = Equipment(slot = 'neck')
	amulet = Object(altar_x, altar_y, "*", "amulet", libtcod.azure, equipment = equipment_component)
	objects.append(amulet)
	send_to_back(amulet)
	#the altar
	altar = Object(altar_x, altar_y, "_", "bloodstained altar", libtcod.darkest_gray, always_visible = True)
	objects.append(altar)
	send_to_back(altar)
コード例 #32
0
ファイル: common.py プロジェクト: AdrienKYoung/mrogue
def summon_ally(name, duration, x=None, y=None):
    adj = main.adjacent_tiles_diagonal(player.instance.x, player.instance.y)

    # Get viable summoning position. Return failure if no position is available
    if x is None or y is None:
        summon_positions = []
        for tile in adj:
            if not main.is_blocked(tile[0], tile[1]):
                summon_positions.append(tile)
        if len(summon_positions) == 0:
            ui.message('There is no room to summon an ally here.')
            return
        summon_pos = summon_positions[libtcod.random_get_int(
            0, 0,
            len(summon_positions) - 1)]
    else:
        summon_pos = (x, y)

    # Select monster type - default to goblin
    import monsters
    if name in monsters.proto.keys():
        summon = main.spawn_monster(name,
                                    summon_pos[0],
                                    summon_pos[1],
                                    team='ally')
        if summon is not None:
            if summon.behavior is not None:
                summon.behavior.follow_target = player.instance

            # Set summon duration
            summon.summon_time = duration + libtcod.random_get_int(
                0, 0, duration)
        return 'success'
    else:
        return 'didnt-take-turn'
コード例 #33
0
ファイル: ai.py プロジェクト: AdrienKYoung/mrogue
def wander(behavior):
    monster = behavior.owner
    target = acquire_target(monster)
    if target is not None:
        behavior.last_seen_position = target.x, target.y
        behavior.target = target
        behavior.wander_path = None
        return 'acquired-target'
    else:
        if behavior.wander_path is None or len(behavior.wander_path) == 0:
            rand_x = libtcod.random_get_int(
                0, min(1, monster.x - 10),
                max(consts.MAP_WIDTH - 2, monster.x + 10))
            rand_y = libtcod.random_get_int(
                0, min(1, monster.y - 10),
                max(consts.MAP_HEIGHT - 2, monster.y + 10))
            rand_pos = rand_x, rand_y
            rand_pos = game.find_closest_open_tile(rand_pos[0], rand_pos[1])
            if rand_pos is None:
                return 'wandered'
            behavior.wander_path = game.get_path_to_point(
                (monster.x, monster.y), rand_pos, monster.movement_type, None)
            if behavior.wander_path is None:
                return 'wandered'
        old_pos = monster.x, monster.y
        next_move = monster.x, monster.y
        while next_move == old_pos and len(behavior.wander_path) > 0:
            next_move = behavior.wander_path.pop(0)
        monster.move(next_move[0] - monster.x, next_move[1] - monster.y)
        if old_pos == (monster.x, monster.y):
            monster.behavior.wander_path = None
        return 'wandered'
コード例 #34
0
 def take_turn(self):
     if self.num_turns > 0:
         self.owner.creature.move( libtcod.random_get_int(0,-1,1), libtcod.random_get_int(0,-1,1))
         self.num_turns -= 1
     else:
         self.owner.ai = self.old_ai
         game_message( "The creature has broken free!" , constants.COLOR_RED )
コード例 #35
0
def use_bandage(actor):
    """
    First aid skill needs to be at least 2x wounds + 5x bleeding to have a 50-50 chance of making
    things better, but if so it does quite a lot.
    """
    effective_skill = actor.fighter.skills.get(
        'first aid', 0) - actor.fighter.action_penalty
    difficulty = actor.fighter.wounds + actor.fighter.bleeding * 4

    attack_roll = libtcod.random_get_int(0, 1, effective_skill)
    defense_roll = libtcod.random_get_int(0, 1, difficulty)

    if defense_roll > attack_roll:
        log.message("Your efforts don't help.", libtcod.red)
        return

    if actor.fighter.bleeding > 0:
        if actor.fighter.bleeding < attack_roll / 8:
            attack_roll -= actor.fighter.bleeding * 4
            actor.fighter.bleeding = 0
        else:
            attack_roll /= 2
            actor.fighter.bleeding /= 2

    actor.fighter.wounds = max(actor.fighter.wounds - attack_roll, 0)
    log.message("You bandage your wounds.")
コード例 #36
0
ファイル: spells.py プロジェクト: Naburimannu/beyaz-dag
def use_bandage(actor):
    """
    First aid skill needs to be at least 2x wounds + 5x bleeding to have a 50-50 chance of making
    things better, but if so it does quite a lot.
    """
    effective_skill = actor.fighter.skills.get('first aid', 0) - actor.fighter.action_penalty
    difficulty = actor.fighter.wounds + actor.fighter.bleeding * 4

    attack_roll = libtcod.random_get_int(0, 1, effective_skill)
    defense_roll = libtcod.random_get_int(0, 1, difficulty)

    if defense_roll > attack_roll:
        log.message("Your efforts don't help.", libtcod.red)
        return

    if actor.fighter.bleeding > 0:
        if actor.fighter.bleeding < attack_roll / 8:
            attack_roll -= actor.fighter.bleeding * 4
            actor.fighter.bleeding = 0
        else:
            attack_roll /= 2
            actor.fighter.bleeding /= 2

    actor.fighter.wounds = max(actor.fighter.wounds - attack_roll, 0)
    log.message("You bandage your wounds.")
コード例 #37
0
    def place_creatures(self, creature_type, room):
        creatures = filter(lambda m: m['type'] == creature_type,
                           objects.MONSTER_TEMPLATES)
        if len(creatures) == 0:
            return

        # Random number of creatures
        max_creatures = from_dungeon_level(
            self.CREATURE_CHANCES[creature_type], self._game.dungeon_level)
        num_creatures = libtcod.random_get_int(0, 0, max_creatures)
        creature_chances = get_spawn_chances(creatures,
                                             self._game.dungeon_level)

        chance = libtcod.random_get_int(0, 1, 100)
        if chance <= 5:
            num_creatures = max_creatures * 3

        for i in range(num_creatures):
            # Random position for creature
            point = room.random_point_inside()

            if not is_blocked(self.map, self.game_actors, point):
                choice = random_choice(creature_chances)
                creature = objects.new_monster(self._game, choice, point)
                self.game_actors.append(creature)
コード例 #38
0
ファイル: examplerl2.py プロジェクト: nrberens/Purge
def place_objects(room):
    #choose random number of monsters
    num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)
 
    for i in range(num_monsters):
        #choose random spot for this monster
        x = libtcod.random_get_int(0, room.x1, room.x2)
        y = libtcod.random_get_int(0, room.y1, room.y2)
 
        #only place it if the tile is not blocked
        if not is_blocked(x, y):

            # create stairs
            '''if libtcod.random_get_int(0, 0, 100) < 100:
                #this is a better way to call this
                objects.append(Object(x,y, '>', 'stairs', libtcod.grey, blocks=False))'''
                #stairs= Object(x,y, '>', 'stairs', libtcod.grey, blocks=False)
            
                
            if libtcod.random_get_int(0, 0, 100) < 80:  #80% chance of getting an orc
                #create an orc
                fighter_component = Fighter(hp=10, defense=0, power=3, xp=0, death_function=monster_death)
                ai_component = BasicMonster()
 
                monster = Object(x, y, '#', 'orc', libtcod.desaturated_green,
                    blocks=True, fighter=fighter_component, ai=ai_component)
            else:
                #create a troll
                fighter_component = Fighter(hp=16, defense=1, power=4, xp=0, death_function=monster_death)
                ai_component = BasicMonster()
 
                monster = Object(x, y, '&', 'troll', libtcod.darker_green,
                    blocks=True, fighter=fighter_component, ai=ai_component)
 
            objects.append(monster)
コード例 #39
0
    def generate_floors(self, level=1, num=5):
        for ID in range(num):
            monster_num = libtcod.random_get_int(0, 10, 25)
            item_num = libtcod.random_get_int(0, 5, 15)
            a_items = []
            a_monst = []
            for n in range(monster_num):
                key = random.choice(MONSTERS[str(self.level)].keys())
                mons = MONSTERS[str(self.level)][key]
                #not finsiehd yet.
                colour = libtcod.Color(mons["colour"][0], mons["colour"][1],
                                       mons["colour"][2])
                temp = entities.Object(0,
                                       0,
                                       char=mons["char"],
                                       name=mons["name"],
                                       colour=colour,
                                       blocks=False,
                                       always_visible=False)

                a_monst.append(mons)
            for n in range(item_num):
                item = random.choice(ITEMS)
                #colour = libtcod.Color(item["colour"][0],item["colour"][1],item["colour"][2])
                #temp = entities.Object(0,0, char=item["char"], name=item["name"], colour=colour, blocks=False, always_visible=False)
                a_items.append(item)
            floor = Floor(ID, a_monst, a_items)
            self.floors.append(floor)
コード例 #40
0
def make_map():
    global map, player

    #fill map with "blocked" tiles
    map = [[Tile(True) for y in range(MAP_HEIGHT)] for x in range(MAP_WIDTH)]

    rooms = []
    num_rooms = 0

    for r in range(MAX_ROOMS):
        #random width and height
        w = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        #random position without going out of the boundaries of the map
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)

        #"Rect" class makes rectangles easier to work with
        new_room = Rect(x, y, w, h)

        #run through the other rooms and see if they intersect with this one
        failed = False
        for other_room in rooms:
            if new_room.intersect(other_room):
                failed = True
                break

        if not failed:
            #this means there are no intersections, so this room is valid

            #"paint" it to the map's tiles
            create_room(new_room)

            #center coordinates of new room, will be useful later
            (new_x, new_y) = new_room.center()

            if num_rooms == 0:
                #this is the first room, where the player starts at
                player.x = new_x
                player.y = new_y
            else:
                #all rooms after the first:
                #connect it to the previous room with a tunnel

                #center coordinates of previous room
                (prev_x, prev_y) = rooms[num_rooms - 1].center()

                #draw a coin (random number that is either 0 or 1)
                if libtcod.random_get_int(0, 0, 1) == 1:
                    #first move horizontally, then vertically
                    create_h_tunnel(prev_x, new_x, prev_y)
                    create_v_tunnel(prev_y, new_y, new_x)
                else:
                    #first move vertically, then horizontally
                    create_v_tunnel(prev_y, new_y, prev_x)
                    create_h_tunnel(prev_x, new_x, new_y)

            #finally, append the new room to the list
            rooms.append(new_room)
            num_rooms += 1
コード例 #41
0
def RoomCrossCenter(prev_x, prev_y, center_x, center_y):
	#If previous room is in top left relative to new room
	if (prev_x < center_x and prev_y < center_y):
		if libtcod.random_get_int(0, 0, 1) == 1:
			return (center_x, center_y-2)
		else:
			return (center_x-2, center_y)
	#If room is in bottom right
	elif (prev_x >= center_x and prev_y >= center_y):
		if libtcod.random_get_int(0, 0, 1) == 1:
			return (center_x, center_y+2)
		else:
			return (center_x+2, center_y)
	#If room is in bottom left relative to new room
	elif (prev_x < center_x and prev_y >= center_y):
		if libtcod.random_get_int(0, 0, 1) == 1:
			return (center_x, center_y+2)
		else:
			return (center_x-2, center_y)
	#If old room is in top right
	elif (prev_x >= center_x and prev_y < center_y):
		if libtcod.random_get_int(0, 0, 1) == 1:
			return (center_x, center_y-2)
		else:
			return (center_x+2, center_y)
	else:
		return (center_x, center_y)
コード例 #42
0
def CreateRandomWalkableCoords():
	x = libtcod.random_get_int(0,0,MAP_WIDTH-1)
	y = libtcod.random_get_int(0,0,MAP_HEIGHT-1)
	while 'Impassable' in Map[x][y].flags:
		x = libtcod.random_get_int(0,0,MAP_WIDTH-1)
		y = libtcod.random_get_int(0,0,MAP_HEIGHT-1)
	return Coord(x,y,'Coords for ' + str(x) + ',' + str(y))
コード例 #43
0
ファイル: firstrl.py プロジェクト: nrberens/Purge
	def attack(self, target):
		
		if	self.owner==player:
			#if player, use player attack stats
			hitdie = player.stats.hitdie
			mindmg = player.stats.mindmg
			maxdmg = player.stats.maxdmg
		else:
			#not player, use filler stats
			hitdie = 2
			mindmg = 1
			maxdmg = 5
			
		if libtcod.random_get_int(0,1,20) > hitdie:
			#hit!
			message('hit!')
			#determine damage
			damage = libtcod.random_get_int(0, mindmg, maxdmg) - target.fighter.defense
		else:
			#miss!
			message('miss!')
			damage = 0

		if damage > 0:
			#make the target take some damage
			message(self.owner.name.capitalize() + ' attacks ' + target.name + ' for ' + str(damage) + ' hit points.')
			target.fighter.take_damage(damage)
		else:
			message(self.owner.name.capitalize() + ' attacks ' + target.name + ' but it has no effect!')
コード例 #44
0
ファイル: object.py プロジェクト: GrishdaFish/Ascension
 def take_turn(self,game):
     self.owner.fighter.ticker.schedule_turn(self.owner.fighter.speed,self.owner)
     
     if self.dest and self.owner.distance(self.dest_x,self.dest_y) <= 0:
         self.dest = False
         
     if self.dest and self.owner.distance(self.dest_x,self.dest_y) > 0:
         self.owner.move_towards(self.dest_x,self.dest_y,game.Map.map,game.objects)
         
     if not self.dest:
         picked = False
         while not picked:
             min_x,max_x = self.home_x-self.radius,self.home_x+self.radius
             min_y,max_y = self.home_y-self.radius,self.home_y+self.radius    
         
             mx,my = game.Map.MAP_WIDTH,game.Map.MAP_HEIGHT
             
             #make sure min and max values are within the boundaries of the map
             if not min_x <=0 or not min_y <=0 or not max_x >= my or not max_y >= mx:
                 self.dest_x=libtcod.random_get_int(0,min_x+1,max_x-1)
                 self.dest_y=libtcod.random_get_int(0,min_y+1,max_y-1)
             
                 if not game.Map.map[self.dest_x][self.dest_y].blocked and not self.owner.distance(self.dest_x,self.dest_y) == 0:
                     picked = True
                     
         self.owner.move_towards(self.dest_x,self.dest_y,game.Map.map,game.objects)
         
     if libtcod.map_is_in_fov(game.fov_map, self.owner.x, self.owner.y):
         self.owner.ai = BasicMonster()
         self.owner.ai.owner = self.owner
コード例 #45
0
ファイル: worldgen.py プロジェクト: pom2ter/immortal
	def place_dungeons(self):
		print 'Placing dungeons....'
		t0 = libtcod.sys_elapsed_seconds()
		path = self.set_dijkstra_map()
		for i in range(game.MAX_THREAT_LEVEL):
			done = False
			attempt = 0
			while not done and attempt <= 1000:
				x = libtcod.random_get_int(self.rnd, 0, game.WORLDMAP_WIDTH - 1)
				y = libtcod.random_get_int(self.rnd, 0, game.WORLDMAP_HEIGHT - 1)
				cellheight = int(libtcod.heightmap_get_value(game.heightmap, x, y) * 1000)
				threat = self.set_threat_level(x, y, path)
				dice = libtcod.random_get_int(self.rnd, 1, 100)
				if dice <= 65:
					dtype = 'Dungeon'
				elif dice <= 95:
					dtype = 'Cave'
				else:
					dtype = 'Maze'
				if cellheight in range(int(game.terrain['Plains']['elevation'] * 1000), int(game.terrain['High Hills']['maxelev'] * 1000)) and threat == i + 1:
					self.dungeons.append((len(self.dungeons) + 1, 'Dungeon', 'Dng', x, y, threat + 1, dtype))
					done = True
				attempt += 1

		starter_dungeon = libtcod.random_get_int(self.rnd, 1, 4)
		if starter_dungeon == 1:
			self.dungeons.append((len(self.dungeons) + 1, 'Starter Dungeon', 'SD', self.player_positionx, self.player_positiony - 1, 1, 'Dungeon'))
		elif starter_dungeon == 2:
			self.dungeons.append((len(self.dungeons) + 1, 'Starter Dungeon', 'SD', self.player_positionx + 1, self.player_positiony, 1, 'Dungeon'))
		elif starter_dungeon == 3:
			self.dungeons.append((len(self.dungeons) + 1, 'Starter Dungeon', 'SD', self.player_positionx, self.player_positiony + 1, 1, 'Dungeon'))
		else:
			self.dungeons.append((len(self.dungeons) + 1, 'Starter Dungeon', 'SD', self.player_positionx - 1, self.player_positiony, 1, 'Dungeon'))
		t1 = libtcod.sys_elapsed_seconds()
		print '    done! (%.3f seconds)' % (t1 - t0)
コード例 #46
0
ファイル: Roguelike.py プロジェクト: 0penSystem/PyRogue
def place_objects(room):
    # choose random number of monsters
    num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)

    for i in range(num_monsters):
        # choose random spot for this monster
        x = libtcod.random_get_int(0, room.x1, room.x2)
        y = libtcod.random_get_int(0, room.y1, room.y2)

        # only place it if the tile is not blocked
        if not is_blocked(x, y):
            if libtcod.random_get_int(0, 0, 100) < 80:  # 80% chance of getting an orc
                # create an orc
                fighter_component = Fighter(hp=10, defense=0, power=3, death_function=monster_death)
                ai_component = BasicMonster()

                monster = Object(
                    x, y, "o", "orc", libtcod.desaturated_green, blocks=True, fighter=fighter_component, ai=ai_component
                )
            else:
                # create a troll
                fighter_component = Fighter(hp=16, defense=1, power=4, death_function=monster_death)
                ai_component = BasicMonster()

                monster = Object(
                    x, y, "T", "troll", libtcod.darker_green, blocks=True, fighter=fighter_component, ai=ai_component
                )

            objects.append(monster)
コード例 #47
0
ファイル: roguelike.py プロジェクト: d-delta/roguelike
def place_objects(room):
    #choose random number of monsters
    num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)

    for i in range(num_monsters):
        #choose random spot for this monster
        x = libtcod.random_get_int(0, room.x1, room.x2)
        y = libtcod.random_get_int(0, room.y1, room.y2)

        #only place it if the tile is not blocked
        if not is_blocked(x, y):
            if libtcod.random_get_int(0, 0,
                                      100) < 80:  #80% chance of getting an orc
                #create an orc
                monster = Object(x,
                                 y,
                                 'o',
                                 'orc',
                                 libtcod.desaturated_green,
                                 blocks=True)
            else:
                #create a troll
                monster = Object(x,
                                 y,
                                 'T',
                                 'troll',
                                 libtcod.darker_green,
                                 blocks=True)

            objects.append(monster)
コード例 #48
0
ファイル: Tower.py プロジェクト: HommeBarbu/PyRL
def make_map():
    global map, player

    # fill map with "blocked" tiles
    map = [[Tile(True) for y in range(MAP_HEIGHT)] for x in range(MAP_WIDTH)]

    rooms = []
    num_rooms = 0

    for r in range(MAX_ROOMS):
        # random width and height
        w = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        # random position without going out of the boundaries of the map
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)

        # "Rect" class makes rectangles easier to work with
        new_room = Rect(x, y, w, h)

        # run through the other rooms and see if they intersect with this one
        failed = False
        for other_room in rooms:
            if new_room.intersect(other_room):
                failed = True
                break

        if not failed:
            # this means there are no intersections, so this room is valid

            # "paint" it to the map's tiles
            create_room(new_room)

            # center coordinates of new room, will be useful later
            (new_x, new_y) = new_room.center()

            if num_rooms == 0:
                # this is the first room, where the player starts at
                player.x = new_x
                player.y = new_y
            else:
                # all rooms after the first:
                # connect it to the previous room with a tunnel

                # center coordinates of previous room
                (prev_x, prev_y) = rooms[num_rooms - 1].center()

                # draw a coin (random number that is either 0 or 1)
                if libtcod.random_get_int(0, 0, 1) == 1:
                    # first move horizontally, then vertically
                    create_h_tunnel(prev_x, new_x, prev_y)
                    create_v_tunnel(prev_y, new_y, new_x)
                else:
                    # first move vertically, then horizontally
                    create_v_tunnel(prev_y, new_y, prev_x)
                    create_h_tunnel(prev_x, new_x, new_y)

            # finally, append the new room to the list
            rooms.append(new_room)
            num_rooms += 1
コード例 #49
0
ファイル: GEAR.py プロジェクト: HelloLion/muscle-wizard
	def pick_up(self):
		#add to the player's inventory and remove from the map
		if len(inventory) >= 26:
			sarcasm = libtcod.random_get_int(0, 0, 100)
			if sarcasm <= 20: 
				message('You cannot carry any more items, puny man.', libtcod.dark_lime)
			elif sarcasm <= 40 and sarcasm > 20: 
				message('Do you really need ' + self.owner.name + '? Cause if you do, you better get rid of some of this other junk.', libtcod.dark_lime)
			elif sarcasm <= 60 and sarcasm > 40: 
				message('Hoarding is not healthy. You must shed some of your itmes before you can add this one to your horrid collection.', libtcod.dark_lime)
			elif sarcasm <= 80 and sarcasm > 60: 
				message('You must clear some space in your inventory before you can pick up ' + self.owner.name + '. Perhaps you should experiment with some magic potions?', libtcod.dark_lime)
			elif sarcasm <= 100 and sarcasm > 80: 
				message('You simply cannot carry anything more. It would be impossible. Even if you were to have the strength of ten men, you could not best the mysterious limit of 26 that plagues all adventurers.', libtcod.dark_lime)
		else:
			inventory.append(self.owner)
			objects.remove(self.owner)
			sarcasm = libtcod.random_get_int(0, 0, 100)
			if sarcasm <= 20: 
				message('You got yourself a shiny, new ' + self.owner.name + '. (Okay, maybe it was a little used.)', libtcod.lime)
			elif sarcasm <= 40 and sarcasm > 20: 
				message('I hope you know what you are doing by picking up ' + self.owner.name + '.', libtcod.lime)
			elif sarcasm <= 60 and sarcasm > 40: 
				message('You now have a ' + self.owner.name + '. Hooray greed!', libtcod.lime)
			elif sarcasm <= 80 and sarcasm > 60: 
				message('Pretty sweet ' + self.owner.name + ' you got there.', libtcod.lime)
			elif sarcasm <= 100 and sarcasm > 80: 
				message('Oh good, you finally got your own ' + self.owner.name + '. Now you can stop borrowing mine.', libtcod.lime)
コード例 #50
0
def choose_armor_material(loot_level=0):
    roll = libtcodpy.random_get_int(0, 0, min(100 + 30 * loot_level, 150))
    if roll > 100:
        ops = armor_materials.keys()
        return ops[libtcodpy.random_get_int(0, 0, len(ops) - 1)]
    else:
        return ''
コード例 #51
0
ファイル: test_speed_system.py プロジェクト: R7E/RLGame
def place_objects(room):
    #choose random number of monsters
    num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)
 
    for i in range(num_monsters):
        #choose random spot for this monster
        x = libtcod.random_get_int(0, room.x1, room.x2)
        y = libtcod.random_get_int(0, room.y1, room.y2)
 
        #only place it if the tile is not blocked
        if not is_blocked(x, y):
            if libtcod.random_get_int(0, 0, 100) < 50:  #50% chance of getting an orc
                #create an orc
                fighter_component = Fighter(hp=10, defense=0, power=3, death_function=monster_death,
                    )
                ai_component = BasicMonster()
                #for speed smaller is faster
                monster = Object(x, y, 'o', 'orc', libtcod.desaturated_green,
                    blocks=True, fighter=fighter_component, ai=ai_component, speed=DEFAULT_SPEED+libtcod.random_get_int(0, -8, -7) )
            else:
                #create a troll
                fighter_component = Fighter(hp=16, defense=1, power=4, death_function=monster_death,
                     )
                ai_component = BasicMonster()
 
                monster = Object(x, y, 'T', 'troll', libtcod.darker_green,
                    blocks=True, fighter=fighter_component, ai=ai_component, speed=DEFAULT_SPEED+libtcod.random_get_int(0, 7, 8))
 
            objects.append(monster)
コード例 #52
0
ファイル: game.py プロジェクト: gatesphere/libtcodpy-tutorial
 def take_turn(self):
   if self.num_turns > 0:
     self.owner.move(libtcod.random_get_int(0, -1, 1), libtcod.random_get_int(0, -1, 1))
     self.num_turns -= 1
   else:
     self.owner.ai = self.old_ai
     message('The ' + self.owner.name + ' is no longer confused!', libtcod.red)
コード例 #53
0
ファイル: main.py プロジェクト: flappity/Dogelike
 def take_turn(self):
     if self.num_turns > 0:
         self.owner.move(libtcod.random_get_int(0, -1, 1), libtcod.random_get_int(0, -1, 1))
         self.num_turns += -1
     else:
         self.owner.ai = self.old_ai
         message('The ' + self.owner.name + ' has shaken off the confusion!', libtcod.light_azure)
コード例 #54
0
def random_point_surrounding(position):
    p = Position(libtcod.random_get_int(0, position.x - 1, position.x + 1),
                 libtcod.random_get_int(0, position.y - 1, position.y + 1))
    while p.x == position.x and p.y == position.y:
        p = Position(libtcod.random_get_int(0, position.x - 1, position.x + 1),
                     libtcod.random_get_int(0, position.y - 1, position.y + 1))
    return p
コード例 #55
0
def make_outdoor_map():
    global map

    # Fill map with "unblocked" tiles
    data = libtcod.noise_get(height_map, [10, 10])
    map = [[Tile(False, data=TILE_TYPE['GRASS_3']) for y in range(MAP_HEIGHT)]
           for x in range(MAP_WIDTH)]

    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            data = libtcod.noise_get(height_map, [x * 0.1, y * 0.1],
                                     libtcod.NOISE_PERLIN)
            # print data
            if data > 0.2: data = TILE_TYPE['GRASS_1']
            elif data < -0.2: data = TILE_TYPE['GRASS_3']
            else: data = TILE_TYPE['GRASS_2']
            map[y][x].data = data

    buildings = []
    num_buildings = 0

    for r in range(MAX_ROOMS):
        #random width and height
        w = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        #random position without going out of the boundaries of the map
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)

        #"Rect" class makes rectangles easier to work with
        new_room = Rect(x, y, w, h)

        #run through the other buildings and see if they intersect with this one
        failed = False
        for other_room in buildings:
            if new_room.intersect(other_room):
                failed = True
                break

        if not failed:
            #this means there are no intersections, so this room is valid

            #"paint" it to the map's tiles
            create_building(new_room)

            #center coordinates of new room, will be useful later
            (new_x, new_y) = new_room.center()

            if num_buildings == 0:
                #this is the first room, where the player starts at
                player.x = new_x
                player.y = new_y

            # Add some objects to the room
            place_objects(new_room)

            #finally, append the new room to the list
            buildings.append(new_room)
            num_buildings += 1
コード例 #56
0
def make_map():
	global map

	#fill map with 'unblocked' tiles
	map = [[ Tile(True)
		for y in range(MAP_HEIGHT)]
			for x in range(MAP_WIDTH)]

	rooms = []
	num_rooms =0

	for r in range(MAX_ROOMS):
		#random height and width
		w = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
		h = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
		#random position
		x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
		y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)

		new_room = Rect(x, y, w, h)
		failed = False
		for other_room in rooms:
			if new_room.intersect(other_room):
				failed = True
				break

		if not failed:
			# if no intersections paint new map tiles
			create_room(new_room)

			#add some content to this room
			place_objects(new_room)


			(new_x, new_y) = new_room.center()

			'''room_no = Object(new_x, new_y, chr(65+num_rooms), libtcod.white)
			objects.insert(0, room_no)'''

			if num_rooms == 0:
				player.x = new_x
				player.y = new_y

			else:
				#all rooms after the first:
				# connect it to the previous with tunnel

				# center coordinates of previous room
				(prev_x, prev_y) = rooms[num_rooms-1].center()

				if libtcod.random_get_int(0, 0, 1) == 1:
					create_h_tunnel(prev_x, new_x, prev_y)
					create_v_tunnel(prev_y, new_y, new_x)
				else:
					create_v_tunnel(prev_y, new_y, prev_x)
					create_h_tunnel(prev_x, new_x, new_y)

			rooms.append(new_room)
			num_rooms += 1
コード例 #57
0
def make_map():
    global tile_map, objects
    global num_downstairs, num_upstairs

    objects = [player]

    rooms = []
    num_rooms = 0
    num_downstairs = 0
    num_upstairs = 0

    # fill map with "unblocked" tiles
    tile_map = [[Tile(blocked=True) for y in xrange(MAP_HEIGHT)]
                for x in xrange(MAP_WIDTH)]

    for r in xrange(MAX_ROOMS):
        # random width and height
        w = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)

        new_room = Rect(x, y, w, h)

        failed = False
        if in_map(x, y) and in_map(x + w, y + h):
            for other_room in rooms:
                if new_room.intersects(other_room):
                    failed = True
                    break
        else:
            failed = True
            r -= 1

        if not failed:
            create_room(new_room)
            # add some contents to this room, such as monsters
            place_objects(new_room)

            new_x, new_y = new_room.center()

            if num_rooms == 0:
                # place character center of first room
                player.x, player.y = new_room.center()
            else:
                # from second room and beyond connect via tunnel
                prev_x, prev_y = rooms[-1].center()

                # coin toss (random int either 0 or 1)
                if libtcod.random_get_int(0, 0, 1) == 1:
                    create_h_tunnel(prev_x, new_x, prev_y)
                    create_v_tunnel(new_x, prev_y, new_y)
                else:
                    create_v_tunnel(prev_x, prev_y, new_y)
                    create_h_tunnel(prev_x, new_x, new_y)
            rooms.append(new_room)
            num_rooms += 1

    place_stairs(rooms)