-
Notifications
You must be signed in to change notification settings - Fork 0
/
hero.js
40 lines (36 loc) · 1.06 KB
/
hero.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
class Hero {
constructor(name, faceLeft, faceRight, faceFront, leftValue) {
this.name = name;
this.leftValue = leftValue;
this.faceLeft = faceLeft;
this.faceRight = faceRight;
this.faceFront = faceFront;
this.topValue = 546;
this.createHero();
}
createHero() {
const bgId = document.getElementById('bg');
this.heroDiv = document.createElement('div');
this.heroDiv.className = this.name;
this.heroDiv.style.top = this.topValue + 'px';
this.heroDiv.style.left = this.leftValue + 'px';
bgId.appendChild(this.heroDiv);
}
changePositionLeft() {
this.heroDiv.style.backgroundPosition = this.faceLeft;
if (this.leftValue > 0) {
this.leftValue -= 10;
this.heroDiv.style.left = this.leftValue + 'px';
}
}
changePositionRight() {
this.heroDiv.style.backgroundPosition = this.faceRight;
if (this.leftValue < (800 - 37)) {
this.leftValue += 10;
this.heroDiv.style.left = this.leftValue + 'px';
}
}
lookFront() {
this.heroDiv.style.backgroundPosition = this.faceFront;
}
}