-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntity_CPU.js
54 lines (49 loc) · 1.08 KB
/
Entity_CPU.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
44
45
46
47
48
49
50
51
52
53
54
function Entity_CPU()
{
var self = this;
self.name = "cpu";
self.x = 547;
self.y = 1024;
self.baseSpeed = 325;
self.speed = self.baseSpeed;
self.heading = 0;//0=up, 1=down;
//Values for Physics
self.height = 96;
self.width = 16;
self.level = 1;
self.moving = false;
self.lightInteraction = true;
this.setLevel = function(LEVEL)
{
self.level = LEVEL;
self.setSpeed();
}
this.setSpeed = function()
{
self.speed = self.baseSpeed + (self.level * 100);
}
this.setPosition = function(X, Y)
{
self.x = X;
self.y = Y;
}
this.update = function()
{
// Get facking ball
for(var i = 0; i < world.entity.length; i++){
if(world.entity[i].name == 'ball'){
ball = world.entity[i];
if(Math.abs(self.x - ball.x) < 300 && ball.xHeading == 0){
console.log(self.y + " | " + ball.y);
self.y += (self.speed * clock.delta) * ((self.y < ball.y) ? 1 : -1);
}
break;
}
}
}
this.draw = function()
{
canvas.fillStyle = "rgb(255,0,255)";
canvas.fillRect(h.X(self.x - self.width / 2), h.Y(self.y - self.height / 2), self.width, self.height);
}
}