public void Shoot(GameTime gameTime, Vector2 position) { // Check if we're allowed to fire, do so if (GameHelper.AllowedToFire(_lastFired, _shootTimer, gameTime)) { _lastFired = gameTime.TotalGameTime.TotalMilliseconds; Game game = GameLogic.GetInstance().GetGame(); Projectile projectile = new Projectile(game, _pelletDamage); projectile.SetMovingBehaviour(new StraightLine(projectile, _speed)); projectile.SetPosition(position + _offset); projectile.SetScale(_bulletScale); game.Components.Add(projectile); GameLogic.GetInstance().AddPlayerProjectile(projectile); } }
public override void Update(GameTime gameTime) { if (_random.NextDouble() <= _shootChance) { GameLogic gameLogic = GameLogic.GetInstance(); Game game = gameLogic.GetGame(); Projectile projectile = new Projectile(game, 1.0f); projectile.SetMovingBehaviour(new StraightLine(projectile, _shootVector)); // Tweak the vertical position with one scaled pixel, // It looks better projectile.SetPosition(GetPosition() + _offset - new Vector2(0.0f,gameLogic.GetScale())); projectile.SetScale(gameLogic.GetScale() * 2.0f); game.Components.Add(projectile); gameLogic.AddEnemyProjectile(projectile); } base.Update(gameTime); }
public override void Shoot(GameTime gameTime, Vector2 position) { // Check if we're allowed to fire, do so if (GameHelper.AllowedToFire(_lastFired, _shootTimer, gameTime)) { _lastFired = gameTime.TotalGameTime.TotalMilliseconds; // If last time we fired from the right, // set the offset to the left and vice versa Vector2 offset; if (_sideFiredLast == SideFired.Left) { offset = new Vector2(_offset.X, _offset.Y); _sideFiredLast = SideFired.Right; } else { offset = new Vector2(-_offset.X, _offset.Y); _sideFiredLast = SideFired.Left; } for(int i = 0;i < _pelletNum;i++) { Vector2 totalOffset = offset; Vector2 verticalOffset = new Vector2(0, _scale * _rocketScale); Projectile projectile = new Projectile(GameLogic.GetInstance().GetGame(), _pelletDamage); projectile.SetMovingBehaviour(new StraightLine(projectile, _speed)); for(int k = 0;k < i;k++) { totalOffset += verticalOffset; } projectile.SetPosition(position + totalOffset); projectile.SetScale(_scale * _rocketScale); GameLogic.GetInstance().GetGame().Components.Add(projectile); GameLogic.GetInstance().AddPlayerProjectile(projectile); } } _wpn.Shoot(gameTime, position); }
public override void Shoot(GameTime gameTime, Vector2 position) { // Check if we're allowed to fire, do so if (GameHelper.AllowedToFire(_lastFired, _shootTimer, gameTime)) { _lastFired = gameTime.TotalGameTime.TotalMilliseconds; // If last time we fired from the right, // set the offset to the left and vice versa Vector2 offset; if (_sideFiredLast == SideFired.Left) { offset = new Vector2(_offset.X, _offset.Y); _sideFiredLast = SideFired.Right; } else { offset = new Vector2(-_offset.X, _offset.Y); _sideFiredLast = SideFired.Left; } // Extra Offset for the spacing between elements Vector2 extraOffset = new Vector2(); // Store the previous projectile so we can follow it. // This allows the rest of the missile to stay together if the // enemy dies. Projectile previousProjectile = null; for(int i = 0;i < _pelletNum;i++) { Vector2 totalOffset = offset; Projectile projectile = new Projectile(GameLogic.GetInstance().GetGame(), _pelletDamage); if(previousProjectile == null) { projectile.SetPosition(position + totalOffset); projectile.SetMovingBehaviour(new Follow(projectile, _enemies, _speed)); Vector2 t = projectile.GetMovingBehaviour().GetSpeed(); t.Normalize(); extraOffset = new Vector2(0.0f, -_scale * _missileScale * 1.01f); } else { for (int j = 0; j < i; j++) { totalOffset += extraOffset; } projectile.SetPosition(position + totalOffset); projectile.SetMovingBehaviour(new Follow(projectile, previousProjectile, _enemies, _speed)); } previousProjectile = projectile; projectile.SetScale(_scale * _missileScale); GameLogic.GetInstance().GetGame().Components.Add(projectile); GameLogic.GetInstance().AddPlayerProjectile(projectile); } } _wpn.Shoot(gameTime, position); }