-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tool.js
89 lines (76 loc) · 2.54 KB
/
Tool.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
function Tool(typeName, bound) {
this.typeName = typeName;
this.width = 40;
this.lifeSpan = 1400; //lifespan is approx 1 miniute
if (typeName == "shell") {
this.height = 39;
this.apply = function (player) { //changes player behavior
this.age = 0;
player.step /= 2;
};
this.restore = function (player) { //restore player behavior
player.step *= 2;
};
}
if (typeName == "heart") {
this.height = 34;
this.apply = function (player) { //changes player behavior
player.life++;
};
}
if (typeName == "ironman") {
this.height = 60;
this.apply = function (player) { //changes player behavior
this.age = 0;
player.isIronman = true;
//change pic Id
};
this.restore = function (player) { //restore player behavior
player.isIronman = false;
//change pic Id
};
}
if (typeName == "shoe") {
this.width = 50;
this.height = 24;
this.apply = function (player) { //Apply: changes player behavior
this.age = 0;
player.kickLevel *= 1.5;
};
this.restore = function (player) { //restore player behavior
player.kickLevel /= 1.5;
};
}
if (typeName == "skate") {
this.height = 46;
this.apply = function (player) { //Apply: changes player behavior
this.age = 0;
player.step *= 1.5;
};
this.restore = function (player) { //restore player behavior
player.step /= 1.5;
};
}
if (typeName == "box") {
this.height = 38;
this.apply = function (player) {
player.bombNum++;
};
}
this.maxX = bound.maxX - this.width;
this.maxY = bound.maxY - this.height;
this.posX = Math.round(Math.random() * this.maxX);
this.posY = Math.round(Math.random() * this.maxY);
this.centerX = this.posX + this.width / 2;
this.centerY = this.posY + this.height / 2;
}
Tool.prototype.extendLife = function (t) {
this.lifeSpan += t.lifeSpan;
};
Tool.prototype.checkCollision = function (o, margin) {
margin = margin || 0;
var dist = Math.ceil(Math.sqrt(Math.pow(this.centerX - o.centerX, 2) + Math.pow(this.centerY - o.centerY, 2)));
var collide = dist < margin + this.width / 2 + o.width / 2;
return collide ? dist : false;
};
module.exports = Tool;