Esempio n. 1
0
    def scatter(self, toScatter, extantItems):
        # get coordinates of all existing things
        # get new coordinates for each toScatter item
        # place new scatter at their new coordinate
        placedItems = list(extantItems)
        for item in toScatter:
            #Come up with 10 random candidates
            candidateCoords = []
            while len(candidateCoords) < 10:
                cx = 0
                cy = 0
                while self.isBlocked([cx, cy]):
                    cx = libtcod.random_get_int(None, 1, self.MAP_WIDTH - 1)
                    cy = libtcod.random_get_int(None, 1, self.MAP_HEIGHT - 1)
                candidateCoords.append([cx, cy])

            #Loop through all the candidates and choose the one furthest from all the placed items
            furthestCandidate = None
            furthestDistance = None
            for candidate in candidateCoords:
                [closest,
                 closestDistance] = item.findClosest(candidate[0],
                                                     candidate[1], placedItems)
                if furthestCandidate == None or closestDistance > furthestDistance:
                    furthestCandidate = candidate
                    furthestDistance = closestDistance

            self.placeItem(item, furthestCandidate)
            placedItems.append(item)
Esempio n. 2
0
 def getIntent(self, x, y, worldMap):
     self.x = x
     self.y = y
     direction = None
     target = self.updatePathToNearestTarget(x, y, worldMap,
                                             self.avatarTargets)
     if target:
         if self.reachedEndOfPath():
             direction = None
             self.path = None
         else:
             direction = self.followPath()
         if randint(0, 5) == 0 and direction:
             numDirection = self.numberDirection(direction)
             nearbyDirections = {
                 1: [4, 2],
                 2: [1, 3],
                 3: [1, 6],
                 6: [3, 9],
                 9: [6, 8],
                 8: [9, 7],
                 7: [8, 4],
                 4: [7, 1]
             }
             options = nearbyDirections[numDirection]
             newNum = options[randint(0, 1)]
             direction = self.vectorForNum(newNum)
     if direction == None:
         direction = [
             libtcod.random_get_int(0, -1, 1),
             libtcod.random_get_int(0, -1, 1)
         ]
     return {'type': 'move', 'item': 0, 'direction': direction}
Esempio n. 3
0
def place_objects(room):
    global MAX_ROOM_MONSTERS

    num_monsters = tcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)

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

        if not is_blocked(x, y):
            if tcod.random_get_int(0, 0,
                                   100) < 80:  # 80% chance of getting an orc
                monster = Object(x,
                                 y,
                                 'o',
                                 'orc',
                                 tcod.desaturated_green,
                                 blocks=True)
            else:
                monster = Object(x,
                                 y,
                                 'T',
                                 'troll',
                                 tcod.darker_green,
                                 blocks=True)

        objects.append(monster)
Esempio n. 4
0
def make_game_map():
    global game_map

    game_map = [[Tile(True) for y in range(SCREEN_HEIGHT)]
                for x in range(SCREEN_WIDTH)]

    rooms = []
    tried = 0

    for r in range(TRIED_TIMES):
        w = tcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = tcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)

        x = tcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = tcod.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:
            create_room(new_room)
            (new_x, new_y) = new_room.center()

            rooms.append(new_room)
            tried += 1
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)
Esempio n. 6
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 = tcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = tcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        #random position without going out of the boundaries of the map
        x = tcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = tcod.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 tcod.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
Esempio n. 7
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):
            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)
Esempio n. 8
0
    def add_monsters_to_room(self, room, monster_target, monster_cnt):

        for i in range(0, monster_cnt):
            rando_x = tcod.random_get_int(0, room.rect.x,
                                          room.rect.x + room.rect.w - 1)
            rando_y = tcod.random_get_int(0, room.rect.y,
                                          room.rect.y + room.rect.h - 1)

            # Add a monter
            monster_values = list(monsters.values())
            rando_monster_blueprint = monster_values[tcod.random_get_int(
                0, 0,
                len(monster_values) - 1)]

            # OBSOLETE
            #rando_difficulty = ["basic", "intermediary", "advanced"][tcod.random_get_int(0,0,2)]

            monster = rando_monster_blueprint.spawn_instance(
                self.game.floor_manager.current_floor_number, monster_target)
            monster.game = self.game
            monster.combat_behavior.game = self.game
            monster.x = rando_x
            monster.y = rando_y

            # Only adds monster to game if it is not on a tile that has something else on it
            if not (gameobjects_exist_at_point(self.floor, rando_x, rando_y)):
                add_agent_to_floor(self.floor, monster)
