Ejemplo n.º 1
0
def new_game():
    # Initialize console & area
    lt.console_set_custom_font(FONT, lt.FONT_TYPE_GRAYSCALE | lt.FONT_LAYOUT_TCOD)
    lt.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'Armament', False)

    lt.sys_set_fps(LIMIT_FPS)

    global messages, log
    messages = list()
    log = lt.console_new(LOG_WIDTH, LOG_HEIGHT)
    message(' ')  # Ensures log is rendered.

    global panel
    panel = lt.console_new(PANEL_WIDTH, SCREEN_HEIGHT)
    lt.console_set_default_background(panel, lt.darkest_blue)
    lt.console_rect(panel, 0, 0, PANEL_WIDTH, SCREEN_HEIGHT, True, lt.BKGND_SET)
    lt.console_print_frame(panel, 1, 1, PANEL_WIDTH-2, SCREEN_HEIGHT-2, False)
    lt.console_blit(panel, 0, 0, PANEL_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

    while not lt.console_is_window_closed():
        global area
        area = Map(MAP_WIDTH, MAP_HEIGHT)
        # I'd rather not global this, but I can't figure out a way to make collision detection play nicely without it.

        # Create player entity
        player = Player()
        area.update_fov(player.being.col, player.being.row, player.being.facing)

        entities = list()
        entities.append(player)

        # Enter game
        if main(area, entities) == "exit":
            return True
Ejemplo n.º 2
0
def render(area, entities):
    area.draw()
    for entity in entities:
        entity.draw(area.con)

    lt.console_blit(area.con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, PANEL_WIDTH, 0)

    lt.console_flush()
Ejemplo n.º 3
0
    def swing(self, being):
        # Flash affected tiles.
        lt.console_set_default_background(area.con, lt.white)
        if being.facing == "N":
            lt.console_rect(area.con, being.col-1, being.row-1, 3, 1, True, lt.BKGND_SET)
        elif being.facing == "S":
            lt.console_rect(area.con, being.col-1, being.row+1, 3, 1, True, lt.BKGND_SET)
        elif being.facing == "W":
            lt.console_rect(area.con, being.col-1, being.row-1, 1, 3, True, lt.BKGND_SET)
        elif being.facing == "E":
            lt.console_rect(area.con, being.col+1, being.row-1, 1, 3, True, lt.BKGND_SET)
        lt.console_blit(area.con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, PANEL_WIDTH, 0)
        lt.console_flush()

        # Update held.
        self.held = "R" if self.held == "L" else "L"
Ejemplo n.º 4
0
    def draw(self):
        '''Draws the map to the offscreen console.'''

        global color_dark_wall, color_dark_ground
        global color_light_wall, color_light_ground

        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                wall = self.map[x][y].block_sight
                if wall:
                    libtcod.console_set_back(self.con, x, y,
                            color_dark_wall, libtcod.BKGND_SET)
                else:
                    libtcod.console_set_back(self.con, x, y,
                            color_dark_ground, libtcod.BKGND_SET)

        libtcod.console_blit(self.con, 0, 0, SCREEN_WIDTH,
                SCREEN_HEIGHT, 0, 0, 0)
Ejemplo n.º 5
0
def message(new_msg, color=lt.white):
    new_msg_lines = textwrap.wrap(str(new_msg), LOG_WIDTH - 4)

    for line in new_msg_lines:
        if len(messages) == LOG_HEIGHT - 4:
            del messages[0]
        messages.append((line, color))

    # Render message log.
    lt.console_clear(log)
    # A simple frame
    lt.console_set_default_foreground(log, lt.lighter_grey)
    lt.console_set_default_background(log, lt.darkest_blue)
    lt.console_rect(log, 0, 0, LOG_WIDTH, LOG_HEIGHT, True, lt.BKGND_SET)
    lt.console_print_frame(log, 0, 1, LOG_WIDTH, LOG_HEIGHT-2, False)
    # The messages
    col = 2
    for (line, color) in messages:
        lt.console_set_default_foreground(log, color)
        lt.console_print_ex(log, 2, col, lt.BKGND_NONE, lt.LEFT, line)
        col += 1

    lt.console_blit(log, 0, 0, LOG_WIDTH, LOG_HEIGHT, 0, PANEL_WIDTH, MAP_HEIGHT)
    lt.console_flush()
Ejemplo n.º 6
0
    def render_all(self):
        '''Renders all objects and tiles to the root console.'''

        global color_light_wall, color_dark_wall
        global color_light_ground, color_dark_ground

        if self.map.fov_recompute:
            self.map.fov_recompute = False
            libtcod.map_compute_fov(self.map.fov_map, self.map.player.x,
                    self.map.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(self.map.fov_map, x, y)
                    wall = self.map.map[x][y].block_sight
                    if not visible:
                        # Not visible, darken the tiles
                        if self.map.map[x][y].explored:
                            if wall:
                                libtcod.console_set_back(self.con, x, y,
                                        color_dark_wall, libtcod.BKGND_SET)
                            else:
                                libtcod.console_set_back(self.con, x, y,
                                        color_dark_ground, libtcod.BKGND_SET)
                    else:
                        # It's visible, light up the tiles
                        if wall:
                            libtcod.console_set_back(self.con, x, y,
                                    color_light_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_back(self.con, x, y,
                                    color_light_ground, libtcod.BKGND_SET)
                        self.map.map[x][y].explored = True

        # Draw all objects to the screen
        for object in self.map.object_list:
            if object != self.map.player:
                object.draw()
        self.map.player.draw()

        # Blit the offscreen console to the root console and flush
        libtcod.console_blit(self.con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

        # Display Player Stats
        libtcod.console_set_background_color(self.panel, libtcod.black)
        libtcod.console_clear(self.panel)

        # Print the message log
        y = 1
        for (line, color) in game_msgs:
            libtcod.console_set_foreground_color(self.panel, color)
            libtcod.console_print_left(self.panel, MSG_X, y,
                    libtcod.BKGND_NONE, line)
            y += 1

        self.render_bar(1, 1, BAR_WIDTH, 'HP', self.map.player.fighter.hp,
                self.map.player.fighter.max_hp, libtcod.red,
                libtcod.darker_red)

        self.render_bar(1, 3, BAR_WIDTH, 'EXP', self.map.player.fighter.exp,
                self.map.player.fighter.max_exp, libtcod.dark_yellow,
                libtcod.darker_yellow)

        self.render_bar(1, 5, BAR_WIDTH, 'Level',
                self.map.player.fighter.level, 10,
                libtcod.blue, libtcod.dark_blue)

        # Check under mouse
        libtcod.console_set_foreground_color(self.panel, libtcod.light_grey)
        libtcod.console_print_left(self.panel, 1, 0, libtcod.BKGND_NONE,
                self.under_mouse())

        libtcod.console_blit(self.panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                PANEL_Y)