-
Notifications
You must be signed in to change notification settings - Fork 0
/
head.js
44 lines (33 loc) · 933 Bytes
/
head.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var Head = (function () {
function Head(data) {
this.position = data.position;
this.direction = data.direction;
}
Head.prototype = new SnakeBit({id:null, position:null, front:null});
Head.prototype.draw = function() {
mvPushMatrix();
mat4.translate(mvMatrix, this.position);
drawCube(snakeTex);
mvPopMatrix();
}
Head.prototype.animate = function (elapsed) {
//lerp is the linear interpolation amount
var lerp = speed*elapsed;
var newPosition = vec3.create();
if(cruiseControl){
//move towards apple
vec3.lerp(this.position, apple.position, lerp*0.1);
}else{
//move in direction
vec3.add(this.position,this.direction, newPosition);
vec3.lerp(this.position, newPosition, lerp);
}
//if goes out of the skybox
for (var i=0; i<3; i++){
if(this.position[i]>30 || this.position[i]<-30){
gameOver = true;
}
}
}
return Head;
}());