12345678910111213141516171819202122232425262728293031323334353637383940 |
- function WorldGen(game) {
- this.game = game;
- this.prevX = 0;
-
- this.minY = -400;
- this.maxY = 400;
- this.powerupCounter = randInt(WorldGen.range[0], WorldGen.range[1]);
-
- // Spawn player
- game.entities.push(new Player(game));
- }
- WorldGen.range = [5, 12];
-
- WorldGen.prototype.update = function() {
- while (this.game.camera.x + this.game.canvas.width > this.prevX)
- this.genNext();
- }
- WorldGen.prototype.genNext = function() {
- var x = this.prevX + 300;
- var y = Math.round((Math.random() - 0.5) * 300);
-
- if (y < this.minY) y = this.minY;
- if (y > this.maxY) y = this.maxY;
-
- var obstacle = new Obstacle(this.game, x, y);
- this.game.entities.push(obstacle);
-
- this.prevX = x;
-
- if (--this.powerupCounter === 0) {
- var powerup = new PowerUp(
- this.game,
- x - 50,
- y + 80 + (this.game.canvas.height / 2));
-
- this.game.entities.push(powerup);
-
- this.powerupCounter = randInt(WorldGen.range[0], WorldGen.range[1]);
- }
- }
|