Esempio n. 9
0
File: main.py Progetto: Jipes/TYRMA
def arkku_interact(object):
    message("Avaat arkun",libtcod.green)
    loot=[]
    possible=["Taikajuoma","Miekka", "Kilpi","Kakku", "Mokkapala", "Impostor_kakku"]
    morkoarkku=False
    if libtcod.random_get_int(0,1,30)==1:
        morkoarkku=True
    for ox in range(-1,2):
        for oy in range(-1,2):
            if morkoarkku and is_blocked(object.x+ox,object.y+oy)==None:
                thing=new_object("Morko")
                thing.x=object.x+ox
                thing.y=object.y+oy
                objects.append(thing)
            elif libtcod.random_get_int(0,1,6)==1 and is_blocked(object.x+ox,object.y+oy)==None:
                choice=random.choice(possible)
                thing=new_object(choice)
                thing.x=object.x+ox
                thing.y=object.y+oy
                objects.append(thing)
                loot.append(thing.name)
    objects.remove(object)
    objects.append(Object(object.x, object.y, "=", "Tyhjä arkku", libtcod.gray, blocks=False))
    if morkoarkku:
        message("Arkusta hyppää esiin mörköarmeija!",libtcod.red)
    elif len(loot)>0:
        message("Arkusta löytyy "+", ".join(loot))
    else:
        message("Arkku on tyhjä!")
Esempio n. 10
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):
            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)
Esempio n. 11
0
def place_objects(room):
    #random num of monsters
    num_monsters = tcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)

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

        if not is_blocked(x, y):
            if tcod.random_get_int(0, 0, 100) < 80:  #80$ chance of getting orc
                #create orc
                monster = Object(x,
                                 y,
                                 'o',
                                 'orc',
                                 tcod.desaturated_green,
                                 blocks=True)
            else:
                #create a troll
                monster = Object(x,
                                 y,
                                 'T',
                                 'troll',
                                 tcod.darker_green,
                                 blocks=True)

            objects.append(monster)
Esempio n. 12
0
def map_place_objects(room_list):
    if room_list:
        cur_level = len(globalvars.GAME.maps_prev) + 1
        top_level = (cur_level == 1)
        final_level = (cur_level == constants.MAP_LEVELS)
        for room in room_list:
            first_room = (room == room_list[0])
            last_room = (room == room_list[-1])

            if first_room:
                globalvars.PLAYER.x, globalvars.PLAYER.y = room.center

            if first_room and top_level:
                generator.gen_portal(room.center)

            if first_room and not top_level:
                generator.gen_stairs(
                    (globalvars.PLAYER.x, globalvars.PLAYER.y),
                    downwards=False)

            if last_room:
                if final_level:
                    generator.gen_lamp(room.center)
                else:
                    generator.gen_stairs(room.center)

            x = libtcodpy.random_get_int(0, room.x1 + 1, room.x2 - 1)
            y = libtcodpy.random_get_int(0, room.y1 + 1, room.y2 - 1)

            generator.gen_enemy((x, y))

            x = libtcodpy.random_get_int(0, room.x1 + 1, room.x2 - 1)
            y = libtcodpy.random_get_int(0, room.y1 + 1, room.y2 - 1)

            generator.gen_item((x, y))
