-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.js
38 lines (30 loc) · 874 Bytes
/
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
(function(exports) {
var Player = function(id, x, y) {
this.id = id || -1;
this.nick = 'Guest'+ this.id;
this.x = x || 0;
this.y = y || 0;
this.isAlive = true;
this.HP = 100;
this.lastMoveTime = Date.now();
this.ping = 0;
this.width = 10;
this.height = 10;
this.centerX = this.width / 2;
this.centerY = this.height / 2;
this.moved = false;
this.moveLeft = false;
this.moveRight = false;
this.moveUp = false;
this.moveDown = false;
this.lastMoveDir = 'd';
};
Player.prototype.toString = function() {
return /*this.id +' '+ */this.nick +' '+ this.x +':'+ this.y +' '+ this.ping +'ms';
};
Player.prototype.hasMoved = function() {
this.moved = (this.moveLeft || this.moveRight || this.moveUp || this.moveDown);
return this.moved;
};
exports.Player = Player;
})(typeof global === "undefined" ? window : exports);