This repository has been archived by the owner on May 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
player.js
90 lines (81 loc) · 2.04 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import vinage from 'vinage';
import resources from '../server/resource_loader.js';
import Smg from '<@Smg@>';
import Lmg from '<@Lmg@>';
import Shotgun from '<@Shotgun@>';
import Knife from '<@Knife@>';
export default class Player {
constructor() {
this.box = new vinage.Rectangle(new vinage.Point(0, 0), 0, 0);
this.controls = {
jump: 0,
crouch: 0,
jetpack: 0,
moveLeft: 0,
moveRight: 0,
run: 0,
changeWeapon: 0,
shoot: 0
};
this.velocity = new vinage.Vector(0, 0);
this._walkFrame = 'stand';
this.jetpack = false;
this.health = 8;
this.fillStamina();
this.attachedPlanet = -1;
this.lastlyAimedAt = Date.now();
this.weapons = {
Smg: new Smg(this),
Lmg: new Lmg(this),
Shotgun: new Shotgun(this),
Knife: new Knife(this)
};
this.armedWeapon = this.weapons.Lmg;
this.carriedWeapon = this.weapons.Smg;
this.aimAngle = 0;
}
get appearance() {
return this._appearance;
}
set appearance(newAppearance) {
this._appearance = newAppearance;
this.setBoxSize();
}
get walkFrame() {
return this._walkFrame;
}
set walkFrame(newWalkFrame) {
this._walkFrame = newWalkFrame;
this.setBoxSize();
}
increaseStamina(by) { // returns whether the stamina has been succesfully increased
let predicStamina = this.stamina + by;
if (this.stamina === this.maxStamina) return false;
else if (predicStamina > this.maxStamina) {
this.stamina = this.maxStamina;
return true;
} else {
this.stamina = predicStamina;
return true;
}
}
decreaseStamina(by) { // returns whether the stamina has been succesfully decerased
let predicStamina = this.stamina - by;
if (this.stamina === 0) return false;
else if (predicStamina < 0) {
this.stamina = 0;
return true;
} else {
this.stamina = predicStamina;
return true;
}
}
fillStamina() {
this.stamina = this.maxStamina;
}
setBoxSize() {
this.box.width = resources[this.appearance + '_' + this.walkFrame].width;
this.box.height = resources[this.appearance + '_' + this.walkFrame].height;
}
}
Player.prototype.maxStamina = 300;