-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverworld.js
81 lines (64 loc) · 2.24 KB
/
Overworld.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
class Overworld {
constructor(config) {
this.element = config.element;
this.canvas = this.element.querySelector('canvas');
this.ctx = this.canvas.getContext('2d');
this.map = null;
}
startGameLoop() {
const step = () => {
// Clear off the canvas
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
const cameraPerson = this.map.gameObject.hero
Object.values(this.map.gameObject).forEach(object => {
object.update({
arrow: this.directionInput.direction,
map: this.map,
})
})
//Draw Lower layer
this.map.drawLowerImage(this.ctx, cameraPerson);
//Draw Game Objects
Object.values(this.map.gameObject).sort((a, b) => {
return a.y - b.y;
}).forEach(object => {
object.sprite.draw(this.ctx, cameraPerson)
})
//Draw Upper layer
this.map.drawUpperImage(this.ctx, cameraPerson);
requestAnimationFrame(() => {
step();
})
}
step()
}
bindActionInput(){
new KeyPressListener("Enter", () =>{
this.map.checkForActionCutscene()
})
}
bindHeroPositionCheck(){
document.addEventListener("PersonWalkingComplete", e => {
if(e.detail.whoId === "hero"){
this.map.checkForFootstepCutscene()
}
})
}
startMap(mapConfig){
this.map = new OverworldMap(mapConfig);
this.map.overworld = this;
this.map.mountObject();
}
init() {
this.startMap(window.OverworldMap.DemoRoom);
this.bindActionInput();
this.bindHeroPositionCheck();
this.directionInput = new DirectionInput();
this.directionInput.init()
this.startGameLoop();
this.map.startCutscene([
// {type: "changMap", map: "DemoRoom"}
{ type: "textMessage", text: "Равным образом повышение уровня гражданского сознания позволяет оценить значение модели..."},
])
}
}