public void RestartGame(int pScore) { foreach (Wall wall in level.UpperWalls) { collisionResolver.Remove(wall); }//remove walls and columns from resolver foreach (Wall wall in level.LowerWalls) { collisionResolver.Remove(wall); }//remove walls and columns from resolver foreach (Column column in level.Columns) { List<Wall> columnComponents = column.ColumnComponents; foreach (Wall wall in columnComponents) { collisionResolver.Remove(wall); } } level = null; level = new Level(wallSprite,columnSprite); level.GenerateWorldBounds(worldLowerBound, worldUpperBound, 80);//generate the worlds lower and upper walls which the pipes are attached to level.GenerateColumns(columnSeperation, player.Dimensions, 3, firstColumnStartPosition); foreach (Wall wall in level.UpperWalls) { collisionResolver.Add(wall); } foreach (Wall wall in level.LowerWalls) { collisionResolver.Add(wall); } foreach (Column column in level.Columns) { List<Wall> columnComponents = column.ColumnComponents; foreach (Wall wall in columnComponents) { collisionResolver.Add(wall); } } player.IsDead = false; player.SpeedBoosts = 3; player.MaxXSpeed = 10; if (playerHiScore.GetNumber() < pScore) playerHiScore.SetNumber(pScore); player.Score = 0; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); audioPlayer = new AudioPlayer(); background = new Background(Content.Load<Texture2D>("BGTile.png"), new Vector2(worldBounds.Width, worldBounds.Height),new Vector2(0,0)); Texture2D playerNormalSprite = Content.Load<Texture2D>("PLAYER.png"); Texture2D playerUpSprite = Content.Load<Texture2D>("PLAYER_UP.png"); Texture2D playerDownSprite = Content.Load<Texture2D>("PLAYER_DOWN.png"); spBoostSprite = Content.Load<Texture2D>("SPEEDBOOSTS.png"); wallSprite = Content.Load<Texture2D>("WALL2.png"); columnSprite = Content.Load<Texture2D>("LASER.png"); fontTexture = Content.Load<Texture2D>("Font.png"); font = Content.Load<SpriteFont>("HellaFont"); worldLowerBound = 650; worldUpperBound = 50; columnSeperation = 500; firstColumnStartPosition = 1000; player = new Player(playerNormalSprite,playerUpSprite,playerDownSprite, new Vector2(0, 360), new Vector2(1, 0.4f), new Vector2(10, 10), columnSeperation, 3); level = new Level(wallSprite,columnSprite); level.GenerateWorldBounds(worldLowerBound, worldUpperBound, 80);//generate the worlds lower and upper walls which the pipes are attached to level.GenerateColumns(columnSeperation, player.Dimensions, 3, firstColumnStartPosition); playerScore = new UI(font, new Vector2(30, 60), 0, "Score: ", true); playerHiScore = new UI(font, new Vector2(600, 60), 0, "Hi Score: ", true); collisionResolver = new CollisionResolver(); collisionResolver.Add(player); foreach (Wall wall in level.UpperWalls) { collisionResolver.Add(wall); } foreach (Wall wall in level.LowerWalls) { collisionResolver.Add(wall); } foreach (Column column in level.Columns) { List<Wall> columnComponents = column.ColumnComponents; foreach (Wall wall in columnComponents) { collisionResolver.Add(wall); } } }