-
Notifications
You must be signed in to change notification settings - Fork 29
/
Player.js
executable file
·76 lines (64 loc) · 1.42 KB
/
Player.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
function Player(startX, startY, pName, hp, id) {
this.pos = {x: startX, y: startY};
this.dir = 2;
this.alive = true;
this.maxhp = 100;
this.money = 0;
this.currhp = hp;
this.name = pName;
this.goFight = null;
this.fighting = null;
this.strength = 50;
this.lastStrike = 0;
this.hitSpeed = 500;
this.id = id;
this.tileSize = 0;
this.xpForLevel = function(level) {
return level*level*level;
};
this.getLastStrike = function() {
return this.lastStrike;
};
this.getCurrHP = function() {
return this.currhp;
};
this.getHurt = function(amount) {
this.currhp -= amount;
if(this.currhp < 0) {
this.currhp = 0;
this.alive = false;
}
};
this.setLastStrike = function(time) {
this.lastStrike = time;
};
this.setGoFight = function(value) {
this.goFight = value;
//this.goToNpc = null;
//this.talkingTo = null;
if(value == null) {
this.fighting = null;
}
};
this.stopFight = function() {
this.goFight = null;
this.fighting = null;
};
this.inFight = function(enemyID) {
this.fighting = enemyID;
};
this.readyToHit = function() {
return (this.fighting != null && (Date.now() - this.lastStrike > this.hitSpeed));
};
this.takeItem = function(type, change) {
if(type == 0) {
this.currhp += change;
}
else if(type == 1) {
this.money += change;
}
};
}
// Export the Player class so you can use it in
// other files by using require("Player").Player
exports.Player = Player;