public void Initialize(Microsoft.Xna.Framework.Content.ContentManager Content) { //Get content... this.Content = Content; //Get player inputs.. //Check if gamepad is connected... if (GamePad.GetCapabilities(PlayerIndex.One).IsConnected&& GamePad.GetCapabilities(PlayerIndex.Two).IsConnected) { input = new Input[2]; input[0].Initialize(Input.GameType.GAMEPAD, PlayerIndex.One); input[1].Initialize(Input.GameType.GAMEPAD, PlayerIndex.Two); } else if (GamePad.GetCapabilities(PlayerIndex.One).IsConnected) { input = new Input[1]; input[0].Initialize(Input.GameType.GAMEPAD, PlayerIndex.One); } else { input = new Input[1]; input[0].Initialize(Input.GameType.KEYBOARD, PlayerIndex.One); } player = new AirmanPlayer[input.Length]; //As many players as inputs gameState = Levels.MAIN_MENU; prevGameState = Levels.MAIN_MENU; collisionTexture = Content.Load <Texture2D>("Entities/collisionSprite"); logo = Content.Load <Texture2D>("AirmanLogo"); backgroundSong = Content.Load <Song>("Sounds/Music/Mercury"); explodeEffect = Content.Load <SoundEffect>("Sounds/SFX/explosion3"); hitSound = Content.Load <SoundEffect>("Sounds/SFX/Hit_03"); //explodeEffect. //Background... Background2D.Initialize(); InitializeLevel(); }
public void DrawLevel(SpriteBatch batch) { switch (gameState) { case Levels.MAIN_MENU: Background2D.DrawParallaxing(batch); for (int i = 0; i < player.Length; i++) { player[i].Draw(batch); } /*drawPrompt(batch, "AIRMAN ! ! !", * new Vector2(GameInformation.screenWidth / 2 - 80, 10), * Color.DarkSalmon); * drawPrompt(batch, "Press any Space or Start...", * new Vector2(GameInformation.screenWidth / 4 + 80, GameInformation.screenHeight / 2), Color.Red);*/ batch.Draw(logo, new Vector2((GameInformation.screenWidth / 2) - (logo.Width / 2), 0), Color.White); //testingDraw(batch); break; case Levels.MAIN_SPLASH: Background2D.DrawParallaxing(batch); for (int i = 0; i < player.Length; i++) { player[i].DrawSource(batch); } break; case Levels.LEVEL_ONE: Background2D.DrawParallaxing(batch); for (int i = 0; i < player.Length; i++) { player[i].DrawWithProjectiles(batch); input[i].DrawTesting(batch); } drawEnemies(batch); //Draw enemies //input.DrawTesting(batch); //testingDraw(batch); break; case Levels.DYING_SPLASH: Background2D.DrawParallaxing(batch); batch.Draw(collisionTexture, new Rectangle(0, 0, GameInformation.screenWidth, GameInformation.screenHeight), deathColor); for (int i = 0; i < player.Length; i++) { player[i].DrawWithProjectiles(batch); } drawPrompt(batch, "THANK YOU FOR PLAYING!", GameInformation.screenHeight + 80, Color.HotPink); drawPrompt(batch, "Press fire key to play again", GameInformation.screenHeight - 120, Color.HotPink); drawPrompt(batch, "Press any key to quit", GameInformation.screenHeight - 80, Color.HotPink); drawPrompt(batch, "Score" + score, GameInformation.screenHeight / 2, Color.HotPink); break; case Levels.TESTING: Background2D.DrawParallaxing(batch); for (int i = 0; i < player.Length; i++) { player[i].DrawWithProjectiles(batch); } testingDraw(batch); break; } }
public void UpdateLevel(float deltaTime) { switch (gameState) { case Levels.MAIN_MENU: Background2D.UpdateParallaxing(deltaTime, 0.02f); KeyboardState ks = Keyboard.GetState(); GamePadState gs = GamePad.GetState(PlayerIndex.One); if (gs.IsButtonDown(Buttons.Start) || ks.IsKeyDown(Keys.Space)) { ChangeGameState(Levels.MAIN_SPLASH); } break; case Levels.MAIN_SPLASH: Background2D.UpdateParallaxing(deltaTime, 0.1f); if (prevGameState != Levels.MAIN_SPLASH) { for (int i = 0; i < player.Length; i++) { player[i].Activate(new Vector2(0, (GameInformation.screenHeight / 2) + (40 * i))); player[i].ChangeMoveSpeed(0.2f); if (player[i].DrawRectangle.X < GameInformation.screenWidth / 4) { player[i].updateSplash(deltaTime, Levels.MAIN_SPLASH); } else { ChangeGameState(Levels.LEVEL_ONE); } } } break; case Levels.LEVEL_ONE: if (timeForTermination() == false) { generateEnemies(75); //Enemies generated after 25 reached Rectangle[] playerRects = new Rectangle[player.Length]; for (int i = 0; i < player.Length; i++) { input[i].Update(deltaTime); player[i].Update(deltaTime, input[i].angle, input[i].firePressed); playerRects[i] = player[i].DrawRectangle; } for (int i = 0; i < enemies.Length; i++) { if (enemies[i].IsActive()) { enemies[i].enemyUpdate(deltaTime, new Vector2(-1, 0), playerRects, Lists.projectiles); } } Background2D.UpdateParallaxing(deltaTime, 0.2f); } else { ChangeGameState(Levels.DYING_SPLASH); } break; case Levels.DYING_SPLASH: if (Keyboard.GetState().GetPressedKeys().Length > 0 || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back)) { Game1.endGame = true; } if (Keyboard.GetState().IsKeyDown(Keys.Space) || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start)) { Game1.restartGame = true; ChangeGameState(Levels.MAIN_MENU); } for (int i = 0; i < player.Length; i++) { player[i].Update(deltaTime, Vector2.Zero, false); } break; case Levels.TESTING: for (int i = 0; i < player.Length; i++) { input[i].Update(deltaTime); player[i].Update(deltaTime, input[i].angle, input[i].firePressed); } Background2D.UpdateParallaxing(deltaTime, 0.5f); break; default: //All cases do not need an initialization stage break; } }
public void InitializeLevel() { Texture2D tex; switch (gameState) { case Levels.MAIN_MENU: //Parallax Background... Background2D.parallaxLayers.Add(Content.Load <Texture2D>("Backgrounds/parallax-Layer1")); Background2D.parallaxLayers.Add(Content.Load <Texture2D>("Backgrounds/parallax-Layer2")); Background2D.parallaxLayers.Add(Content.Load <Texture2D>("Backgrounds/parallax-Layer3")); Background2D.parallaxLayers.Add(Content.Load <Texture2D>("Backgrounds/parallax-Layer4")); Background2D.parallaxLayers.Add(Content.Load <Texture2D>("Backgrounds/parallax-Layer5")); Background2D.InitializeParallax(); //Player Texture... tex = Content.Load <Texture2D>("Entities/helicopterSpritesheet"); //We need player... InitializePlayer(tex); break; case Levels.MAIN_SPLASH: //Start playing song... MediaPlayer.Play(backgroundSong); MediaPlayer.IsRepeating = true; //Play the song on a loop... break; case Levels.LEVEL_ONE: //Loading resources needed... tex = Content.Load <Texture2D>("Entities/helicopterSpritesheet"); Texture2D explodeTexture = Content.Load <Texture2D>("ExplosionSprite"); int explTotalFrames = 16, explRows = 4, explCols = 4, explWidth = 96, explHeight = 96; int explFrameRate = 33; enemies = new Enemy[8]; for (int i = 0; i < enemies.Length; i++) { int width = GameInformation.screenWidth / 5; enemies[i] = new Enemy(); enemies[i].Initialize(tex, new Vector2(GameInformation.screenWidth, 0), width, width / 3, 100); enemies[i].InitializeHealth(); enemies[i].InitializeAnimation(8, 33, 2, 4); enemies[i].InitializeExplosion(explodeTexture, explWidth, explHeight); enemies[i].InitializeExplosionAnimation(explTotalFrames, explFrameRate, explRows, explCols); enemies[i].ChangeMoveSpeed(2f); //enemies[i].DeActivate(); } for (int i = 0; i < player.Length; i++) { player[i].ChangeMoveSpeed(1f); //player[i].InitializeCrosshairs(); } break; case Levels.DYING_SPLASH: MediaPlayer.Stop(); break; case Levels.TESTING: break; default: break; } }