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