Game
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

worldgen.js 916B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. function WorldGen(game) {
  2. this.game = game;
  3. this.prevX = 0;
  4. this.minY = -400;
  5. this.maxY = 400;
  6. this.powerupCounter = randInt(WorldGen.range[0], WorldGen.range[1]);
  7. // Spawn player
  8. game.spawn(new Player(game));
  9. }
  10. WorldGen.range = [5, 12];
  11. WorldGen.prototype.update = function() {
  12. while (this.game.camera.x + this.game.canvas.width > this.prevX)
  13. this.genNext();
  14. }
  15. WorldGen.prototype.genNext = function() {
  16. var x = this.prevX + 300;
  17. var y = Math.round((Math.random() - 0.5) * 300);
  18. if (y < this.minY) y = this.minY;
  19. if (y > this.maxY) y = this.maxY;
  20. var obstacle = new Obstacle(this.game, x, y);
  21. this.game.entities.push(obstacle);
  22. this.prevX = x;
  23. if (--this.powerupCounter === 0) {
  24. var powerup = new PowerUp(
  25. this.game,
  26. x - 50,
  27. y + 80 + (this.game.canvas.height / 2));
  28. this.game.entities.push(powerup);
  29. this.powerupCounter = randInt(WorldGen.range[0], WorldGen.range[1]);
  30. }
  31. }