-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.py
53 lines (37 loc) · 1.53 KB
/
engine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from tcod import ecs, console, context
from numpy import ndarray
from game_map import generate_game_map
from position import Position
from graphic import Graphic
from tags import IsPlayer, CanSee
from player import Player
def getplayer(registry: ecs.Registry):
return registry.Q.all_of(tags=[IsPlayer])
class Engine:
def __init__(self, map_width, map_height) -> None:
self.registry = ecs.Registry()
self.game_map = generate_game_map(self.registry, map_width, map_height)
Player(name="David", hp=10).spawn(1,1, self.registry)
def render(self, console: console.Console, context: context.Context):
# Render the tilemap onto the screen at a position based on offset
console.rgb[
0:self.game_map.components[("width", int)],
0:self.game_map.components[("height", int)]
] = self.game_map.components[ndarray]["dark"]
# Render all entities with "visible" tag
for e in self.registry.Q.all_of(
relations=[(getplayer(self.registry), CanSee, None)]
):
x = e.components[Position].x
y = e.components[Position].y
e.components[Graphic].render(x, y, console)
# Present the new console to the screen
context.present(console)
def do_player_turn(self):
pass
def do_enemy_turns(self):
pass
def do_one_turn(self, console: console.Console, context: context.Context):
self.render(console, context)
self.do_player_turn()
self.do_enemy_turns()