Ejemplo n.º 1
0
def play_game():
    player_action = None

    #main loop
    while True:
        render_all()
        check_level_up()

        #terminal.layer(5)
        #terminal.put(10, 10, 24) #place individual tile slime: 160:, troll=162: .
        terminal.refresh()

        for object in objects:
            object.clear()

        player_action = handle_keys()
        if player_action == 'exit':
            save_game()
            break

        #let monsters take their turn
        if game_state == 'playing' and player_action != 'didnt-take-turn':
            for object in objects:
                if object.ai:
                    object.ai.take_turn()
Ejemplo n.º 2
0
def main_menu():

    while True:
        terminal.clear()
        for y in range(50):
            for x in range(80):
                terminal.color(1678238975 - x)
                terminal.put(x, y, 20)

        terminal.refresh()

        #show the game's title and some credits
        terminal.layer(6)
        terminal.color(4294967103)
        terminal.print_(SCREEN_WIDTH/2 - 10, SCREEN_HEIGHT/2-4, 'CAVES OF THE SNAILMEN')
        terminal.print_(SCREEN_WIDTH/2, SCREEN_HEIGHT-2, 'By Tommy Z')

        #show options and wait for player's choice
        choice = menu('', ['Play a new game', 'Continue last game', 'Save & Quit'], 24)

        if choice == 0:  #new game
            terminal.clear()
            new_game()
            play_game()
        if choice == 1:  #load last game
            try:
                load_game()
            except:
                msgbox('\n No saved game to load.\n', 24)
                continue
            play_game()
        elif choice == 2:  #quit

            terminal.close()
            break
Ejemplo n.º 3
0
def main():
    global WINDOW_WIDTH, WINDOW_HEIGHT, CELLSIZE
    blt.open_()
    blt.set_("window: size={}x{}, cellsize={}, title='Grid Test';"
             "font: default".format(
                 str(WINDOW_WIDTH), str(WINDOW_HEIGHT), CELLSIZE))
    blt.clear()
    blt.refresh()
    blt.color("white")
    g = Quadrant()
    blt.clear()
    for x in range(30):
        for y in range(30):
            if [x, y] in g.all_nodes:
                blt.print_(x * 2, y * 2, 'O')
            elif [x, y] in g.roads:
                # if x != 0 and x != 10 and y != 0 and y != 10:
                    # blt.layer(1)
                # blt.print_(x * 2, y * 2, str(g.roads.index([x, y])))
                    # blt.layer(0)
                # else:
                blt.print_(x * 2, y * 2, '+')
    blt.refresh()

    proceed = True
    while proceed:
        key = 0
        while blt.has_input():
            key = blt.read()
            if key == blt.TK_CLOSE or key == blt.TK_Q:
                proceed = False
    blt.close()
Ejemplo n.º 4
0
 def initialize_blt(self):
     terminal.open()
     terminal.set(
         "window: size={}x{}, cellsize={}, title='Roguelike';"
         "font: default;"
         "input: filter=[keyboard+];"
         "".format(str(self.window_width), str(self.window_height), self.cellsize)
     )
     terminal.clear()
     terminal.refresh()
     terminal.color("white")
Ejemplo n.º 5
0
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')
    #calculate total height for the header (after auto-wrap) and one line per option
    #header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)!!!

    header_height = len(textwrap.wrap(header, width))
    height = len(options) + header_height
    #set co-ords of menu
    menu_x = SCREEN_WIDTH/2 - width/2
    menu_y = SCREEN_HEIGHT/2 - height/2

    #paint menu background
    terminal.layer(5)
    terminal.color(MENU_BACKGROUND_COLOR) #menu
    for y_bg in range(height):
        for x_bg in range(width):
            terminal.put(menu_x + x_bg, menu_y + y_bg, 20)


    #print the header, with auto-wrap
    terminal.layer(6)
    terminal.color('#FFFFFF')
    y = 0
    for line in textwrap.wrap(header, width):
        terminal.print_(menu_x, menu_y + y, line)
        y += 1

    #position of options, below header (y)
    y = menu_y + header_height
    letter_index = ord('a')

    #print all the options
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        #libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        terminal.print_(menu_x, y, text)
        y += 1
        letter_index += 1
    #present the root console to the player and wait for a key-press

    terminal.refresh()
    key = terminal.read() #temporary halt of operation, wait for keypress/click

    #clear the menu from screen
    terminal.layer(5)
    terminal.clear_area(menu_x, menu_y, width, height)

    if terminal.state(terminal.TK_CHAR): #!! maybe no if statement here?
        #convert the ASCII code to an index; if it corresponds to an option, return it
        index = terminal.state(terminal.TK_CHAR) - ord('a')
        if index >= 0 and index < len(options): return index
        return None