Esempio n. 13
0
def place_object(room):
    #choose random number of monsters
    num_monsters = tcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)

    for i in range(num_monsters):
        #choose monster spawn
        x = tcod.random_get_int(0, room.x1, room.x2)
        y = tcod.random_get_int(0, room.y1, room.y2)
        choice = tcod.random_get_int(0, 0, 100)

        if not is_blocked(x,y):
            if choice < 40: #80% chance of getting an orc
                #create an orc
                monster = Object(x, y, 'O', 'Orc', tcod.desaturated_green, blocks=True)
            elif choice < 40+10:
                #create a troll
                monster = Object(x, y, 'T', 'Troll', tcod.darker_pink, blocks=True)
            elif choice < 40+10+20:
                #create an undead
                monster = Object(x, y, 'U', 'Undead', tcod.grey, blocks=True)
            elif choice < 40+10+20+20:
                #create a warlock
                monster = Object(x, y, 'W', 'Warolock', tcod.black, blocks=True)
            else:
                #create a demon
                monster = Object(x, y, 'D','Demon', tcod.lightest_red, blocks=True)

            objects.append(monster)
Esempio n. 14
0
def how_much_to_place(level, room_size: int, room: pygame.Rect) -> None:
    count = 2
    for i in range(0, count):
        x = tcod.random_get_int(None, room.left + 1, room.right - 1)
        y = tcod.random_get_int(None, room.top + 1, room.bottom - 1)
        ent = level.first_entity_at_position(Position(x, y))
        if not ent:
            generator.what_to_gen(level, (x, y))
Esempio n. 15
0
    def move(self, path_blocked):
        if self.is_alive:
            x = self.x + libtcodpy.random_get_int(0, -2, 2)
            y = self.y + libtcodpy.random_get_int(0, -2, 2)

            if not path_blocked(x, y):
                self.x = x
                self.y = y
Esempio n. 16
0
def make_map():
    global map

    # 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):
        #rand width and height
        w = tcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = tcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)

        # random pos
        x = tcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = tcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)

        # New room
        new_room = Rect(x, y, w, h)

        # run through other rooms to check for collision
        failed = False

        for other_room in rooms:
            if new_room.intersect(other_room):
                failed = True
                break

        if not failed:
            # paint the room
            create_room(new_room)

            #center coordinates of new room

            (new_x, new_y) = new_room.center()

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

        else:

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

            if tcod.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)
        place_objects(new_room)

        num_rooms += 1
Esempio n. 17
0
 def take_turn(self):
     if self.num_turns > 0:
         self.owner.move(tcod.random_get_int(0, -1, 1),
                         tcod.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!',
                 tcod.red)
Esempio n. 18
0
def create():
    '''Creates the default map.
    Currently, the map this function creatures is a small room with 2 pillars 
    within it.  It is a testing map.
    Returns:
        new_map (array): This array is populated with struc_Tile objects.
    Effects:
        Calls make_fov on new_map to preemptively create the fov.
    '''

    # initializes an empty map
    new_map = [[data.StrucTile(True) for y in range(0, constants.MAP_HEIGHT)]
               for x in range(0, constants.MAP_WIDTH)]

    # generate new room
    list_of_rooms = []

    for i in range(constants.MAP_MAX_NUM_ROOMS):

        w = libtcod.random_get_int(0, constants.ROOM_MIN_WIDTH,
                                   constants.ROOM_MAX_WIDTH)
        h = libtcod.random_get_int(0, constants.ROOM_MIN_HEIGHT,
                                   constants.ROOM_MAX_HEIGHT)

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

        #create the room
        new_room = ObjRoom((x, y), (w, h))

        failed = False

        # check for interference
        for other_room in list_of_rooms:
            if new_room.intersect(other_room):
                failed = True
                break

        if not failed:
            # place room
            create_room(new_map, new_room)
            current_center = new_room.center

            if len(list_of_rooms) != 0:

                previous_center = list_of_rooms[-1].center

                # dig tunnels
                create_tunnels(current_center, previous_center, new_map)

            list_of_rooms.append(new_room)

    # create FOV_MAP
    make_fov(new_map)

    # returns the created map
    return (new_map, list_of_rooms)
    def take_turn(self):
        if self.num_turns > 0:  #still confused...
            #move in a random direction, and decrease the number of turns confused
            self.owner.move(libtcod.random_get_int(0, -1, 1), libtcod.random_get_int(0, -1, 1))
            self.num_turns -= 1
 
        else:  #restore the previous AI (this one will be deleted because it's not referenced anymore)
            self.owner.ai = self.old_ai
            message('The ' + self.owner.name + ' is no longer confused!', libtcod.red)
