/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { //GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(background, Vector2.Zero, Color.White); bgScroll.Draw(spriteBatch); if (gameState == GameState.Menu) { spriteBatch.Draw(logo, new Vector2((Width - logo.Width) / 2, 100), Color.White); if (textEnable) { spriteBatch.DrawString(pericles14, "Press Space to continue", new Vector2(280, 300), Color.White); } } bgScroll2.Draw(spriteBatch); if (gameState == GameState.Play) { ship.Draw(spriteBatch); ShotManager.Draw(spriteBatch); AsteroidsManager.Draw(spriteBatch); ExplosionsManager.Draw(spriteBatch); spriteBatch.DrawString(pericles14, $"Score: {score}", new Vector2(10, 10), Color.White); } spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } bgScroll.Update(gameTime); bgScroll2.Update(gameTime); if (gameState == GameState.Menu) { textCounter--; if (textCounter <= 0) { textCounter = MaxRespawnCounter; textEnable = !textEnable; } if (InputHandler.IsKeyPressed(Keys.Space)) { gameState = GameState.Play; } } else if (gameState == GameState.Play) { if (ship.IsDead) { respawnCounter--; if (respawnCounter < 0) { ship.Center = new Vector2(Width / 2, Height / 2); ship.Velocity = Vector2.Zero; ship.IsDead = false; } } else { if (InputHandler.IsKeyDown(Keys.Left)) { ship.Rotation -= 0.05f; } if (InputHandler.IsKeyDown(Keys.Right)) { ship.Rotation += 0.05f; } ship.Thrust = InputHandler.IsKeyDown(Keys.Up); if (InputHandler.IsKeyDown(Keys.LeftControl)) { ShotManager.AddShot(ship.Center + ship.Heading * ship.Radius, ship.Heading * 3); } } ship.Update(gameTime); CollisionDetection(); ShotManager.Update(gameTime); AsteroidsManager.Update(gameTime); ExplosionsManager.Update(gameTime); } base.Update(gameTime); }
public static void Initialize( Texture2D shipTexture, Texture2D shotTexture, Vector2 position, Rectangle initFrame, Vector2 velocity) { shipSprite = new Sprite(shipTexture, position, initFrame, velocity, Color.White); shipSprite.AddFrame(new Rectangle(45, 0, 45, 40)); shotManager = new ShotManager(shotTexture, shotSpeed, 1, 10); }
/// <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); background = Content.Load <Texture2D>(@"Images\nebula_blue.f2014"); bgScroll = new BgScroll(Content.Load <Texture2D>(@"Images\debris2_blue")) { DxOffset = 0.5f }; bgScroll2 = new BgScroll(Content.Load <Texture2D>(@"Images\debris2_blue")) { Flip = true }; ship = new Ship(Content.Load <Texture2D>(@"Images\double_ship"), new Vector2(Width / 2, Height / 2)); ShotManager.Initialize(Content.Load <Texture2D>(@"Images\shot2")); AsteroidsManager.Initialize(Content.Load <Texture2D>(@"Images\asteroid_blue")); AsteroidsManager.AddAsteroids(5); pericles14 = Content.Load <SpriteFont>(@"Fonts\Pericles14"); ExplosionsManager.Initialize(Content.Load <Texture2D>(@"Images\explosion_alpha")); SoundManager.Initialize(Content, Width); logo = Content.Load <Texture2D>(@"Images\asteroids"); }