-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsceneManager.js
More file actions
176 lines (143 loc) · 6.31 KB
/
sceneManager.js
File metadata and controls
176 lines (143 loc) · 6.31 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
class SceneManager{
levels = [levelOne, levelTwo, levelThree, levelFour];
constructor(game){
this.game = game;
this.game.camera = this;
this.worldSize = 1;
this.x = 0;
this.y = 0 ;
this.score = 0;
this.gameOver = false;
this.soundEngine = new SoundEngine(this.game);
this.soundEngine.setVolumes(); // configure volumes to reflect configs.
this.player = new CharacterController(this.game,0,0);
this.levelNum = 0;
this.loadLevel(levelOne,0,0);
this.marker = 0;
};
clearEntities() {
this.game.entities.forEach(function (entity) {
entity.removeFromWorld = true;
this.soundEngine.pauseBackgroundMusic();
}.bind(this));
};
loadLevel(level , x, y){
// Setup of level properties here.
this.level = level;
this.game.entities = [this] // TODO: this does not clear/unload entities.
this.x = 0;
this.y = 0;
// Hi. I changed this from 'y' to '0' to make it look like the
// character just falls out of the sky. More so that they fall
// into the ground level 2 from above - Michael
this.player.jumpInitPosition = null; // on zone-in lets simulate dropping off a ledge.
this.player.jumpInitTime = null;
this.player.wasOnGround = true;
this.player.onGround = true;
this.player.state = "IDLE";
console.log("zoning in @ ", x, y);
if(level.music) {
this.soundEngine.pauseBackgroundMusic();
this.soundEngine.playBackgroundMusic(level.music);
}
//Custom level starting point
this.player.x = level.spawnPoint[0];
this.player.y = level.spawnPoint[1];
this.game.addEntity(new Background(this.game, level.background));
this.game.addEntity(new Foreground(this.game, level.foreground));
this.game.addEntity(new Pillars(this.game, level.pillars));
this.worldSize = level.worldSize;
// TODO: refactor/ generalize to handle more diverse blocks in the level design
for(const entry of level.ground) {
// generate ground objects based on designated type in levels.js
this.game.addEntity(new level['groundType'](this.game, entry.x, entry.y, entry.size));
}
for(const entry of level.wall) {
// generate ground objects based on designated type in levels.js
this.game.addEntity(new level['wallType'](this.game, entry.x, entry.y, entry.size));
}
for(const entry of level.targetblock) {
this.game.addEntity(new Flag_Block(this.game, entry.x, entry.y,entry.xScale,entry.yScale));
console.log("added flagblock", [entry.x, entry.y, entry.size]);
}
for(const entry of level.arrows){
if(entry.name == "Down"){
this.game.addEntity(new DownArrow(this.game,entry.x ,entry.y));
}else if(entry.name == "Up"){
this.game.addEntity(new UpArrow(this.game,entry.x ,entry.y));
}else if(entry.name == "Right"){
this.game.addEntity(new RightArrow(this.game,entry.x ,entry.y));
}else if(entry.name == "Left"){
this.game.addEntity(new LeftArrow(this.game,entry.x ,entry.y));
}
}
for(const entry of level.wheels){
this.game.addEntity(new Wheel(this.game ,entry.name ,entry.x ,entry.y ,entry.r,entry.f));
}
for(const entry of level.pitglow) {
this.game.addEntity(new Pit_Glow(this.game, entry.x, entry.y, entry.xScale, entry.yScale));
console.log("added pitglow", [entry.x, entry.y, entry.size]);
}
for(const entry of level.enemies) {
if(entry.name == "Uoma"){
this.game.addEntity(new Uoma(this.game, entry.x, entry.y));
}
if(entry.name == "Heavy_Sentry"){
this.game.addEntity(new Heavy_Sentry(this.game, entry.x, entry.y));
}
if(entry.name == "Massive_Jelly") {
this.game.addEntity(new Massive_Jelly(this.game, entry.x, entry.y));
}
if(entry.name == "Hive_Knight") {
this.game.addEntity(new Hive_Knight(this.game, entry.x, entry.y));
}
}
for(const entry of level.powerUps) {
if(entry.name == "Charged_Lumafly"){
this.game.addEntity(new Charged_Lumafly(this.game, entry.x, entry.y));
}
if(entry.name == "Gathering_Swarm"){
this.game.addEntity(new Gathering_Swarm(this.game, entry.x, entry.y));
}
if(entry.name == "Lightseed") {
this.game.addEntity(new Lightseed(this.game, entry.x, entry.y));
}
}
this.game.addEntity(this.player);
this.game.addEntity(new HUD());
console.log('Done level: '+level.groundType.name)
};
loadNextLevel(x, y) {
// it wraps for now, but we can change this later if we want.
this.levelNum = (this.levelNum + 1) % this.levels.length;
console.log(["loading level", this.levelNum, this.levels[this.levelNum]]);
this.loadLevel(this.levels[this.levelNum], x, y);
}
update() {
// This code is to ensure that once moving, Hornet maintains center
let midpoint = params.canvasWidth/2;
let vertMidpoint = params.canvasHeight/2;
if( this.player.x < midpoint ){
this.x = 0;
}else{
this.x = this.player.x - midpoint;
}
if(this.worldSize>1){
if(this.player.y < vertMidpoint - this.player.BB.height/2){
this.y = 0;
}else if(this.player.y > params.canvasHeight + vertMidpoint- this.player.BB.height/2 ){
this.y = 768;
}else{
this.y = this.player.y - vertMidpoint+this.player.BB.height/2;
}
}
// spawn some more enemies for troubleshooting/dev purposes.
const nowTime = this.game.timer.gameTime;
if(this.game.keys['c'] && 0.5 > (nowTime - this.marker)) {
this.marker = nowTime;
this.game.addEntity(new Uoma(this.game));
}
};
draw(ctx){
};
};