Esempio n. 20
0
    def take_turn(self):
        if self.num_turns > 0:  #still confused...
            #move in a random direction, and decrease the number of turns confused
            self.owner.move(libtcod.random_get_int(0, -1, 1), libtcod.random_get_int(0, -1, 1))
            self.num_turns -= 1
 
        else:  #restore the previous AI (this one will be deleted because it's not referenced anymore)
            self.owner.ai = self.old_ai
            message('The ' + self.owner.name + ' is no longer confused!', libtcod.red)
Esempio n. 21
0
    def take_turn(self):
        if self.num_turns > 0: #still confused
            #move in random direction
            self.owner.move(libtcod.random_get_int(0, -1, 1), libtcod.random_get_int(0, -1, 1))
            self.num_turns -=1

        else: #restore previous ai
            self.owner.ai = self.old_ai
            message('The ' + self.owner.name + ' is no longer confused!OWO', libtcod.red)
Esempio n. 22
0
 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)
Esempio n. 23
0
def make_map():
    global map, objects

    objects = [player]

    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):
        w = tcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = tcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        # random position without going out of the boundaries of the map
        x = tcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = tcod.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:

            create_room(new_room)

            (new_x, new_y) = new_room.center()
            room_no = Object(new_x,
                             new_y,
                             chr(65 + num_rooms),
                             'room number',
                             tcod.white,
                             blocks=False)
            objects.insert(0, room_no)

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

            else:
                (prev_x, prev_y) = rooms[num_rooms - 1].center()

                if tcod.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)

                place_objects(new_room)

            rooms.append(new_room)
            num_rooms += 1
Esempio n. 24
0
File: main.py Progetto: Jipes/TYRMA
 def randomize_target(self):
     blocked=True
     room = random.choice(rooms)
     while blocked is not None:
         x = libtcod.random_get_int(0, room.x1+1, room.x2-1)
         y = libtcod.random_get_int(0, room.y1+1, room.y2-1)
         blocked=is_blocked(x,y)
         self.target_x=y
         self.target_y=x
     self.recalculate()
Esempio n. 25
0
 def take_turn(self):
     if self.num_turns > 0:
         self.owner.creature.move(libtcodpy.random_get_int(0, -1, 1),
                                  libtcodpy.random_get_int(0, -1, 1))
         self.num_turns -= 1
     else:
         self.owner.ai = self.old_ai
         game.game_message(
             self.owner.display_name + " is no longer confused",
             constants.COLOR_WHITE)
Esempio n. 26
0
 def generate_room(self):
     # get a random width and height
     r_width = tcod.random_get_int(0, self.min_room_size,
                                   self.max_room_size)
     r_height = tcod.random_get_int(0, self.min_room_size,
                                    self.max_room_size)
     # get a random position on the map
     x = tcod.random_get_int(0, 0, self.map_width - r_width - 1)
     y = tcod.random_get_int(0, 0, self.map_height - r_height - 1)
     return Room(x=x, y=y, width=r_width, height=r_height)
Esempio n. 27
0
    def getIntent(self, x, y, worldMap):
        self.x = x
        self.y = y
        target = self.updatePathToNearestTarget(x, y, worldMap,
                                                self.allTargets())
        if target:
            [dx, dy] = self.vectorTowards(target)
            if randint(0, 2) == 0:
                # move randomly
                numDirection = self.numberDirection([dx, dy])
                nearbyDirections = {
                    1: [4, 2],
                    2: [1, 3],
                    3: [1, 6],
                    6: [3, 9],
                    9: [6, 8],
                    8: [9, 7],
                    7: [8, 4],
                    4: [7, 1]
                }
                options = nearbyDirections[numDirection]
                newNum = options[randint(0, 1)]
                [dx2, dy2] = self.vectorForNum(newNum)
                dx = dx2
                dy = dy2
            if randint(0, 4) == 0:
                dx = dx * 2
                dy = dy * 2
            if [dx, dy] == [0, 0]:
                return {
                    'type':
                    'move',
                    'item':
                    0,
                    'direction': [
                        libtcod.random_get_int(0, -1, 1),
                        libtcod.random_get_int(0, -1, 1)
                    ]
                }
            self.lastDirection = [dx, dy]
            return {'type': 'move', 'item': 0, 'direction': self.lastDirection}

        # if self.type == 'random':
        direction = [0, 0]
        if self.lastDirection:
            direction = self.lastDirection
            if randint(0, 5) == 1:
                self.lastDirection = None
        if direction == [0, 0]:
            direction = [
                libtcod.random_get_int(0, -1, 1),
                libtcod.random_get_int(0, -1, 1)
            ]
        return {'type': 'move', 'item': 0, 'direction': direction}
