-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathminimap.js
101 lines (70 loc) · 2.45 KB
/
minimap.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
class MiniMap {
constructor(screen, w, h) {
this.width = w;
this.height = h;
this.x = screen.width - this.width * 1 / 10 - w;
this.y = screen.height - this.height * 1 / 10 - h;
this.color = "#282828";
}
step(dt) {
}
draw(ctx) {
ctx.save();
ctx.lineWidth = 1;
ctx.strokeStyle = "#fff";
ctx.fillStyle = this.color;
ctx.translate(this.x - 10, this.y - 20);
ctx.beginPath();
ctx.rect(0, 0, this.width, this.height);
ctx.fill();
ctx.stroke();
let ratioX = 0.03;
let ratioY = 0.08;
ctx.translate(20, 75);
ctx.beginPath();
ctx.fillStyle = "rgba(0,200,100,0.6)";
ctx.fillRect(0 - 20, 5 + groundPoint * ratioY, this.width, (this.height / 2 - groundPoint) * ratioY);
ctx.strokeStyle = "rgb(255,255,255,0.5)";
ctx.setLineDash([2, 2]);
ctx.lineWidth = 3;
let resource = game.resources
.filter(resource => { return resource.name == game.mission.path[0] })[0];
if (resource) {
// Target
game.bases
.filter(base => { return base.name == game.mission.path[1] })
.forEach(base => {
ctx.beginPath();
ctx.moveTo(50 + resource.x * ratioX, resource.y * ratioY);
ctx.lineTo(50 + base.x * ratioX, base.y * ratioY);
ctx.stroke();
});
}
// Customers position
game.bases
.forEach(base => {
if (base.visible) {
ctx.font = "bold 25px Verdana";
ctx.beginPath();
ctx.fillText(base.name, 35 + base.x * ratioX, base.y * ratioY - 5);
}
});
// Resources position
game.resources
.forEach(resource => {
if (resource.visible) {
ctx.font = "bold 20px Verdana";
ctx.beginPath();
ctx.fillText(resource.name, 35 + resource.x * ratioX, resource.y * ratioY - 5);
}
});
// Rocket position
game.rockets.forEach(rocket => {
ctx.beginPath();
ctx.fillStyle = "rgb(255, 255, 50)";
ctx.arc(50 + rocket.x * ratioX, 0 + rocket.y * ratioY, 5, 0, Math.PI * 2);
ctx.fill();
});
ctx.restore();
}
}