コード例 #1
0
ファイル: display.py プロジェクト: witheld9/r3-tdw
def boot():
	global SCREEN

	framework.events.register_event('draw', blit)

	tcod.console_set_custom_font(os.path.join('data', 'tiles', 'dejavu_wide12x12_gs_tc.png'),#,'consolas10x10_gs_tc.png')
	                             flags=tcod.FONT_LAYOUT_TCOD|tcod.FONT_TYPE_GREYSCALE)
	tcod.console_init_root(constants.WINDOW_WIDTH,
	                       constants.WINDOW_HEIGHT,
	                       constants.WINDOW_TITLE,
	                       fullscreen='--fullscreen' in sys.argv,
	                       renderer=tcod.RENDERER_GLSL)
	tcod.console_set_keyboard_repeat(200, 0)
	tcod.sys_set_fps(constants.FPS)	
	tcod.mouse_show_cursor(constants.SHOW_MOUSE)

	SCREEN['c'] = numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH), dtype=numpy.int32)
	SCREEN['d'] = '0'*(constants.WINDOW_HEIGHT*constants.WINDOW_WIDTH)
	SCREEN['r'] = []

	SCREEN['f'] = []
	SCREEN['f'].append(numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH), dtype=numpy.int16))
	SCREEN['f'].append(numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH), dtype=numpy.int16))
	SCREEN['f'].append(numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH), dtype=numpy.int16))

	SCREEN['b'] = []
	SCREEN['b'].append(numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH), dtype=numpy.int16))
	SCREEN['b'].append(numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH), dtype=numpy.int16))
	SCREEN['b'].append(numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH), dtype=numpy.int16))
コード例 #2
0
ファイル: display.py プロジェクト: penny64/r3-tdw
def boot():
    global SCREEN

    framework.events.register_event('draw', blit)

    tcod.console_set_custom_font(
        os.path.join(
            'data', 'tiles',
            'dejavu_wide12x12_gs_tc.png'),  #,'consolas10x10_gs_tc.png')
        flags=tcod.FONT_LAYOUT_TCOD | tcod.FONT_TYPE_GREYSCALE)
    tcod.console_init_root(constants.WINDOW_WIDTH,
                           constants.WINDOW_HEIGHT,
                           constants.WINDOW_TITLE,
                           fullscreen='--fullscreen' in sys.argv,
                           renderer=tcod.RENDERER_GLSL)
    tcod.console_set_keyboard_repeat(200, 0)
    tcod.sys_set_fps(constants.FPS)
    tcod.mouse_show_cursor(constants.SHOW_MOUSE)

    SCREEN['c'] = numpy.zeros(
        (constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH), dtype=numpy.int32)
    SCREEN['d'] = '0' * (constants.WINDOW_HEIGHT * constants.WINDOW_WIDTH)
    SCREEN['r'] = []

    SCREEN['f'] = []
    SCREEN['f'].append(
        numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH),
                    dtype=numpy.int16))
    SCREEN['f'].append(
        numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH),
                    dtype=numpy.int16))
    SCREEN['f'].append(
        numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH),
                    dtype=numpy.int16))

    SCREEN['b'] = []
    SCREEN['b'].append(
        numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH),
                    dtype=numpy.int16))
    SCREEN['b'].append(
        numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH),
                    dtype=numpy.int16))
    SCREEN['b'].append(
        numpy.zeros((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH),
                    dtype=numpy.int16))
コード例 #3
0
def test_mouse(console):
    libtcodpy.mouse_show_cursor(True)
    libtcodpy.mouse_is_cursor_visible()
    mouse = libtcodpy.mouse_get_status()
    repr(mouse)
    libtcodpy.mouse_move(0, 0)
コード例 #4
0
ファイル: mouse_test.py プロジェクト: brycepg/cave-dweller
import sys
sys.path.append('cave_dweller')
import libtcodpy as libtcod

from game import Game

