BlueGit

blue-star cellular-evolution

Files

cellular-evolution / src / cell.js

cell.js

cell.js 1.9 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 activate: function(strength, deltaTime)
29 {
30 this.lastSum = strength;
31
32 switch(this.type)
33 {
34 case TYPES.LOCOMOTOR:
35 var rotated = this.localPos.rotate(this.parentCreature.transform.rotation);
36
37 this.parentCreature.transform.position = this.parentCreature.transform.position.subtract(rotated.stretch(deltaTime));
38 break;
39 case TYPES.ROTATOR:
40 this.parentCreature.transform.rotation += (strength - 0.5) * deltaTime * 50;
41 break;
42 }
43 },
44
45 draw: function()
46 {
47 this.defaultDraw();
48
49 GameWindow.canvasContext.fillStyle = 'black';
50 GameWindow.canvasContext.fillText(this.lastSum, this.transform.position.x, this.transform.position.y);
51 },
52
53 update: function()
54 {
55 var rotated = this.localPos.rotate(this.parentCreature.transform.rotation);
56 this.transform.position = rotated.stretch(this.transform.scale.x).add(this.parentCreature.transform.position);
57
58 if(this.type == TYPES.EYE)
59 this.transform.rotation = rotated.toAngle();
60
61 if(this.type == TYPES.LOCOMOTOR)
62 this.transform.rotation = rotated.toAngle() - 90;
63 },
64
65 setType: function(typeID)
66 {
67 this.renderer.subImage = typeID;
68 this.type = typeID;
69 }
70}