Part 2 in progress.
This commit is contained in:
84
engine.py
84
engine.py
@@ -1,66 +1,34 @@
|
||||
import tcod
|
||||
from entity import Entity
|
||||
from render_functions import *
|
||||
from game_map import *
|
||||
from input_handlers import EventHandler
|
||||
from typing import Set, Iterable, Any
|
||||
|
||||
from tcod.context import Context
|
||||
from tcod.console import Console
|
||||
|
||||
from actions import EscapeAction, MovementAction
|
||||
from entity import Entity
|
||||
from input_handlers import EventHandler
|
||||
|
||||
class Engine:
|
||||
def __init__(self, entities: Set[Entity], event_handler: EventHandler, player: Entity):
|
||||
self.entities = entities
|
||||
self.event_handler = event_handler
|
||||
self.player = player
|
||||
|
||||
def main():
|
||||
screen_width = 80
|
||||
screen_height = 50
|
||||
def handle_events(self, events: Iterable[Any]) -> None:
|
||||
for event in events:
|
||||
action = self.event_handler.dispatch(event)
|
||||
|
||||
map_width = 80
|
||||
map_height = 50
|
||||
if action is None:
|
||||
continue
|
||||
|
||||
room_max_size = 10
|
||||
room_min_size = 6
|
||||
max_rooms = 30
|
||||
if isinstance(action, MovementAction):
|
||||
self.player.move(dx=action.dx, dy=action.dy)
|
||||
elif isinstance(action, EscapeAction):
|
||||
raise SystemExit()
|
||||
|
||||
colors = {
|
||||
'dark_wall': tcod.Color(0, 0, 100),
|
||||
'dark_ground': tcod.Color(50, 50, 150)
|
||||
}
|
||||
def render(self, console: Console, context: Context) -> None:
|
||||
for entity in self.entities:
|
||||
console.print(entity.x, entity.y, entity.char, fg=entity.color)
|
||||
|
||||
# player = Entity(int(screen_width/2), int(screen_height/2), '@', tcod.white)
|
||||
# npc = Entity(int(screen_width/2), int(screen_height/2), '@', tcod.yellow)
|
||||
# entities = [npc, player]
|
||||
player_x = int(screen_width/2)
|
||||
player_y = int(screen_width/2)
|
||||
context.present(console)
|
||||
|
||||
tileset = tcod.tileset.load_tilesheet(
|
||||
"arial10x10.png", 32,8, tcod.tileset.CHARMAP_TCOD
|
||||
)
|
||||
|
||||
event_handler = EventHandler()
|
||||
|
||||
with tcod.context.new_terminal(
|
||||
screen_width,
|
||||
screen_height,
|
||||
tileset=tileset,
|
||||
title='Roguelike Tutorial',
|
||||
vsync=True,
|
||||
) as context:
|
||||
root_console = tcod.Console(screen_width,screen_height, order="F")
|
||||
while True:
|
||||
root_console.print(x=player_x, y=player_y, string="@")
|
||||
|
||||
context.present(root_console)
|
||||
|
||||
root_console.clear()
|
||||
|
||||
for event in tcod.event.wait():
|
||||
action = event_handler.dispatch(event)
|
||||
|
||||
if action is None:
|
||||
continue
|
||||
|
||||
if isinstance(action, MovementAction):
|
||||
player_x += action.dx
|
||||
player_y += action.dy
|
||||
elif isinstance(action, EscapeAction):
|
||||
raise SystemExit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
console.clear()
|
||||
Reference in New Issue
Block a user