Esempio n. 28
0
    def move(self, path_blocked):
        self._next_step -= 1

        if self._next_step == 0:
            self._next_step = 10

            x = self.x + libtcodpy.random_get_int(0, -1, 1)
            y = self.y + libtcodpy.random_get_int(0, -1, 1)

            if not path_blocked(x, y):
                self.x = x
                self.y = y
Esempio n. 29
0
 def step(self):
     if self.num_turns > 0:  # Still confused...
         # Move in a random direction
         self.owner.move(libtcod.random_get_int(0, -1, 1),
                         libtcod.random_get_int(0, -1, 1))
         self.num_turns -= 1
     else:
         # Remove this confused ai, add the old one back, and inform the player
         self.owner.components.remove(self)
         self.old_ai.active = True
         message("The {0} is no longer confused!".format(self.owner.name),
                 libtcod.red)
Esempio n. 30
0
    def take_turn(self):

        if self.num_turns > 0:
            # Random direction
            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(self.owner.display_name + " has broken free!",
                         constants.COLOR_RED)
Esempio n. 31
0
def scroll_lightning(coords):

    x, y = coords

    damage = libtcod.random_get_int(0, 8, 10)
    m_range = libtcod.random_get_int(0, 8, 9)
    

    item_com = actor.CompItem(use_function = magic.cast_lighting, value = (damage, m_range))
    
    return_object = actor.ObjActor(x, y, "Lightning scroll", animation_key = "S_SCROLL_01", item = item_com)
    
    return return_object
Esempio n. 32
0
def place_map_specific(level):
    if level.name == Levels.WATER1:
        for room in level.rooms:
            for i in range(2):
                x = tcod.random_get_int(None, room.left + 1, room.right - 1)
                y = tcod.random_get_int(None, room.top + 1, room.bottom - 1)
                ent = level.first_entity_at_position(Position(x, y))
                if not ent:
                    level.world.create_entity(
                        Position(x, y), Name("Bubble"),
                        Renderable(animation_key="DECOR_STATUE_01",
                                   depth=constants.DEPTH_STRUCTURES,
                                   special_flags=pygame.BLEND_RGBA_ADD))
Esempio n. 33
0
def test_random():
    rand = libtcodpy.random_get_instance()
    rand = libtcodpy.random_new()
    libtcodpy.random_delete(rand)
    rand = libtcodpy.random_new_from_seed(42)
    libtcodpy.random_set_distribution(rand, libtcodpy.DISTRIBUTION_LINEAR)
    libtcodpy.random_get_int(rand, 0, 1)
    libtcodpy.random_get_int_mean(rand, 0, 1, 0)
    libtcodpy.random_get_float(rand, 0, 1)
    libtcodpy.random_get_double(rand, 0, 1)
    libtcodpy.random_get_float_mean(rand, 0, 1, 0)
    libtcodpy.random_get_double_mean(rand, 0, 1, 0)

    backup = libtcodpy.random_save(rand)
    libtcodpy.random_restore(rand, backup)

    libtcodpy.random_delete(rand)
    libtcodpy.random_delete(backup)
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)
def random_choice_index(chances):  #choose one option from list of chances, returning its index
    #the dice will land on some number between 1 and the sum of the chances
    dice = libtcod.random_get_int(0, 1, sum(chances))
 
    #go through all chances, keeping the sum so far
    running_sum = 0
    choice = 0
    for w in chances:
        running_sum += w
 
        #see if the dice landed in the part that corresponds to this choice
        if dice <= running_sum:
            return choice
        choice += 1
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+1, room.x2-1)
        y = libtcod.random_get_int(0, room.y1+1, room.y2-1)
 
        #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)
 
    #choose random number of items
    num_items = libtcod.random_get_int(0, 0, MAX_ROOM_ITEMS)
 
    for i in range(num_items):
        #choose random spot for this item
        x = libtcod.random_get_int(0, room.x1+1, room.x2-1)
        y = libtcod.random_get_int(0, room.y1+1, room.y2-1)
 
        #only place it if the tile is not blocked
        if not is_blocked(x, y):
            #create a healing potion
            item_component = Item(use_function=cast_heal)
 
            item = Object(x, y, '!', 'healing potion', libtcod.violet, item=item_component)
 
            objects.append(item)
            item.send_to_back()  #items appear below other objects
