forked from HexDecimal/python-tcod-tutorial-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworld_tools.py
More file actions
32 lines (22 loc) · 899 Bytes
/
world_tools.py
File metadata and controls
32 lines (22 loc) · 899 Bytes
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
"""Functions for working with worlds."""
from __future__ import annotations
from random import Random
from tcod.ecs import Registry
from game.components import Gold, Graphic, Position
from game.tags import IsActor, IsItem, IsPlayer
def new_world() -> Registry:
"""Return a freshly generated world."""
world = Registry()
rng = world[None].components[Random] = Random()
player = world[object()]
player.components[Position] = Position(5, 5)
player.components[Graphic] = Graphic(ord("@"))
player.components[Gold] = 0
player.tags |= {IsPlayer, IsActor}
for _ in range(10):
gold = world[object()]
gold.components[Position] = Position(rng.randint(0, 20), rng.randint(0, 20))
gold.components[Graphic] = Graphic(ord("$"), fg=(255, 255, 0))
gold.components[Gold] = rng.randint(1, 10)
gold.tags |= {IsItem}
return world