]> git.r.bdr.sh - rbdr/serpentity/blame_incremental - README.md
Adds link + priority in to-do
[rbdr/serpentity] / README.md
... / ...
CommitLineData
1# Serpentity
2
3Serpentity is a simple entity framework inspired by [Ash][ash].
4
5Usage:
6
7 require('serpentity');
8
9## Instantiating an engine
10
11 var engine = Serpentity();
12
13Add entities or systems:
14
15 engine.addEntity(entityFactory());
16 engine.addSystem(new GameSystem());
17
18Update all systems:
19
20 engine.update(dt);
21
22Remove entities or systems:
23
24 engine.removeEntity(entityReference);
25 engine.removeSystem(systemReference);
26
27## Creating Entities
28
29Entities are the basic object of Serpentity, and they do nothing.
30
31 var entity = new Serpentity.Entity();
32
33All the behavior is added through components
34
35## Creating Components
36
37Components define data that we can add to an entity. This data will
38eventually be consumed by "Systems"
39
40 Class("PositionComponent").inherits(Serpentity.Component)({
41 prototype : {
42 x : 0,
43 y : 0
44 }
45 });
46
47You can add components to entities by using the add method:
48
49 entity.add(new PositionComponent());
50
51
52Systems can refer to entities by requesting nodes.
53
54## Working with Nodes
55
56Nodes are sets of components that you define, so your system can require
57entities that always follow the API defined in the node.
58
59 Class("MovementNode").inherits(Serpentity.Node)({
60 types : {
61 position : PositionComponent,
62 motion : MotionComponent
63 }
64 });
65
66You can then request an array of all the nodes representing entities
67that comply with that API
68
69 engine.getNodes(MovementNode);
70
71## Creating Systems
72
73Systems are called on every update, and they use components through nodes.
74
75 Class("TestSystem").inherits(Serpentity.System)({
76 prototype : {
77 added : function added(engine){
78 this.nodeList = engine.getNodes(MovementNode);
79 },
80 removed : function removed(engine){
81 this.nodeList = undefined;
82 }
83 update : function update(dt){
84 this.nodeList.forEach(function (node) {
85 console.log("Current position is: " + node.position.x + "," + node.position.y);
86 });
87 }
88 }
89 });
90
91## That's it
92
93Just run `engine.update(dt)` in your game loop :D
94
95## TO-DO
96
97* Priorities
98* Removing components
99* Implement the ashteroids demo (Serpentoids)
100* Actually check performance
101
102[ash]: http://www.ashframework.org/