-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpg.py
69 lines (58 loc) · 2.16 KB
/
rpg.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
from ecs import EntityManager, SystemManager
from components import *
from systems import *
def main():
# Create an entity manager, a database entities and components.
database = EntityManager()
# Create a player entity.
player = database.create_entity()
wep1 = database.create_entity()
# Add components
database.add_component(wep1, Weapon())
database.add_component(wep1, Item())
database.add_component(wep1, Str(10))
database.add_component(wep1, Name("Basic Sword"))
database.add_component(player, Position(x=10, y=10))
database.add_component(player, Velocity())
database.add_component(player, Player())
database.add_component(player, Name("Ra"))
database.add_component(player, Health(10000))
database.add_component(player, Str(10))
database.add_component(player, Def(10))
database.add_component(player, Vision(10))
database.add_component(player, Visible())
database.add_component(player, Equip(weapon=wep1))
pos = [Position(x=15, y=20), Position(x=11, y=10), Position(x=16, y=19)]
for p in pos:
mob1 = database.create_entity()
database.add_component(mob1, p)
database.add_component(mob1, Velocity(1, 1))
database.add_component(mob1, AI())
database.add_component(mob1, Name("Mob" + str(mob1._guid)))
database.add_component(mob1, Health(100))
database.add_component(mob1, Str(15))
database.add_component(mob1, Def(1))
database.add_component(mob1, Visible())
database.add_component(mob1, Vision(5))
database.add_component(mob1, Equip(weapon=wep1))
# Create a system manager, i.e. the game world.
game = SystemManager(database)
# add systems
game.add_system(Movement())
game.add_system(Attack())
game.add_system(Kill())
game.add_system(SpawnMob())
game.add_system(Display())
game.add_system(Input())
game.add_system(AIMove())
try:
while True:
# Runs the update() method of all added systems.
game.update(1)
except KeyboardInterrupt:
return
if __name__ == '__main__':
main()