font_size_index = 0
libtcod.console_set_custom_font(os.path.join('fonts', 'dejavu{size}x{size}_gs_tc.png'.format(size=Game.font_sizes[font_size_index])), libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(Game.screen_width, Game.screen_height, 'Cave Dweller', libtcod.RENDERER_GLSL)
libtcod.console_set_default_background(0,libtcod.red)
mouse_con = libtcod.console_new(Game.screen_width, Game.screen_height)
libtcod.console_set_default_background(mouse_con,None)
libtcod.sys_set_fps(40)
mouse = libtcod.Mouse()
libtcod.mouse_show_cursor(False)
key = libtcod.Key()
while True:
    libtcod.sys_check_for_event(libtcod.EVENT_ANY, key, mouse)
    print((mouse.cx, mouse.cy))
    print(libtcod.console_has_mouse_focus())
    libtcod.console_clear(0)
    libtcod.console_clear(mouse_con)
    libtcod.console_put_char_ex(0, 10, 10, ord(' '), None, libtcod.black)
    # There's a bug where has mouse focus returns true if the mouse starts on 
    # the console. (hence the edge checks)
    if libtcod.console_has_mouse_focus() or ((mouse.cx != 0 and mouse.cy != 0) and (mouse.cx != 0 and mouse.cy != Game.screen_height-1) and (mouse.cx != Game.screen_width-1 and mouse.cy != Game.screen_height-1) and (mouse.cx != Game.screen_width-1 and mouse.cy != 0)):
        libtcod.console_put_char_ex(mouse_con, mouse.cx, mouse.cy, ord('x'), libtcod.yellow, None)
    #console_blit(src,xSrc,ySrc,xSrc,hSrc,dst,xDst,yDst,foregroundAlpha=1.0,backgroundAlpha=1.0)
    libtcod.console_blit(mouse_con, x=0, y=0, w=0, h=0, dst=0, xdst=0, ydst=0, ffade=.75, bfade=.0)
    libtcod.console_flush()
コード例 #5
0
ファイル: pyMemory.py プロジェクト: Dozed12/pyMemory
import libtcodpy as libtcod
from random import randint
import time
import sys

SCREEN_WIDTH = 60
SCREEN_HEIGHT = 60

libtcod.console_set_custom_font("cp437_12x12.png", libtcod.FONT_LAYOUT_ASCII_INROW)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'pyMemory', False, libtcod.RENDERER_OPENGL)
libtcod.mouse_show_cursor (True)

mouse = libtcod.Mouse()
key = libtcod.Key()

def DrawSquare(x,y,size,color): #x and y are upper left coordinates, size is side of square, color is color of square

    for a in range(size):
        for b in range(size):
            libtcod.console_put_char_ex(None,x+a,y+b,219,color,libtcod.white)

    return

def MouseSquare(mouse,x,y,size): #mouse is mouse,x and y are upper left coordinates, size is side of square

    if mouse.cx >= x and mouse.cx <= x + size and mouse.cy >= y and mouse.cy <= y + size:
        return True
    return False

