diff --git a/roguebasin/main.py b/roguebasin/main.py index 1331586..d9c85e3 100644 --- a/roguebasin/main.py +++ b/roguebasin/main.py @@ -8,6 +8,7 @@ New script. import argparse import logging import os.path +import random import tcod from .object import Object @@ -16,7 +17,8 @@ FONT = 'terminal16x16_gs_ro.png' LOG = logging.getLogger('roguebasin') -PLAYER = Object('@', x=CONSOLE_WIDTH / 2, y=CONSOLE_HEIGHT / 2) +PLAYER = Object('@', x=CONSOLE_WIDTH // 2, y=CONSOLE_HEIGHT // 2) +NPC = Object('@', color=tcod.yellow, x=random.randint(0, CONSOLE_WIDTH), y=random.randint(0, CONSOLE_HEIGHT)) def parse_args(argv, *a, **kw): parser = argparse.ArgumentParser(*a, **kw) @@ -65,11 +67,14 @@ def main(argv): tileset = tcod.tileset.load_tilesheet(font, 16, 16, tcod.tileset.CHARMAP_CP437) console = tcod.Console(CONSOLE_WIDTH, CONSOLE_HEIGHT, order='F') + objects = [PLAYER, NPC] + with tcod.context.new(columns=console.width, rows=console.height, tileset=tileset) as context: while True: console.clear() - PLAYER.print(console) + for obj in objects: + obj.print(console) context.present(console) diff --git a/roguebasin/object.py b/roguebasin/object.py index 2caecb8..120cd20 100644 --- a/roguebasin/object.py +++ b/roguebasin/object.py @@ -8,10 +8,11 @@ class Object: A drawable object with a symbol and (x, y) position. ''' - def __init__(self, symbol, x=0, y=0): + def __init__(self, symbol, color=(255, 255, 255), x=0, y=0): self.__x = int(x) self.__y = int(y) - self.symbol = symbol + self.__color = color + self.__symbol = symbol @property def x(self): @@ -30,4 +31,4 @@ class Object: self.__y = int(value) def print(self, console: tcod.Console) -> None: - console.print(x=self.__x, y=self.__y, string=self.symbol) + console.print(x=self.__x, y=self.__y, string=self.__symbol, fg=self.__color)