Ejemplo n.º 6
0
def target_tile(max_range=None):
    #return the position of a tile left-clicked in player's FOV (optionally in a range), or (None,None) if right-clicked.
    global key, mouse
    while True:
        #render the screen. this erases the inventory and shows the names of objects under the mouse.
        render_all()
        terminal.refresh()
        key = terminal.read() #temporary halt of operation, wait for keypress/click

        #render_all()
        (x, y) = (terminal.state(terminal.TK_MOUSE_X), terminal.state(terminal.TK_MOUSE_Y))

        #if mouse.rbutton_pressed or key.vk == libtcod.KEY_ESCAPE:
        if key == terminal.TK_ESCAPE or key == terminal.TK_MOUSE_RIGHT:
            return (None, None)  #cancel if the player right-clicked or pressed Escape

        #accept the target if the player clicked in FOV, and in case a range is specified, if it's in that range
        #if (mouse.lbutton_pressed and libtcod.map_is_in_fov(fov_map, x, y) and
        if (key == terminal.TK_MOUSE_LEFT and libtcod.map_is_in_fov(fov_map, x, y) and
            (max_range is None or player.distance(x, y) <= max_range)):
            return (x, y)
Ejemplo n.º 7
0
 def render(self):
     terminal.clear()
     self.render_viewport()
     self.render_UI()
     self.render_message_bar()
     terminal.refresh()
Ejemplo n.º 8
0
class AtMan(MapChild):
    def __init__(self, x, y, parent_map):
        MapChild.__init__(self, x, y, '@', parent_map)
        eventhandler.register(self, *ARROW_EVENTS)

    def receive_event(self, event):
        if event == bl.TK_RIGHT: new_pos = (self.x + 1, self.y)
        elif event == bl.TK_LEFT: new_pos = (self.x - 1, self.y)
        elif event == bl.TK_UP: new_pos = (self.x, self.y - 1)
        elif event == bl.TK_DOWN: new_pos = (self.x, self.y + 1)
        self.parent_map.move(self, new_pos)


bl.open()
bl.refresh()
SCREEN_WIDTH = bl.state(bl.TK_WIDTH)
SCREEN_HEIGHT = bl.state(bl.TK_HEIGHT)

the_map = Map(SCREEN_WIDTH, SCREEN_HEIGHT, 3, 3, 9, 9)
at = AtMan(5, 5, the_map)
left_apostrophe = MapChild(0, 1, "'", the_map)
right_apostrophe = MapChild(2, 1, "'", the_map)
dud = MapChild(4, 4, "\u2193", the_map)
the_map.draw_view()
eventhandler.register(the_map, *ARROW_EVENTS + WASD_EVENTS)

menu = ui.Menu(60, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1)

paint(gridtools.hollow_rectangle(2, 2, 10, 10))
paint(gridtools.rectangle(60, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1))
Ejemplo n.º 9
0
def draw(drawables):
    for obj in drawables:
        bl.put(obj.screen_x, obj.screen_y, obj.char)
    bl.refresh()
Ejemplo n.º 10
0
import PyBearLibTerminal as terminal

terminal.open()
terminal.printf(2, 1, "β")
terminal.put(2, 2, "β")
terminal.refresh()
while True:
    if terminal.has_input():
        key = terminal.read()
        print(key)
        if key == terminal.TK_Q | terminal.TK_KEY_RELEASED:
            print("released")
            break
        elif key == terminal.TK_Q:
            break
terminal.close()
Ejemplo n.º 11
0
    terminal.printf(l1[0] - 1, l1[1], '>')

    color10 = bltColor('sky')
    line.draw_line((l1[0], l1[1]), (l2[0], l2[1]), color10)

    terminal.color(bltColor('255, 255,64,64'))
    terminal.print_(15, 8, "[wrap=25x5][align=left-bottom]Hello my name is rudy!!!!!!!! I want to be your friend")



    terminal.color('yellow')
    terminal.printf(l2[0] + 1, l2[1], '<')



    terminal.refresh()

    if terminal.has_input():
        key = terminal.read()
    if key == terminal.TK_CLOSE:
        break
    elif key == terminal.TK_UP:
        l2 = (l2[0], l2[1] - 1)
    elif key == terminal.TK_DOWN:
        l2 = (l2[0], l2[1] + 1)
    elif key == terminal.TK_LEFT:
        l2 = (l2[0] - 1, l2[1])
    elif key == terminal.TK_RIGHT:
        l2 = (l2[0] + 1, l2[1])