BlueGit

blue-star cellular-evolution

Files

cellular-evolution / src / cell.js

cell.js

cell.js 1.1 KiB Download Raw
1/**
2 * Part of a creature!
3 */
4
5var cell =
6{
7 localPos: new vector(0, 0),
8 parentCreature: null,
9 cellRef: -1,
10 currentSensorSignal: 0, //only used for sensors, else forever zero
11 lastSum: 0, //used for debug purposes
12
13 start: function()
14 {
15 this.transform.scale.x = 0;
16 this.transform.scale.y = 0;
17
18 var scaleUpTween = new TWEEN.Tween(this.transform.scale);
19
20 scaleUpTween.to({x: [1.5, 1], y: [1.5, 1]}, Math.random() * 3200);
21
22 scaleUpTween.easing(TWEEN.Easing.Back.Out);
23
24 scaleUpTween.start();
25 },
26
27 draw: function()
28 {
29 this.defaultDraw();
30
31 GameWindow.canvasContext.fillStyle = 'black';
32 GameWindow.canvasContext.fillText(this.lastSum, this.transform.position.x, this.transform.position.y);
33 },
34
35 update: function()
36 {
37 var rotated = this.localPos.rotate(this.parentCreature.transform.rotation);
38 this.transform.position = rotated.stretch(this.transform.scale.x).add(this.parentCreature.transform.position);
39 },
40
41 setType: function(typeID)
42 {
43 this.renderer.subImage = typeID;
44 }
45}