How to use the tcod.random_get_int function in tcod

To help you get started, we’ve selected a few tcod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libtcod / python-tcod / examples / samples_libtcodpy.py View on Github external
textColor.r = 255 - textColor.r
        textColor.g = 255 - textColor.g
        textColor.b = 255 - textColor.b
        libtcod.console_set_default_foreground(sample_console, textColor)
        for x in range(SAMPLE_SCREEN_WIDTH):
            for y in range(SAMPLE_SCREEN_HEIGHT):
                col = libtcod.console_get_char_background(sample_console, x, y)
                col = libtcod.color_lerp(col, libtcod.black, 0.5)
                c = libtcod.random_get_int(None, ord('a'), ord('z'))
                libtcod.console_set_default_foreground(sample_console, col)
                libtcod.console_put_char(sample_console, x, y, c,
                                         libtcod.BKGND_NONE)
    else:
        # same, but using the ConsoleBuffer class to speed up rendering
        buffer = libtcod.ConsoleBuffer(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT)  # initialize buffer
        c = libtcod.random_get_int(None, ord('a'), ord('z'))
        for x in range(SAMPLE_SCREEN_WIDTH):
            xcoef = float(x) / (SAMPLE_SCREEN_WIDTH - 1)
            top = libtcod.color_lerp(tc_cols[TOPLEFT], tc_cols[TOPRIGHT], xcoef)
            bottom = libtcod.color_lerp(tc_cols[BOTTOMLEFT], tc_cols[BOTTOMRIGHT], xcoef)
            for y in range(SAMPLE_SCREEN_HEIGHT):
                # for maximum speed, we avoid using any libtcod function in
                # this inner loop, except for the ConsoleBuffer's functions.
                ycoef = float(y) / (SAMPLE_SCREEN_HEIGHT - 1)
                r = int(top.r * ycoef + bottom.r * (1 - ycoef))
                g = int(top.g * ycoef + bottom.g * (1 - ycoef))
                b = int(top.b * ycoef + bottom.b * (1 - ycoef))
                c += 1
                if c > ord('z'): c = ord('a')
                # set background, foreground and char with a single function
                buffer.set(x, y, r, g, b, r // 2, g // 2, b // 2, chr(c))
        buffer.blit(sample_console)  # update console with the buffer's contents
github Mysteryquy / Roguelike / src / map_helper.py View on Github external
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))
github Mysteryquy / Roguelike / death.py View on Github external
def death_ice_elemental(monster, killer,):


    chance = tcod.random_get_int(None, 1, 3)
    if chance < 1:

        x, y = monster.owner.x, monster.owner.y
        new_coords = map_helper.search_empty_tile(x, y, 2, 2, exclude_origin=True)
        if new_coords:
            new_mob = monster_gen.gen_elemental_icicle(new_coords, monster.name_instance)
            level.objects.append(new_mob)
            config.GAME.game_message(monster.name_instance + " was smashed but small pieces still remain!", msg_color=constants.COLOR_RED)
    else:
        config.GAME.game_message(monster.name_instance + " is smashed to a icey mess!", constants.COLOR_GREY)
github Mysteryquy / Roguelike / generator.py View on Github external
def gen_weapon_longaxe_2(level, coords):
    x, y = coords

    bonus = tcod.random_get_int(None, 1, 2)

    equipment_com = Equipment(attack_bonus=bonus, equip_text="2 Handed Axe Type 2", value=100,
                              pickup_text="2 Handed Axe Type 2")

    return_object = Actor(x, y, "2 Handed Axe Type 2", animation_key="S_WEP_LONGAXE_2", depth=constants.DEPTH_ITEM,
                          equipment=equipment_com,
                          item=equipment_com)

    return return_object
github Mysteryquy / Roguelike / main_game 08.py View on Github external
def take_turn(self):
		self.owner.move(libtcodpy.random_get_int(None,-1,1), libtcodpy.random_get_int(None,-1,1))
