-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverworld.js
89 lines (71 loc) · 2.42 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
82
83
84
85
86
87
88
89
class Overworld {
constructor(config) {
this.element = config.element;
this.canvas = this.element.querySelector(".game-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);
//Establish the camera person
const cameraPerson = this.map.gameObjects.hero;
//Update all objects
Object.values(this.map.gameObjects).forEach(object => {
object.update({
arrow: this.directionInput.direction,
map: this.map,
})
})
//Draw Lower layer
this.map.drawLowerImage(this.ctx, cameraPerson);
//Draw Game Objects
// reorders array so more northern characters are layered differently from southern
Object.values(this.map.gameObjects).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", () => {
//Is there a person here to talk to ???
this.map.checkForActionCutscene()
});
}
bindHeroPositionCheck() {
document.addEventListener("PersonWalkingComplete", e => {
if (e.detail.whoId === "hero") {
//Hero's position has changed
this.map.checkForFootstepCutscene()
}
})
}
startMap(){
}
init() {
this.map = new OverworldMap(window.OverworldMaps.DemoRoom);
this.map.mountObjects();
this.bindActionInput();
this.bindHeroPositionCheck();
this.directionInput = new DirectionInput();
this.directionInput.init();
this.startGameLoop();
/* this.map.startCutscene([
{ who: "hero", type: "walk", direction: "down"},
{ who: "hero", type: "walk", direction: "down"},
{ who: "npcA", type: "walk", direction: "up"},
{ who: "npcA", type: "walk", direction: "left"},
{ who: "hero", type: "stand", direction: "right",time:200},
{ type: "textMessage", text: "you gotta escape"},
]) */
}
}