def __init__(self):
     self.main_console_w = 100
     self.main_console_h = 60
     font_path = os.path.normpath(
         os.path.join(os.path.realpath(__file__), "..", "..",
                      "terminal8x8_gs_ro.png"))
     tdl.setFont(font_path)
     self.main_console = tdl.init(self.main_console_w, self.main_console_h,
                                  'Roguelike Game')
    def __init__(self):
        self.main_console_w = 80
        self.main_console_h = 60

        tdl.setFont('terminal8x8_gs_ro.png')  # Configure the font.

        # Create the root console.
        self.main_console = tdl.init(self.main_console_w, self.main_console_h,
                                     'Roguelike Game')

        CONSOLES['action_log'] = self.create_new_console(40, 15)
        CONSOLES['status'] = self.create_new_console(40, 15)
Example #3
0
    def init(self,
             width,
             height,
             font='assets/arial_16x16.png',
             name='Renderer'):
        System.init(self)
        self.width = width
        self.height = height

        # Set rendered font
        tdl.setFont(font)

        # Create console window
        self.window = tdl.init(self.width, self.height, name)
 def setUp(self):
     tdl.setFont('../fonts/libtcod/terminal8x8_gs_ro.png')
     tdl.event.get()
     self.console.set_colors((0,0,0), (0,0,0))
     self.console.clear()
 def setUpClass(cls):
     tdl.setFont('../fonts/libtcod/terminal8x8_gs_ro.png')
     cls.console = tdl.init(WIDTH, HEIGHT, 'TDL UnitTest', False, renderer='SDL')
     # make a small window in the corner
     cls.window = tdl.Window(cls.console, 0, 0, WINWIDTH, WINHEIGHT)
Example #6
0
                 # may be missing a keypad entirely.
                 # 7 8 9
                 # 4   6
                 # 1 2 3
                 'KP1': [-1, 1],
                 'KP2': [0, 1],
                 'KP3': [1, 1],
                 'KP4': [-1, 0],
                 'KP6': [1, 0],
                 'KP7': [-1, -1],
                 'KP8': [0, -1],
                 'KP9': [1, -1],
                 }


tdl.setFont('terminal8x8_gs_ro.png') # Configure the font.

# Create the root console.
console = tdl.init(WIDTH, HEIGHT, 'python-tdl tutorial')

# player coordinates
playerX, playerY = 1, 2

while True: # Continue in an infinite game loop.
    
    console.clear() # Blank the console.
    
    # Using "(x, y) in console" we can quickly check if a position is inside of
    # a console.  And skip a draw operation that would otherwise fail.
    if (playerX, playerY) in console:
        console.drawChar(playerX, playerY, '@')
Example #7
0
            for y in range(height):
                val = self.noise.getPoint((x + self.x) / width * self.zoom,
                                          (y + self.y) / height * self.zoom,
                                          self.z)
                bgcolor = (int(val * 255), ) * 2 + (min(
                    255, int(val * 2 * 255)), )
                samplewin.drawChar(x, y, ' ', (255, 255, 255), bgcolor)


WIDTH, HEIGHT = 80, 40
SAMPLE_WINDOW_RECT = (20, 10, 46, 20)

FONT = '../fonts/X11/8x13.png'

if __name__ == '__main__':
    tdl.setFont(FONT)
    console = tdl.init(WIDTH, HEIGHT, renderer='opengl')
    samplewin = tdl.Window(console, *SAMPLE_WINDOW_RECT)

    samples = [cls() for cls in [TrueColorSample, NoiseSample]]

    while 1:
        console.clear()
        samples[sampleIndex].runOnce()
        for i, sample in enumerate(samples):
            bgcolor = (0, 0, 0)
            if sampleIndex == i:
                bgcolor = (0, 0, 192)
            console.drawStr(0, -5 + i, '%s' % sample.name, (255, 255, 255),
                            bgcolor)
        console.drawStr(0, -1, '%i FPS' % tdl.getFPS())
Example #8
0
import socket
import tdl
import threading
import json

UDP_IP = "127.0.0.1"
UDP_PORT = 5005

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Set rendered font
tdl.setFont('assets/arial_16x16.png')

# Create console window
window = tdl.init(50, 30, "Network Client")


def listener():
    global window
    recvSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    recvSock.bind(("127.0.0.1", 5006))
    recvSock.setblocking(0)
    while (1):
        dataIn = None
        try:
            dataIn = recvSock.recv(10000).decode('utf-8')
        except:
            pass

        if dataIn != None:
            window.clear()
            data = json.loads(dataIn)
Example #9
0
    then check for an event that tells that the user has closed the window.

    When the window is closed the script quits out by raising a SystemExit
    exception.