while not libtcod.console_is_window_closed():    
コード例 #6
0
ファイル: main.py プロジェクト: orodley/stalker-rl
def play_arena(ui_con):
    console_buffer = tcod.ConsoleBuffer(constant.SCREEN_WIDTH, constant.SCREEN_HEIGHT)

    map_size = (constant.SCREEN_WIDTH * 1, constant.SCREEN_HEIGHT * 1)
    the_map = game_map.make_map(*map_size)
    fov_map = tcod.map_new(*map_size)

    player = entity.Entity(map_size[0] / 2, map_size[1] / 2, "@", tcod.black)
    player.inventory_component = item.Inventory(player, constant.INENTORY_SIZE[0],
                                constant.INENTORY_SIZE[1], constant.WEIGHT_LIMIT)


    blah = "Makarov PM"
    test_makarov = item.Item(blah, item_types.firearms[blah][-1])
    test_makarov.gun_component = item.Gun(test_makarov, *item_types.firearms[blah][:-1])
    makarov_entity = entity.Entity(map_size[0] / 2 + 1, map_size[1] / 2 + 1, "]",
                                   tcod.dark_grey, item_component=test_makarov,
                                   is_walkable=True)

    entity_list = [player, makarov_entity]

    camera_x, camera_y = (player.x, player.y)

    fov_map = fov.update_fov_map(the_map, fov_map)
    tcod.map_compute_fov(fov_map, player.x, player.y, constant.VISION_RANGE, True, tcod.FOV_BASIC)
    fov_recompute = True

    in_menu = False
    selected_inv_square = None

    test = tcod.image_load(os.path.join("images", "weapons", "Makarov PM.png"))
    tcod.image_set_key_color(test, tcod.pink)

    # Set initial values for key and mouse event; required to pass into sys_check_for_event
    key = tcod.console_check_for_keypress(tcod.KEY_PRESSED)
    mouse_status = tcod.mouse_get_status()
    
    while True:
        # Get input
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse_status)

        if not in_menu:
            # Update camera. This must be done before rendering
            (center_x, center_y) = geometry.get_point_ahead(player.x, player.y, mouse_status.cx + camera_x,
                                                   mouse_status.cy + camera_y, constant.CAMERA_DISTANCE)
            (camera_x, camera_y) = geometry.update_camera(center_x, center_y, the_map.width, the_map.height)
            player_facing_point = (mouse_status.cx, mouse_status.cy)

        # Update FOV
        if fov_recompute:
            tcod.map_compute_fov(fov_map, player.x, player.y, constant.VISION_RANGE, True, tcod.FOV_BASIC)
        fov.update_entity_fov(entity_list, the_map, fov_map)

        # Render the map and entities
        the_map.render(console_buffer, fov_map, camera_x, camera_y, player.x, player.y, *player_facing_point)
        console_buffer.blit(0)
        
        # Only entities in the player's line of sight should be drawn
        for _entity in reversed(entity_list):
            if fov.in_player_fov(_entity.x, _entity.y, player.x, player.y, mouse_status.cx + camera_x,
                                 mouse_status.cy + camera_y, fov_map):
                _entity.render(0, camera_x, camera_y)

        # fps display
        tcod.console_print_ex(0, constant.SCREEN_WIDTH - 1, 0, tcod.BKGND_NONE, tcod.RIGHT, str(tcod.sys_get_fps()))
        

        # If in inventory, draw inventory grid
        if in_menu == "inventory":
            tcod.mouse_show_cursor(True)
            tcod.console_clear(ui_con)
            ui.draw_checkerboard(ui_con, constant.INENTORY_SIZE[0], constant.INENTORY_SIZE[1],
                                 constant.SQUARE_SIZE, tcod.grey, tcod.dark_grey)
            ui.draw_inventory_items(ui_con, player.inventory_component)
            if selected_inv_square is not None:
                tcod.console_print_frame(ui_con, selected_inv_square[0] * constant.SQUARE_SIZE,
                                                 selected_inv_square[1] * constant.SQUARE_SIZE,
                                                 constant.SQUARE_SIZE, constant.SQUARE_SIZE, False, tcod.BKGND_NONE, False)
            tcod.console_blit(ui_con, 0, 0, constant.INENTORY_SIZE[0] * constant.SQUARE_SIZE,
                              constant.INENTORY_SIZE[1] * constant.SQUARE_SIZE, 0, constant.INVENTORY_X, constant.INVENTORY_Y)

        tcod.console_flush()
        fov_recompute = False

        # Handle input
        if not in_menu:
            if key.vk == tcod.KEY_LEFT: # Move left
                if not entity.check_collision(player.x - 1, player.y, the_map, entity_list):
                    player.x -= 0 if player.x == 0 else 1
                    fov_recompute = True
            elif key.vk == tcod.KEY_RIGHT: # Move right
                if not entity.check_collision(player.x + 1, player.y, the_map, entity_list):
                    player.x += 0 if player.x == the_map.width else 1
                    fov_recompute = True
            elif key.vk == tcod.KEY_UP: # Move up
                if not entity.check_collision(player.x, player.y - 1, the_map, entity_list):
                    player.y -= 0 if player.y == 0 else 1
                    fov_recompute = True
            elif key.vk == tcod.KEY_DOWN: # Move down
                if not entity.check_collision(player.x, player.y + 1, the_map, entity_list):
                    player.y += 0 if player.y == the_map.height else 1
                    fov_recompute = True
            elif key.c == ord("i"):
                in_menu = "inventory"
            elif key.c == ord(","):
                for _entity in entity_list:
                    if (_entity.item_component is not None and
                            _entity.x == player.x and
                            _entity.y == player.y):
                        player.inventory_component.add(_entity.item_component)
                        entity_list.remove(_entity)
                        
                                                              
            elif key.vk == tcod.KEY_ESCAPE: # Quit back to main menu
                break
        elif in_menu == "inventory":
            if mouse_status.lbutton_pressed:
                prev_square = selected_inv_square
                selected_inv_square = ((mouse_status.cx - constant.INVENTORY_X) / constant.SQUARE_SIZE,
                                       (mouse_status.cy - constant.INVENTORY_Y) / constant.SQUARE_SIZE)
                if selected_inv_square == prev_square:
                    selected_inv_square = None
                elif not ((0 <= selected_inv_square[0] < constant.INENTORY_SIZE[0]) and
                          (0 <= selected_inv_square[1] < constant.INENTORY_SIZE[1])):
                    selected_inv_square = prev_square
            elif key.c == ord("i"):
                tcod.mouse_show_cursor(False)
                in_menu = ""
