-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpBar.js
More file actions
66 lines (53 loc) · 1.39 KB
/
ExpBar.js
File metadata and controls
66 lines (53 loc) · 1.39 KB
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
import Phaser from "phaser";
// import Config from "../Config";
import { clamp } from "../utils/math";
// TODO: HpBar와 겹치는 부분 클래스로 분리
export default class ExpBar extends Phaser.GameObjects.Graphics {
// static WIDTH = Config.width;
static WIDTH = 800; // TODO: how to get from config?
static HEIGHT = 30;
static BORDER = 4;
constructor(scene, maxExp) {
super(scene);
this.m_x = 0;
this.m_y = 30;
this.m_maxExp = maxExp;
this.m_currentExp = 0;
this.draw();
this.setDepth(100);
this.setScrollFactor(0);
scene.add.existing(this);
}
increase(amount) {
this.m_currentExp = clamp(this.m_currentExp + amount, 0, this.m_maxExp);
this.draw();
}
reset() {
this.m_currentExp = 0;
this.draw();
}
draw() {
this.clear();
// BG
this.fillStyle(0x000000);
this.fillRect(this.m_x, this.m_y, ExpBar.WIDTH, ExpBar.HEIGHT);
// Exp
this.fillStyle(0xffffff);
this.fillRect(
this.m_x + ExpBar.BORDER,
this.m_y + ExpBar.BORDER,
ExpBar.WIDTH - 2 * ExpBar.BORDER,
ExpBar.HEIGHT - 2 * ExpBar.BORDER
);
this.fillStyle(0x3665d5);
let d = Math.floor(
((ExpBar.WIDTH - 2 * ExpBar.BORDER) / this.m_maxExp) * this.m_currentExp
);
this.fillRect(
this.m_x + ExpBar.BORDER,
this.m_y + ExpBar.BORDER,
d,
ExpBar.HEIGHT - 2 * ExpBar.BORDER
);
}
}