public Fly(Game1 game, float startAngle, Terrain terrain) : base(game) { this.game = game; this.terrain = terrain; this.position = new Vector2(); Random r = new Random(); scale = 0.5f; //position.X = r.Next(game.screenWidth); position.Y = game.screenHeight * 0.5f; positionAngle = startAngle; texture = game.Content.Load<Texture2D>(@"ObjectsAnimations/Fly/fl_0"); origin.X = texture.Width * 2 * scale; origin.Y = terrain.position.Y - 100; boxCollider = new Rectangle(0, 0, (int)(texture.Bounds.Width * scale), (int)(texture.Bounds.Height * scale)); Initialize(); }
public Terrain generateRandomTerrain(float angle, Random rand) { Terrain lastTerrain = this.terrains[terrains.Count - 1]; bool fly = false; int flyChance = rand.Next(0, 4); if (flyChance == 0) { fly = true; } double terrainHeight = lowestH; int terNum = rand.Next(0, 4); if (terNum == 1) { terrainHeight = secondH; } if (terNum == 2 && lastTerrain.tHeight != lowestH) { terrainHeight = thirdH; } if (terNum == 3 && lastTerrain.tHeight != lowestH && lastTerrain.tHeight != secondH) { terrainHeight = topH; } Terrain[] allTerrains = new Terrain[7]; allTerrains[0] = new PlainTerrain(game, angle, terrainHeight, fly); allTerrains[1] = new AscentTerrain(game, angle, terrainHeight, fly); allTerrains[2] = new LavaPitTerrain(game, angle, terrainHeight, fly); allTerrains[3] = new LavaPitWideTerrain(game, angle, terrainHeight, fly); allTerrains[4] = new LoweredTerrain(game, angle, terrainHeight, fly); allTerrains[5] = new DescentTerrain(game, angle, terrainHeight, fly); // volcanos get too high.. double volcanoHeight = lastTerrain.tHeight == topH || lastTerrain.tHeight == thirdH ? secondH : lastTerrain.tHeight; //Console.WriteLine("volcano height " + volcanoHeight); allTerrains[6] = new VolcanoTerrain(game, angle, volcanoHeight, fly); Terrain nextTerrain = allTerrains[rand.Next(0, 7)]; if (lastTerrain is AscentTerrain) { if (lastTerrain.tHeight == lowestH) { nextTerrain.tHeight = lowestH; } if (lastTerrain.tHeight == secondH) { nextTerrain.tHeight = secondH; } if (lastTerrain.tHeight == thirdH) { nextTerrain.tHeight = thirdH; } if (nextTerrain is AscentTerrain) { nextTerrain = generateRandomTerrain(angle, rand); } } if (lastTerrain is DescentTerrain) { if (lastTerrain.tHeight == lowestH) { nextTerrain.tHeight = lowestH; } if (lastTerrain.tHeight == secondH) { nextTerrain.tHeight = secondH; } if (lastTerrain.tHeight == thirdH) { nextTerrain.tHeight = thirdH; } if (nextTerrain is DescentTerrain) { nextTerrain = generateRandomTerrain(angle, rand); } } return nextTerrain; }