public override void Update(UpdateEventArgs e) { this.asteroidChance = Math.Min(asteroidChanceMax, this.asteroidChance + (float)e.ElapsedTimeInS * asteroidChanceIncrease); if (this.environment.Offset > firePlanetChanceThreshold) { this.fireplanetChance = GameMath.Clamp(firePlanetChanceInitial, firePlanetChanceMax, this.fireplanetChance + (float)e.ElapsedTimeInS * firePlanetChanceIncrease); } if (this.environment.Offset > repellingPlanetChanceThreshold) { this.repellingPlanetChance = GameMath.Clamp(repellingPlanetChanceInitial, repellingPlanetChanceMax, this.repellingPlanetChance + (float)e.ElapsedTimeInS * repellingPlanetChanceIncrease); } // Check for planets out of the screen while (!this.planets.First.Value.IsOnScreen()) { this.environment.RemoveWorldObject(this.planets.First.Value.ID); if (this.planets.First.Value is FirePlanet) { this.fireplanetCount--; } if (this.planets.First.Value is RepellingPlanet) { this.repellingPlanetCount--; } this.environment.Planets.RemoveFirst(); } // Check if spacecore is still visible if (this.spacecore != null && this.spacecore.Position.X + 645 + LevelGenerator.SideBuffer < this.environment.Offset) { this.environment.RemoveWorldObject("spacecore"); this.spacecore = null; } // Always have at least a certain amount of planets on the playfield if (this.planets.Count < minPlanets) { this.generatePlanet(); } if (GlobalRandom.NextDouble() < this.asteroidChance) { this.generateAsteroid(); } if (GlobalRandom.NextDouble() < spacecoreChance && this.spacecore == null) { this.generateSpacecore(); } }
private void generateSpacecore() { // y-coordinate float y = 0; do { y = (float)GlobalRandom.NextDouble(-345, 345); } while (!this.checkPosition(y, 15)); this.spacecore = new Spacecore(this.environment, new Vector2(655 + SideBuffer + this.environment.Offset, y)); this.environment.AddWorldObject("spacecore", this.spacecore); }