private static void fireShotsGamePad(GamePadState padState, float elapsed) { if (padState.ThumbSticks.Right != Vector2.Zero) { if (shotTimer >= minShotTimer) { Vector2 angle = padState.ThumbSticks.Right - shipSprite.Position; if (angle != Vector2.Zero) { angle.Normalize(); } shotManager.FireShot(shipSprite.Center, angle, shipSprite.Rotation); SoundEffectManager.GetSound("shipLaser").Play(0.5f, 0f, 0f); shotTimer = 0f; } } shotTimer += elapsed; }
private static void fireShotsMouse(MouseState mouseState, float elapsed) { ButtonState button = (AsteroidsGame.ControlStyle == ControlStyles.KBM_LH) ? mouseState.RightButton : mouseState.LeftButton; if (button == ButtonState.Pressed) { if (shotTimer >= minShotTimer) { Vector2 angle = mouseState.Position.ToVector2() - shipSprite.Position; if (angle != Vector2.Zero) { angle.Normalize(); } shotManager.FireShot(shipSprite.Center, angle, shipSprite.Rotation); SoundEffectManager.GetSound("shipLaser").Play(0.5f, 0f, 0f); shotTimer = 0.0f; } } shotTimer += elapsed; }
/// <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 = this.Content.Load <Texture2D>("Backgrounds/space2"); shipSpriteSheet = this.Content.Load <Texture2D>("Sprites/ship"); shotSprite = this.Content.Load <Texture2D>("Sprites/lasers"); FontManager.LoadFonts(this.Content); SoundEffectManager.LoadSounds(this.Content); MusicManager.LoadMusic(this.Content); Player.Initialize( shipSpriteSheet, shotSprite, new Vector2( (this.Window.ClientBounds.Width / 2) - 22.5f, (this.Window.ClientBounds.Height / 2) - 20f), new Rectangle(0, 0, 45, 40), Vector2.Zero); enemy = new EnemyShip(shipSpriteSheet, Vector2.Zero, new Rectangle(0, 0, 45, 40)); }