Draw a PLAYER and NPC @; make the NPC yellow
This commit is contained in:
parent
638f2d8826
commit
4419eb360d
2 changed files with 11 additions and 5 deletions
|
@ -8,6 +8,7 @@ New script.
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
|
import random
|
||||||
import tcod
|
import tcod
|
||||||
from .object import Object
|
from .object import Object
|
||||||
|
|
||||||
|
@ -16,7 +17,8 @@ FONT = 'terminal16x16_gs_ro.png'
|
||||||
|
|
||||||
LOG = logging.getLogger('roguebasin')
|
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):
|
def parse_args(argv, *a, **kw):
|
||||||
parser = argparse.ArgumentParser(*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)
|
tileset = tcod.tileset.load_tilesheet(font, 16, 16, tcod.tileset.CHARMAP_CP437)
|
||||||
console = tcod.Console(CONSOLE_WIDTH, CONSOLE_HEIGHT, order='F')
|
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:
|
with tcod.context.new(columns=console.width, rows=console.height, tileset=tileset) as context:
|
||||||
while True:
|
while True:
|
||||||
console.clear()
|
console.clear()
|
||||||
|
|
||||||
PLAYER.print(console)
|
for obj in objects:
|
||||||
|
obj.print(console)
|
||||||
|
|
||||||
context.present(console)
|
context.present(console)
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,11 @@ class Object:
|
||||||
A drawable object with a symbol and (x, y) position.
|
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.__x = int(x)
|
||||||
self.__y = int(y)
|
self.__y = int(y)
|
||||||
self.symbol = symbol
|
self.__color = color
|
||||||
|
self.__symbol = symbol
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def x(self):
|
def x(self):
|
||||||
|
@ -30,4 +31,4 @@ class Object:
|
||||||
self.__y = int(value)
|
self.__y = int(value)
|
||||||
|
|
||||||
def print(self, console: tcod.Console) -> None:
|
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue