Bring in the ECS I wrote for later and phase_07.py now has a change the window display. If I have a border then the self.map coordinates don't fit the screen coordinates. Removing it makes them match which is easier. Also going to a smaller display makes it easier to work with and less intimidating.
parent
117748ae5d
commit
83eac4747f
@ -0,0 +1,62 @@ |
||||
|
||||
class ECS: |
||||
def __init__(self): |
||||
self.entities = {} |
||||
self.facts = {} |
||||
self.id_counter = 0 |
||||
|
||||
def entity(self): |
||||
self.id_counter += 1 |
||||
return self.id_counter |
||||
|
||||
def set(self, entity_id, obj): |
||||
name = obj.__class__.__qualname__ |
||||
target = self.entities.get(name, {}) |
||||
target[entity_id] = obj |
||||
self.entities[name] = target |
||||
|
||||
def query(self, cls): |
||||
return self.entities[cls.__qualname__].items() |
||||
|
||||
|
||||
class Systems: |
||||
def __init__(self, ecs): |
||||
self.ecs = ecs |
||||
|
||||
def play_sounds(self): |
||||
for eid, entity in ecs.query(Sound): |
||||
print("TALKING: ", entity.text) |
||||
|
||||
def combat(self): |
||||
for eid, entity in ecs.query(Combat): |
||||
print("FIGHT: ", entity.hp) |
||||
|
||||
def movement(self): |
||||
for eid, entity in ecs.query(Position): |
||||
print("MOVE: ", entity.x, entity.y) |
||||
|
||||
class Combat: |
||||
def __init__(self, hp): |
||||
self.hp = hp |
||||
|
||||
class Sound: |
||||
def __init__(self, text): |
||||
self.text = text |
||||
|
||||
class Position: |
||||
def __init__(self, x, y): |
||||
self.x = x |
||||
self.y = y |
||||
|
||||
|
||||
ecs = ECS() |
||||
systems = Systems(ecs) |
||||
|
||||
troll = ecs.entity() |
||||
ecs.set(troll, Combat(100)) |
||||
ecs.set(troll, Sound("ROAR!")) |
||||
ecs.set(troll, Position(1, 2)) |
||||
|
||||
systems.play_sounds() |
||||
systems.combat() |
||||
systems.movement() |
Loading…
Reference in new issue