-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplace.js
83 lines (56 loc) · 1.52 KB
/
place.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
class Place {
constructor(name, x, y, size = 200) {
this.name = name;
this.colorNormal = "rgb(90,100,90,0.4)";
this.colorActive = "rgb(90,100,90,0.7)";
this.color = this.colorNormal
this.visible = true;
this.x = x;
this.y = y;
this.radius = 30;
this.width = 2*this.radius;
this.height = 2*this.radius;
this.type = (y == groundPoint ? Place.TYPE.GROUND : Place.TYPE.SPACE);
this.emojiSize = size;
}
step(dt) {
}
draw() {
ctx.save();
ctx.translate(this.x, this.y);
ctx.strokeStyle = this.color;
ctx.fillStyle = this.color;
let r = this.radius*4;
ctx.beginPath();
ctx.ellipse(0, 0+32, r, r * 0.2, 0, 0, 2 * Math.PI);
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.ellipse(0, 0+34 + 1, r / 2, r / 2 * 0.2, 0, 0, 2 * Math.PI);
ctx.fill();
ctx.stroke();
// ctx.strokeStyle = "red";
// ctx.beginPath(),
// ctx.arc(0,0,this.radius,0,Math.PI*2);
// ctx.stroke();
// ctx.closePath();
// ctx.rect(-this.width/2, -this.height/2, this.width, this.height);
// ctx.stroke();
ctx.restore();
}
inSafeDistance(otherDot) {
var dist = this.distance(otherDot);
var minDist = this.SafeDistance + otherDot.radius;
if (dist < minDist) {
return true;
}
return false;
}
distance(position) {
var dx = position.x - this.x,
dy = position.y - this.y,
dist = Math.sqrt(dx * dx + dy * dy);
return dist;
}
}
Place.TYPE = { GROUND: "GROUND", SPACE: "SPACE" };