/// <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) { KeyboardState keyboardState = Keyboard.GetState(); MouseState mouseState = Mouse.GetState(); switch (Stat) { case Stat.SplashScreen: SplashScreen.Update(); if (keyboardState.IsKeyDown(Keys.Space)) { Stat = Stat.Game; } break; case Stat.Game: Asteroids.Update(); float time = (float)gameTime.TotalGameTime.TotalMilliseconds / 10; if (mouseState.LeftButton == ButtonState.Pressed && time > Asteroids.playerReload) { Asteroids.CreateBullet(); Asteroids.playerReload = time + 15; } if (keyboardState.IsKeyDown(Keys.M)) { Stat = Stat.SplashScreen; } if (keyboardState.IsKeyDown(Keys.W)) { Asteroids.Player.Up(); } if (keyboardState.IsKeyDown(Keys.S)) { Asteroids.Player.Down(); } if (keyboardState.IsKeyDown(Keys.D)) { Asteroids.Player.Right(); } if (keyboardState.IsKeyDown(Keys.A)) { Asteroids.Player.Left(); } break; } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // TODO: Add your update logic here base.Update(gameTime); }
/// <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); SplashScreen.Background = Content.Load <Texture2D>("background"); SplashScreen.Font = Content.Load <SpriteFont>("SplashFont"); Asteroids.Init(spriteBatch, 800, 480); Star.Texture2D = Content.Load <Texture2D>("Star"); Player.Texture2D = Content.Load <Texture2D>("Player"); Target.Texture2D = Content.Load <Texture2D>("Target"); Enemy.Texture2D = Content.Load <Texture2D>("Enemy"); Bullet.Texture2D = Content.Load <Texture2D>("Bullet"); Bullet.EnemyTexture2D = Content.Load <Texture2D>("EnemyBullet"); Asteroids.healthTexture = Content.Load <Texture2D>("Health"); // TODO: use this.Content to load your game content here }
/// <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.Black); spriteBatch.Begin(); switch (Stat) { case Stat.SplashScreen: SplashScreen.Draw(spriteBatch); break; case Stat.Game: Asteroids.Draw(); break; } spriteBatch.End(); // TODO: Add your drawing code here base.Draw(gameTime); }
public void Update() { phase += 0.04f; if (this.hiddenTimer > 0) { this.hiddenTimer--; } else if (alphaBlending < 1) { this.alphaBlending += 0.02f; } if (this.hiddenTimer <= 0) { // shooting if (shootingTime > 0) { shootingTime--; } else { Asteroids.CreateEnemyBullet(); shootingTime = shootingTimer; } // rotation if (isSegmentized && length < maxLength) { length += 2; } double targetAngle = Math.Atan2(Asteroids.Player.Pos.Y - Pos.Y, Asteroids.Player.Pos.X - Pos.X) * 180.0 / Math.PI; if (currentAngle > 180) { currentAngle = -180; } if (currentAngle < -180) { currentAngle = 180; } if (Math.Abs(currentAngle - targetAngle) > 5) { if (Math.Abs(currentAngle - targetAngle) < 180) { // Rotate current directly towards target. if (currentAngle < targetAngle) { currentAngle += angleRotationSpeed; } else { currentAngle -= angleRotationSpeed; } } else { // Rotate the other direction towards target. if (currentAngle < targetAngle) { currentAngle -= angleRotationSpeed; } else { currentAngle += angleRotationSpeed; } } } } }
public double getAngle(int randomize = 32) { return(((currentAngle + Asteroids.getRandInt(-randomize, randomize)) / 180 * Math.PI) + coefRadius * Math.Sin(phase)); }
public void RandomSet() { Pos = new Vector2(Asteroids.getRandInt(Asteroids.Width, Asteroids.Width + 300), Asteroids.getRandInt(0, Asteroids.Height)); // color = Color.FromNonPremultiplied(Asteroids.getRandInt(0, 256), Asteroids.getRandInt(0, 256), Asteroids.getRandInt(0, 256), 255); }