BlueGit

blue-star cellular-evolution

Files

cellular-evolution / src / cell.js

cell.js

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