コード例 #7
0
def render_all():
    global fov_map
    global fov_recompute

    if fov_recompute:
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight

                if not visible:
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(
                                con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(
                                con, x, y, color_dark_ground,
                                libtcod.BKGND_SET)
                else:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, color_light_wall, libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, color_light_ground, libtcod.BKGND_SET)
                    #visible, so explore it:
                    map[x][y].explored = True

        #draw all objects in the list
        for object in objects:
            object.draw()

        #gui
        libtcod.console_set_default_background(panel, libtcod.black)
        libtcod.console_clear(panel)

        #print messages one at a time
        y = 1
        for (line, color) in game_msgs:
            libtcod.console_set_default_foreground(panel, color)
            libtcod.console_print_ex(panel, MSG_X, y, libtcod.BKGND_NONE,
                                     libtcod.LEFT, line)
            y += 1

        #coords under mouse gets called here
        libtcod.console_set_default_foreground(panel, libtcod.light_purple)
        libtcod.console_print_ex(panel, 1, 1, libtcod.BKGND_NONE, libtcod.LEFT,
                                 get_coords_under_mouse())

        #mouse stuff
        libtcod.mouse_show_cursor(False)

        display_cursor_tile()
        #display_cursor_trail()
        display_status()
        display_border('>', libtcod.red)

        #BLIT CONSOLE#
        libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)

        #BLIT PANEL#
        libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                             PANEL_Y)

        #BLIT OVERLAY#
        libtcod.console_blit(overlay, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0,
                             0.5, 0.1)
コード例 #8
0
def start_console():
    libtcod.console_init_root(WIDTH, HEIGHT, "FabSec", False,
                              libtcod.RENDERER_SDL)
    libtcod.sys_set_fps(60)


def read_command_file():
    """Debuggin' tool. Apply a series of commands."""
    with open('commands') as f:
        content = f.readlines()
    return content


if __name__ == "__main__":
    start_console()
    libtcod.mouse_show_cursor(True)
    facility = buildFacility()

    # TODO : read all that from a config file
    tree = MenuItem("Main menu", '', MenuItem.ITEM_VERB, Message.VIEW, "", [
        MenuItem("(D)ig", 'd', MenuItem.ITEM_VERB, Message.DIG,
                 "Select tiles to dig."),
        MenuItem("(B)uild", 'b', MenuItem.ITEM_VERB, Message.BUILD, "", [
            MenuItem("(E)levator", 'e', MenuItem.ITEM_COMPLEMENT, "ELEVATOR")
        ]),
        MenuItem("(R)ecruit", 'r', MenuItem.ITEM_VERB, Message.RECRUIT, "", [
            MenuItem("(W)orker", 'w', MenuItem.ITEM_COMPLEMENT,
                     EmployeeType.WORKER),
            MenuItem("(S)ecurity guard", 's', MenuItem.ITEM_COMPLEMENT,
                     EmployeeType.SECURITY),
            MenuItem("(R)esearcher", 'r', MenuItem.ITEM_COMPLEMENT,
コード例 #9
0
ファイル: stalker-rl.py プロジェクト: orodley/stalker-rl
MAIN_MENU_X = (constant.SCREEN_WIDTH / 2)  - (MAIN_MENU_WIDTH / 2) # Co-ordinates to draw main menu at
MAIN_MENU_Y = (constant.SCREEN_HEIGHT / 2) - (MAIN_MENU_HEIGHT / 2)

tcod.console_set_custom_font(os.path.join('fonts', 'terminal8x8_aa_ro.png'),
                             tcod.FONT_LAYOUT_ASCII_INROW)

tcod.console_init_root(constant.SCREEN_WIDTH, constant.SCREEN_HEIGHT, 'S.T.A.L.K.E.R RL', False)

# Console for any temporary UI elements (inventory, equipment, etc)
ui_con   = tcod.console_new(constant.SCREEN_WIDTH, constant.SCREEN_HEIGHT)
# Main console that the map and constant UI elements are rendered to
game_con = tcod.console_new(constant.SCREEN_WIDTH, constant.SCREEN_HEIGHT)

tcod.sys_set_fps(constant.FPS_CAP)
tcod.console_set_keyboard_repeat(10, 50)
tcod.mouse_show_cursor(False)

tcod.console_credits()

img = tcod.image_load(os.path.join('images', 'menu_background.png'))
tcod.image_blit_2x(img, game_con, 0, 0)
tcod.console_blit(game_con, 0, 0, 0, 0, 0, 0, 0)
tcod.console_flush()

main_menu_index = 0
while not tcod.console_is_window_closed():
    tcod.image_blit_2x(img, game_con, 0, 0)
    tcod.console_blit(game_con, 0, 0, 0, 0, 0, 0, 0)
    tcod.console_clear(ui_con)
    ui.draw_menu(ui_con, "S.T.A.L.K.E.R. RL", ['New Game', 'Load Game', 'Highscores', 'Exit'],
                 MAIN_MENU_WIDTH, MAIN_MENU_HEIGHT, main_menu_index)