Example #1
0
def main():
    # Opens and initializes terminal settings, then starts game.

    # Load config and adjust settings for the game based off of the config data.
    with open("config.json", "r") as read_file:
        config = json.load(read_file)

    config['tile_spacing_x'] = int(config['tile_font_width'] /
                                   config['cellsize_x'])
    config['tile_spacing_y'] = int(config['tile_font_height'] /
                                   config['cellsize_y'])
    config['window_width'] = config['camera_width'] * config['tile_spacing_x']
    config[
        'window_height'] = config['camera_height'] * config['tile_spacing_y']

    # Open terminal/config terminal.
    terminal.open()
    terminal.set("window: title='Etheria', size=%sx%s, cellsize=%sx%s" %
                 (config['window_width'], config['window_height'],
                  config['cellsize_x'], config['cellsize_y']))
    terminal.set("input.filter = [keyboard, mouse]")
    terminal.set(
        "text font: 'fonts/PxPlus_IBM_CGAthin.ttf', size=8x16, spacing=2x1")
    terminal.set(
        "bar font: 'fonts/PxPlus_IBM_CGAthin.ttf', size=4x4, spacing=1x6")
    terminal.set(
        "minimap font: 'fonts/PxPlus_IBM_CGAthin.ttf', size=4x4, spacing=1x2")
    terminal.set("main font: 'fonts/VeraMono.ttf', size=20x20, spacing=5x5")
    terminal.font('main')
    terminal.composition(True)

    # Start the game, close the terminal after game is exited.
    start_game(config)
    terminal.close()
Example #2
0
    def animate(self, current_map, animations, camera, config, animation_data):
        # Scale color based on ticks left.
        terminal.font("main")
        color = animation_data['attack']['color_fg']['attacked'][:]
        color[0] += (self.ticks*5)

        # Put an indicator around attacker.
        terminal.color(terminal.color_from_argb(*animation_data['attack']['color_fg']['attacker']))
        dx, dy = camera.to_camera_coords(self.actor.x, self.actor.y)
        terminal.put(dx*config['tile_spacing_x'], dy*config['tile_spacing_y'],
                     animation_data['attack']['image']['attacker'])

        # Put an indicator around attacked target, fades based on amount of ticks left.
        terminal.color(terminal.color_from_argb(*color))
        dx, dy = camera.to_camera_coords(self.target.x, self.target.y)
        terminal.put(dx*config['tile_spacing_x'], dy*config['tile_spacing_y'], 
                     animation_data['attack']['image']['attacked'])

        # Make sure background stays the default color.
        terminal.bkcolor(terminal.color_from_argb(0, 0, 0, 0))

        # Remove animation once its maximum ticks are reached.
        if self.ticks <= 0:
            animations.remove(self)

        self.ticks -= 1
Example #3
0
    def draw(self):
        terminal.font('text')
        if not self.selected:
            terminal.color(terminal.color_from_argb(*self.color))
        else:
            terminal.color(terminal.color_from_argb(*self.selected_color))

        terminal.printf(self.x1, self.y1, self.text, terminal.TK_ALIGN_DEFAULT)
Example #4
0
def render_map(player, current_map, fov, camera, under_mouse, config,
               game_state):
    # Renders everything in the map(tiles, objects, items)
    # that is within view of the camera and in the current FOV.
    terminal.font('main')
    for x in range(camera.width):
        for y in range(camera.height):
            dx, dy = x + camera.x, y + camera.y
            tile = current_map.tiles[dx][dy]
            if tile != under_mouse and game_state != GameState.targeting:
                tile.highlight = None
            if tile in fov.fov_map:
                tile.draw(
                    *camera.to_camera_coords(dx, dy),
                    dim_argb(tile.color_fg,
                             player.distance_to(tile) * 40),
                    dim_argb(tile.color_bg,
                             player.distance_to(tile) * 40),
                    config['tile_spacing_x'], config['tile_spacing_y'])
                tile.explored = True

                # Draw all items if on top of tiles that are within FOV.
                for item in current_map.items:
                    if item.x == tile.x and item.y == tile.y:
                        if item != under_mouse:
                            item.highlight = None
                        item.draw(*camera.to_camera_coords(dx, dy),
                                  tile.color_bg, config['tile_spacing_x'],
                                  config['tile_spacing_y'])

                # Draw all actors if on top of tiles that are within FOV.
                for actor in current_map.actors:
                    if actor.x == tile.x and actor.y == tile.y:
                        if actor != under_mouse:
                            actor.highlight = None
                        actor.draw(*camera.to_camera_coords(dx, dy),
                                   tile.color_bg, config['tile_spacing_x'],
                                   config['tile_spacing_y'])

            elif tile.explored:
                tile.draw(*camera.to_camera_coords(dx, dy),
                          dim_argb(tile.color_fg, 200),
                          dim_argb(tile.color_bg, 200),
                          config['tile_spacing_x'], config['tile_spacing_y'])

    # Draw player at camera coords.
    dx, dy = camera.to_camera_coords(player.x, player.y)
    if player != under_mouse:
        player.highlight = None
    player.draw(dx, dy, current_map.tiles[player.x][player.y].color_bg,
                config['tile_spacing_x'], config['tile_spacing_y'])

    # Keep general background one color.
    terminal.bkcolor(terminal.color_from_argb(0, 0, 0, 0))
