Define an Object with a position and symbol; make the player an Object
This commit is contained in:
parent
f98243b047
commit
d069ca4981
2 changed files with 43 additions and 8 deletions
|
@ -6,17 +6,18 @@ New script.
|
|||
'''
|
||||
|
||||
import argparse
|
||||
from curses import KEY_DOWN
|
||||
import logging
|
||||
import math
|
||||
import os.path
|
||||
import tcod
|
||||
from .object import Object
|
||||
|
||||
CONSOLE_WIDTH, CONSOLE_HEIGHT = 50, 50
|
||||
FONT = 'terminal16x16_gs_ro.png'
|
||||
|
||||
LOG = logging.getLogger('roguebasin')
|
||||
|
||||
PLAYER = Object('@', x=CONSOLE_WIDTH / 2, y=CONSOLE_HEIGHT / 2)
|
||||
|
||||
def parse_args(argv, *a, **kw):
|
||||
parser = argparse.ArgumentParser(*a, **kw)
|
||||
# TODO: Configure arguments here.
|
||||
|
@ -65,10 +66,11 @@ def main(argv):
|
|||
console = tcod.Console(CONSOLE_WIDTH, CONSOLE_HEIGHT, order='F')
|
||||
|
||||
with tcod.context.new(columns=console.width, rows=console.height, tileset=tileset) as context:
|
||||
player_x, player_y = math.floor(CONSOLE_WIDTH / 2), math.floor(CONSOLE_HEIGHT / 2)
|
||||
while True:
|
||||
console.clear()
|
||||
console.print(x=player_x, y=player_y, string='@')
|
||||
|
||||
PLAYER.print(console)
|
||||
|
||||
context.present(console)
|
||||
|
||||
for event in tcod.event.wait():
|
||||
|
@ -81,13 +83,13 @@ def main(argv):
|
|||
elif isinstance(event, tcod.event.KeyDown):
|
||||
sym = event.sym
|
||||
if sym == tcod.event.KeySym.h:
|
||||
player_x = max([0, player_x - 1])
|
||||
PLAYER.x = max([0, PLAYER.x - 1])
|
||||
elif sym == tcod.event.KeySym.j:
|
||||
player_y = min([CONSOLE_HEIGHT - 1, player_y + 1])
|
||||
PLAYER.y = min([CONSOLE_HEIGHT - 1, PLAYER.y + 1])
|
||||
elif sym == tcod.event.KeySym.k:
|
||||
player_y = max([0, player_y - 1])
|
||||
PLAYER.y = max([0, PLAYER.y - 1])
|
||||
elif sym == tcod.event.KeySym.l:
|
||||
player_x = min([CONSOLE_WIDTH - 1, player_x + 1])
|
||||
PLAYER.x = min([CONSOLE_WIDTH - 1, PLAYER.x + 1])
|
||||
else:
|
||||
handled = False
|
||||
else:
|
||||
|
|
33
roguebasin/object.py
Normal file
33
roguebasin/object.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python3
|
||||
# Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
import tcod
|
||||
|
||||
class Object:
|
||||
'''
|
||||
A drawable object with a symbol and (x, y) position.
|
||||
'''
|
||||
|
||||
def __init__(self, symbol, x=0, y=0):
|
||||
self.__x = int(x)
|
||||
self.__y = int(y)
|
||||
self.symbol = symbol
|
||||
|
||||
@property
|
||||
def x(self):
|
||||
return self.__x
|
||||
|
||||
@x.setter
|
||||
def x(self, value):
|
||||
self.__x = int(value)
|
||||
|
||||
@property
|
||||
def y(self):
|
||||
return self.__y
|
||||
|
||||
@y.setter
|
||||
def y(self, value):
|
||||
self.__y = int(value)
|
||||
|
||||
def print(self, console: tcod.Console) -> None:
|
||||
console.print(x=self.__x, y=self.__y, string=self.symbol)
|
Loading…
Add table
Add a link
Reference in a new issue