-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshiphandler.js
86 lines (82 loc) · 2.46 KB
/
shiphandler.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class Ship {
constructor(x, y, angle, color, health, acc, diacc, maxspeed, turn){
this.x = x;
this.y = y;
this.angle = angle;
this.color = "green";
this.prevcolor = "green"
this.health = health;
this.speed = 0
this.turn = turn;
this.acc = acc;
this.diacc = diacc,
this.maxspeed = maxspeed;
this.timer;
}
draw(){
canvas.strokeStyle = this.color;
canvas.lineWidth = 3;
canvas.beginPath();
canvas.translate(this.x, this.y);
canvas.rotate(deg(this.angle));
canvas.moveTo(+22, -7);
canvas.lineTo(+14, -15);
canvas.lineTo(-36, -15);
canvas.lineTo(-19, -7);
canvas.lineTo(+30, -7);
canvas.lineTo(+38, 0);
canvas.lineTo(+30, +6);
canvas.lineTo(-19, +6);
canvas.lineTo(-36, +14);
canvas.lineTo(+14, +14);
canvas.lineTo(+22, +6);
canvas.moveTo(-36, -15);
canvas.closePath();
canvas.stroke();
canvas.rotate(deg(-this.angle));
canvas.translate(-this.x, -this.y);
}
cannon() {
let {x, y} = trig(this.x, this.y, this.angle, 33)
return trig(x, y, this.angle, 5);
}
loop(t){
if (this.speed < 0){
this.speed += this.diacc;
} else if (this.speed > 0) {
this.speed -= this.diacc;
}
if (this.speed > this.maxspeed){
this.speed = this.maxspeed;
} else if (this.speed < -this.maxspeed){
this.speed = -this.maxspeed;
}
let {x, y} = trig(this.x, this.y, this.angle, this.speed)
this.x = x;
this.y = y;
if (status == "invincible"){
this.color = "gray"
this.timer -= t;
if (this.timer <= 0){
status = "idle"
}
} else {
if (this.health > 60 && this.health <= 80){
this.color = "lime"
this.prevcolor = "lime"
} else if (this.health > 40 && this.health <= 60){
this.prevcolor = "yellow"
this.color = "yellow"
} else if (this.health > 20 && this.health <= 40){
this.color = "orange"
this.prevcolor = "orange"
} else if (this.health <= 20) {
this.color = "red"
this.prevcolor = "red"
}
this.color = this.prevcolor;
this.timer = 5;
}
//console.log(this.timer)
}
}