Example #5
0
def render_minimap(player, start_x, start_y, current_map):

    terminal.font('minimap')
    for x in range(current_map.width):
        for y in range(current_map.height):
            if current_map.tiles[x][y]:
                terminal.color(
                    terminal.color_from_argb(
                        *current_map.tiles[x][y].color_bg))
                terminal.put(start_x + x, start_y + y, '▄')

    terminal.color(terminal.color_from_argb(*player.color_fg))
    terminal.put(start_x + player.x, start_y + player.y, '▄')
    terminal.font('main')
Example #6
0
def create_window(x, y, width, height, text):
    terminal.font('bar')
    terminal.layer(1)

    # Draw window.
    terminal.color(terminal.color_from_argb(255, 50, 50, 50))
    for dx in range(width):
        for dy in range(height):
            terminal.put(x + dx, y + dy, '▄')

    # Draw window title in center of the window.
    terminal.font('text')
    terminal.color(terminal.color_from_argb(255, 255, 255, 255))
    center_x = int(x + (width / 2 - len(text)))
    terminal.printf(center_x, y + 4, text)
    def animate(self, current_map, animations, camera, config, animation_data):
        # Scale text color based on ticks left.
        terminal.font("text")
        color = self.color[:]
        color[0] += (self.ticks*3)

        # Display text at given coords.
        terminal.color(terminal.color_from_argb(*color))
        dx, dy = camera.to_camera_coords(self.x, self.y)
        terminal.printf(dx*config['tile_spacing_x'], dy*config['tile_spacing_x'], str(self.text))

        # Remove animation once its maximum ticks are reached.
        if self.ticks <= 0:
            animations.remove(self)

        self.ticks -= 1

        # Shift the text slowly upward
        if self.ticks % 15 == 0:
            self.y -= 1
Example #8
0
def render_bar(x, y, width, name, value, max_value, color_fg, color_bg,
               color_text):
    # Calculate current bar width.
    bar_width = int(float(value) / max_value * width)

    # Make sure there is always some bar showing even if value is super low.
    if bar_width < 1 and bar_width > 0:
        bar_width = 1

    # Draw background of the bar to the width given.
    terminal.color(terminal.color_from_argb(*color_bg))
    terminal.font('bar')
    for i in range(width):
        terminal.put(x + i, y, '▄')

    # Draw the foreground to the width calculated earlier.
    terminal.color(terminal.color_from_argb(*color_fg))
    for i in range(bar_width):
        terminal.put(x + i, y, '▄')

    # Draw text in the center of the bar.
    terminal.font('text')
    terminal.color(terminal.color_from_argb(*color_text))
    bar_text = name + ': %s/%s' % (value, max_value)
    center_x = int(x + (width / 2 - len(bar_text)))
    terminal.printf(center_x, y + 4, bar_text)

    # Reset font back to normal.
    terminal.font('main')
Example #9
0
    def animate(self, current_map, animations, camera, config, animation_data):
        terminal.font("main")
        if not self.lingering:
            # Scale color based on ticks left.
            color = animation_data['soulrip']['color_bg'][:]
            color[0] = (50 + (self.ticks * 5))
            terminal.bkcolor(terminal.color_from_argb(*color))

            # Put color in aoe of the caster.
            for x in range(camera.width):
                for y in range(camera.height):
                    dx, dy = x + camera.x, y + camera.y
                    tile = current_map.tiles[dx][dy]
                    if self.actor.distance_to(tile) <= self.aoe:
                        if not tile.blocksLOS:
                            dx, dy = camera.to_camera_coords(tile.x, tile.y)
                            terminal.put(dx * config['tile_spacing_x'],
                                         dy * config['tile_spacing_y'], ' ')

        terminal.bkcolor(
            terminal.color_from_argb(*animation_data['soulrip']['color_bg']))
        dx, dy = camera.to_camera_coords(self.target.x, self.target.y)
        terminal.put(dx * config['tile_spacing_x'],
                     dy * config['tile_spacing_y'], ' ')

        # Make sure background stays the default color.
        terminal.bkcolor(terminal.color_from_argb(0, 0, 0, 0))

        # Remove animation once its maximum ticks are reached.
        if self.ticks <= 0:
            if not self.lingering:
                self.ticks += 20
                self.lingering = True
            else:
                animations.remove(self)

        self.ticks -= 1
Example #10
0
 def reset_font(self):
     if not self.options.graphical_tiles:
         return
     terminal.font("")
Example #11
0
 def set_sprite_font(self):
     if not self.options.graphical_tiles:
         return
     terminal.font("tile")