1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 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 and background
- game.spawn(new Player(game));
- game.spawn(new Background(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.spawn(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.spawn(powerup);
-
- this.powerupCounter = randInt(WorldGen.range[0], WorldGen.range[1]);
- }
- }
|