github libtcod / python-tcod / examples / samples_libtcodpy.py View on Github external
# calculate the room size
        minx = node.x + 1
        maxx = node.x + node.w - 1
        miny = node.y + 1
        maxy = node.y + node.h - 1
        if not bsp_room_walls:
            if minx > 1:
                minx -= 1
            if miny > 1:
                miny -=1
        if maxx == SAMPLE_SCREEN_WIDTH - 1:
            maxx -= 1
        if maxy == SAMPLE_SCREEN_HEIGHT - 1:
            maxy -= 1
        if bsp_random_room:
            minx = libtcod.random_get_int(None, minx, maxx - bsp_min_room_size + 1)
            miny = libtcod.random_get_int(None, miny, maxy - bsp_min_room_size + 1)
            maxx = libtcod.random_get_int(None, minx + bsp_min_room_size - 1, maxx)
            maxy = libtcod.random_get_int(None, miny + bsp_min_room_size - 1, maxy)
        # resize the node to fit the room
        node.x = minx
        node.y = miny
        node.w = maxx-minx + 1
        node.h = maxy-miny + 1
        # dig the room
        for x in range(minx, maxx + 1):
            for y in range(miny, maxy + 1):
                bsp_map[x][y] = True
    else:
        # resize the node to fit its sons
        left = libtcod.bsp_left(node)
        right = libtcod.bsp_right(node)
github Mysteryquy / Roguelike / ai.py View on Github external
def take_turn(self) -> None:
        if self.num_turns > 0:
            self.owner.creature.move(tcod.random_get_int(None, -1, 1), tcod.random_get_int(None, -1, 1))

            self.num_turns -= 1

        else:
            self.owner.ai = self.old_ai

            config.GAME.game_message(self.owner.display_name + " has broken free!", constants.COLOR_GREEN)
github libtcod / python-tcod / examples / samples_libtcodpy.py View on Github external
minx = node.x + 1
        maxx = node.x + node.w - 1
        miny = node.y + 1
        maxy = node.y + node.h - 1
        if not bsp_room_walls:
            if minx > 1:
                minx -= 1
            if miny > 1:
                miny -=1
        if maxx == SAMPLE_SCREEN_WIDTH - 1:
            maxx -= 1
        if maxy == SAMPLE_SCREEN_HEIGHT - 1:
            maxy -= 1
        if bsp_random_room:
            minx = libtcod.random_get_int(None, minx, maxx - bsp_min_room_size + 1)
            miny = libtcod.random_get_int(None, miny, maxy - bsp_min_room_size + 1)
            maxx = libtcod.random_get_int(None, minx + bsp_min_room_size - 1, maxx)
            maxy = libtcod.random_get_int(None, miny + bsp_min_room_size - 1, maxy)
        # resize the node to fit the room
        node.x = minx
        node.y = miny
        node.w = maxx-minx + 1
        node.h = maxy-miny + 1
        # dig the room
        for x in range(minx, maxx + 1):
            for y in range(miny, maxy + 1):
                bsp_map[x][y] = True
    else:
        # resize the node to fit its sons
        left = libtcod.bsp_left(node)
        right = libtcod.bsp_right(node)
        node.x = min(left.x, right.x)
github Mysteryquy / Roguelike / generator.py View on Github external
def gen_armor_shield(level, coords):
    x, y = coords

    bonus = tcod.random_get_int(None, 1, 2)
    n = random.choice(list(shield_name_dict))
    random_name = shield_name_dict[n]

    equipment_com = Equipment(defense_bonus=bonus, equip_text=random_name, value=100,
                              pickup_text=random_name)

    return_object = Actor(x, y, random_name, animation_key="S_ARM_SHIELD_" + str(n), depth=constants.DEPTH_ITEM,
                          equipment=equipment_com,
                          item=equipment_com)

    return return_object
github Mysteryquy / Roguelike / casting.py View on Github external
def cast_teleportation(caster, value):
    # generate the target destination
    new_room_number = tcod.random_get_int(None, 0, len(config.GAME.current_rooms) - 1)
    new_room = config.GAME.current_rooms[new_room_number]
    new_x = tcod.random_get_int(None, new_room.left + 1, new_room.right - 1)
    new_y = tcod.random_get_int(None, new_room.top + 1, new_room.bottom - 1)

    if not game_map.check_for_creature(new_x, new_y):
        # add in some cool effects
        config.GAME.game_message("You teleported to a different location!", msg_color=constants.COLOR_BLUE_LIGHT)
        pygame.mixer.Channel(1).play(pygame.mixer.Sound("data/audio/teleport.wav"))
        # actually teleport the player
        caster.x, caster.y = new_x, new_y
        config.FOV_CALCULATE = True

    else:
        pygame.mixer.Channel(1).play(pygame.mixer.Sound("data/audio/teleport_fail.wav"))
        config.GAME.game_message("The spell fizzels and fails! You stay where you were.",
                                 msg_color=constants.COLOR_BLUE_LIGHT)