def place_objects(room):
    #this is where we decide the chance of each monster or item appearing.
 
    #maximum number of monsters per room
    max_monsters = from_dungeon_level([[2, 1], [3, 4], [5, 6]])
 
    #chance of each monster
    monster_chances = {}
    monster_chances['orc'] = 80  #orc always shows up, even if all other monsters have 0 chance
    monster_chances['troll'] = from_dungeon_level([[15, 3], [30, 5], [60, 7]])
 
    #maximum number of items per room
    max_items = from_dungeon_level([[1, 1], [2, 4]])
 
    #chance of each item (by default they have a chance of 0 at level 1, which then goes up)
    item_chances = {}
    item_chances['heal'] = 35  #healing potion always shows up, even if all other items have 0 chance
    item_chances['lightning'] = from_dungeon_level([[25, 4]])
    item_chances['fireball'] =  from_dungeon_level([[25, 6]])
    item_chances['confuse'] =   from_dungeon_level([[10, 2]])
 
 
    #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)
 
        #only place it if the tile is not blocked
        if not is_blocked(x, y):
            choice = random_choice(monster_chances)
            if choice == 'orc':
                #create an orc
                fighter_component = Fighter(hp=20, defense=0, power=4, xp=35, death_function=monster_death)
                ai_component = BasicMonster()
 
                monster = Object(x, y, 'o', 'orc', libtcod.desaturated_green,
                    blocks=True, fighter=fighter_component, ai=ai_component)
 
            elif choice == 'troll':
                #create a troll
                fighter_component = Fighter(hp=30, defense=2, power=8, xp=100, 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)
 
    #choose random number of items
    num_items = libtcod.random_get_int(0, 0, max_items)
 
    for i in range(num_items):
        #choose random spot for this item
        x = libtcod.random_get_int(0, room.x1+1, room.x2-1)
        y = libtcod.random_get_int(0, room.y1+1, room.y2-1)
 
        #only place it if the tile is not blocked
        if not is_blocked(x, y):
            choice = random_choice(item_chances)
            if choice == 'heal':
                #create a healing potion
                item_component = Item(use_function=cast_heal)
                item = Object(x, y, '!', 'healing potion', libtcod.violet, item=item_component)
 
            elif choice == 'lightning':
                #create a lightning bolt scroll
                item_component = Item(use_function=cast_lightning)
                item = Object(x, y, '#', 'scroll of lightning bolt', libtcod.light_yellow, item=item_component)
 
            elif choice == 'fireball':
                #create a fireball scroll
                item_component = Item(use_function=cast_fireball)
                item = Object(x, y, '#', 'scroll of fireball', libtcod.light_yellow, item=item_component)
 
            elif choice == 'confuse':
                #create a confuse scroll
                item_component = Item(use_function=cast_confuse)
                item = Object(x, y, '#', 'scroll of confusion', libtcod.light_yellow, item=item_component)
 
            objects.append(item)
            item.send_to_back()  #items appear below other objects
            item.always_visible = True  #items are visible even out-of-FOV, if in an explored area
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