"""

import tdl

# Define the window size (in character tiles.) We'll pick something small.
WIDTH, HEIGHT = 40, 30  # 320x240 when the font size is taken into account

# Set the font to the example font in the tutorial folder.  This font is
# equivalent to the default font you will get if you skip this call.
# With the characters rows first and the font size included in the filename
# you won't have to specify any parameters other than the font file itself.
tdl.setFont('terminal8x8_gs_ro.png')

# Call tdl.init to create the root console.
# We will call drawing operations on the returned object.
console = tdl.init(WIDTH, HEIGHT, 'python-tdl tutorial')

# Start an infinite loop.  Drawing and game logic will be put in this loop.
while True:

    # Reset the console to a blank slate before drawing on it.
    console.clear()

    # Now draw out 'Hello World' starting at an x,y of 1,2.
    console.draw_str(1, 2, 'Hello World')

    # Now to update the image on the window we make sure to call tdl.flush
Example #10
0
    then check for an event that tells that the user has closed the window.
    
    When the window is closed the script quits out by raising a SystemExit
    exception.
"""

import tdl

# Define the window size (in character tiles.) We'll pick something small.
WIDTH, HEIGHT = 40, 30 # 320x240 when the font size is taken into account

# Set the font to the example font in the tutorial folder.  This font is
# equivalent to the default font you will get if you skip this call.
# With the characters rows first and the font size included in the filename
# you won't have to specify any parameters other than the font file itself.
tdl.setFont('terminal8x8_gs_ro.png')

# Call tdl.init to create the root console.
# We will call drawing operations on the returned object.
console = tdl.init(WIDTH, HEIGHT, 'python-tdl tutorial')

# Start an infinite loop.  Drawing and game logic will be put in this loop.
while True:
    
    # Reset the console to a blank slate before drawing on it.
    console.clear()
    
    # Now draw out 'Hello World' starting at an x,y of 1,2.
    console.drawStr(1, 2, 'Hello World')
    
    # Now to update the image on the window we make sure to call tdl.flush
Example #11
0
#!/usr/bin/env python3
import tdl

from player import Player

WIDTH, HEIGHT = 50, 40

tdl.setFont('terminal8x8.png')
console = tdl.init(WIDTH, HEIGHT, 'Python RL')

p = Player()
p.position = WIDTH // 2, HEIGHT // 2

map = [
    [
        '#',
        '#',
        '#',
        '#',
    ],
    [
        '#',
        ' ',
        ' ',
        '#',
    ],
    [
        '#',
        ' ',
        ' ',
        '#',
Example #12
0
    # is on or off.  Keep in mind that some keyboards and laptops
    # may be missing a keypad entirely.
    # 7 8 9
    # 4   6
    # 1 2 3
    'KP1': [-1, 1],
    'KP2': [0, 1],
    'KP3': [1, 1],
    'KP4': [-1, 0],
    'KP6': [1, 0],
    'KP7': [-1, -1],
    'KP8': [0, -1],
    'KP9': [1, -1],
}

tdl.setFont('terminal8x8_gs_ro.png')  # Configure the font.

# Create the root console.
console = tdl.init(WIDTH, HEIGHT, 'python-tdl tutorial')

# player coordinates
playerX, playerY = 1, 2

while True:  # Continue in an infinite game loop.

    console.clear()  # Blank the console.

    # Using "(x, y) in console" we can quickly check if a position is inside of
    # a console.  And skip a draw operation that would otherwise fail.
    if (playerX, playerY) in console:
        console.draw_char(playerX, playerY, '@')
Example #13
0
import tdl
import random
from PIL import Image

FONTSIZE = 8
tdl.setFont('consolas8x8.png', 32, None, True, True,
            True)  # Configure the font.


# blits image to ASCII recreation of same size
def blit(fname):
    #image open
    try:
        img = Image.open(fname)
    except:
        input('ERROR: File not found.')
        return
    #image resize
    size = (W, H) = img.size
    w_blit = W // FONTSIZE
    h_blit = H // FONTSIZE
    size_blit = (w_blit, h_blit)
    img.thumbnail(size_blit, Image.ANTIALIAS)

    pix = img.load()
    #tdl renderer start
    console = tdl.init(
        w_blit, h_blit,
        'ASCII BLITTER                               Press ANY key to save to file.'
    )
    console.clear()
Example #14
0
        width, height = samplewin.getSize()
        for x in range(width):
            for y in range(height):
                val = self.noise.getPoint((x + self.x) / width * self.zoom,
                                          (y + self.y) / height * self.zoom,
                                          self.z)
                bgcolor = (int(val * 255),) * 2 + (min(255, int(val * 2 * 255)),)
                samplewin.drawChar(x, y, ' ', (255, 255, 255), bgcolor)

WIDTH, HEIGHT = 80, 40
SAMPLE_WINDOW_RECT = (20, 10, 46, 20)
    
FONT = '../fonts/X11/8x13.png'
    
if __name__ == '__main__':
    tdl.setFont(FONT)
    console = tdl.init(WIDTH, HEIGHT, renderer='opengl')
    samplewin = tdl.Window(console, *SAMPLE_WINDOW_RECT)
    
    samples = [cls() for cls in [TrueColorSample, NoiseSample]]
    sampleIndex = 0
    
    while 1:
        console.clear()
        samples[sampleIndex].runOnce()
        for i, sample in enumerate(samples):
            bgcolor = (0, 0, 0)
            if sampleIndex == i:
                bgcolor = (0, 0, 192)
            console.drawStr(0, -5 + i, '%s' % sample.name, (255, 255, 255), bgcolor)
        console.drawStr(0, -1, '%i FPS' % tdl.getFPS())