public override Boolean Activate(PlayerVerticalShooter player, GameTime gameTime) { var gameObjectTargets = player.GetTargetsWithinRange(blastRadius); if (gameObjectTargets.Count == 0) { return(false); } foreach (var target in gameObjectTargets) { Vector2 dir = new Vector2(target.PositionX - player.PositionX, target.PositionY - player.PositionY); Vector2 scaledDir = MathFunctions.ScaleDirection(dir); BasicLaser bullet = new BasicLaser(Game, spriteSheet); bullet.PositionX = player.PositionX; bullet.PositionY = player.PositionY; BasicBulletSetup(bullet); bullet.Direction = scaledDir; bullet.Speed = speed; bullet.Damage = damage; Game.stateManager.shooterState.gameObjects.Add(bullet); } return(true); }
//Hanterar "shooting" private void HandleShooting(GameTime gameTime) { lastTimeShot += gameTime.ElapsedGameTime.Milliseconds; if (lastTimeShot >= shootingDelay) { EnemyGreenBullet bullet1 = new EnemyGreenBullet(Game, spriteSheet); EnemyGreenBullet bullet2 = new EnemyGreenBullet(Game, spriteSheet); bullet1.PositionX = PositionX - 10; bullet1.PositionY = PositionY + 16; bullet1.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); bullet1.Initialize(); bullet1.Duration = 500; bullet2.PositionX = PositionX + 10; bullet2.PositionY = PositionY + 16; bullet2.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); bullet2.Initialize(); bullet2.Duration = 500; Game.stateManager.shooterState.gameObjects.Add(bullet1); Game.stateManager.shooterState.gameObjects.Add(bullet2); lastTimeShot -= shootingDelay; Game.soundEffectsManager.PlaySoundEffect(SoundEffects.SmallLaser, soundPan); } }
public override Boolean Activate(PlayerVerticalShooter player, GameTime gameTime) { player.SightRange = 300; GameObjectVertical target = player.FindAimObject(); if (target == null) { return(false); } Vector2 dir = new Vector2(target.PositionX - player.PositionX, target.PositionY - player.PositionY); Vector2 scaledDir = MathFunctions.ScaleDirection(dir); TurretBullet bullet = new TurretBullet(Game, spriteSheet); bullet.PositionX = player.PositionX; bullet.PositionY = player.PositionY; BasicBulletSetup(bullet); bullet.Direction = scaledDir; bullet.Speed = speed; bullet.Damage = damage; Game.stateManager.shooterState.gameObjects.Add(bullet); return(true); }
public static Vector2 ChangeDirection(GameTime gameTime, Vector2 dir, Vector2 pos, Vector2 followedPos, double degreeChange) { double radians = RadiansFromDir(dir); double radianChange = degreeChange * (Math.PI / 180); Vector2 dirToFollowed = new Vector2(followedPos.X - pos.X, followedPos.Y - pos.Y); dirToFollowed = MathFunctions.ScaleDirection(dirToFollowed); double dirFolRadians; if (dirToFollowed.Y > 0) { dirFolRadians = Math.Acos(dirToFollowed.X); } else { dirFolRadians = 2 * Math.PI - (Math.Acos(dirToFollowed.X)); } if (dirFolRadians > 2 * Math.PI) { dirFolRadians -= 2 * Math.PI; } double deltaRadians = MathFunctions.DeltaRadians(radians, dirFolRadians); // If target angle is closer to current than the given delta angle, assign target angle if (Math.Abs(deltaRadians) < Math.Abs(radianChange)) { radians = dirFolRadians; } // If not, increment current angle by given delta angle else { var fpsCompensatedRadianChange = radianChange * MathFunctions.FPSSyncFactor(gameTime); if (deltaRadians > 0 && deltaRadians <= 180) { radians += fpsCompensatedRadianChange; } else if (deltaRadians < 0 && deltaRadians <= 180) { radians -= fpsCompensatedRadianChange; } else if (deltaRadians > 0 && deltaRadians > 180) { radians -= fpsCompensatedRadianChange; } else //(dirFolRadians < Radians && (dirFolRadians - Radians) > 180) { radians += fpsCompensatedRadianChange; } } Vector2 newDir = Vector2.Zero; newDir.X = (float)(Math.Cos(radians)); newDir.Y = (float)(Math.Sin(radians)); return(newDir); }
//Hanterar "shooting" private void HandleShooting(GameTime gameTime) { lastTimeShot += gameTime.ElapsedGameTime.Milliseconds; if (lastTimeShot >= shootingDelay) { lastTimeShot -= shootingDelay; EnemyGreenBullet laser1 = new EnemyGreenBullet(Game, spriteSheet); laser1.PositionX = PositionX - 2; laser1.PositionY = PositionY - 2; laser1.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); laser1.Initialize(); laser1.Duration = 500; laser1.DrawLayer = .5f; EnemyGreenBullet laser2 = new EnemyGreenBullet(Game, spriteSheet); laser2.PositionX = PositionX + 2; laser2.PositionY = PositionY + 2; laser2.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); laser2.Initialize(); laser2.Duration = 500; laser2.DrawLayer = .5f; Game.stateManager.shooterState.gameObjects.Add(laser1); Game.stateManager.shooterState.gameObjects.Add(laser2); shootingDelay2 = 350; Game.soundEffectsManager.PlaySoundEffect(SoundEffects.SmallLaser, soundPan); } if (shootingDelay2 != -1 && lastTimeShot >= shootingDelay2) { lastTimeShot -= shootingDelay2; EnemyGreenBullet laser1 = new EnemyGreenBullet(Game, spriteSheet); laser1.PositionX = PositionX - 2; laser1.PositionY = PositionY - 2; laser1.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); laser1.Initialize(); laser1.Duration = 500; laser1.DrawLayer = .5f; EnemyGreenBullet laser2 = new EnemyGreenBullet(Game, spriteSheet); laser2.PositionX = PositionX + 2; laser2.PositionY = PositionY + 2; laser2.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); laser2.Initialize(); laser2.Duration = 500; laser2.DrawLayer = .5f; Game.stateManager.shooterState.gameObjects.Add(laser1); Game.stateManager.shooterState.gameObjects.Add(laser2); shootingDelay2 = -1; Game.soundEffectsManager.PlaySoundEffect(SoundEffects.SmallLaser, soundPan); } }
private void Homing(GameTime gameTime) { if (FollowObject != null) { Direction = MathFunctions.ChangeDirection(gameTime, Direction, Position, FollowObject.Position, DegreeChange); Direction = MathFunctions.ScaleDirection(Direction); } }
private void SetRotation(Vector2 playerPosition) { Vector2 targetDir = new Vector2(targetCoordinate.X - playerPosition.X, targetCoordinate.Y - playerPosition.Y); Vector2 targetDirScaled = MathFunctions.ScaleDirection(targetDir); double radiansDir = MathFunctions.RadiansFromDir(targetDirScaled); rotation = (float)(radiansDir - Math.PI / 2); }
protected override void ShootingPattern(GameTime gameTime) { EnemyHomingBullet bullet = new EnemyHomingBullet(Game, spriteSheet, player); bullet.Position = Position; bullet.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); bullet.Initialize(); Game.stateManager.shooterState.gameObjects.Add(bullet); }
public override void Update(GameTime gameTime, GameObjectVertical obj) { obj.FindFollowObject(); if (obj.FollowObject != null && obj.DisableFollowObject <= 0) { obj.Direction = MathFunctions.ChangeDirection(gameTime, obj.Direction, obj.Position, obj.FollowObject.Position, obj.TurningSpeed); obj.Direction = MathFunctions.ScaleDirection(obj.Direction); } }
private void UpdateFollowing(GameTime gameTime) { if (TurningSpeed == 0) { TurningSpeed = 1; } Direction = MathFunctions.ChangeDirection(gameTime, Direction, Position, FollowObject.Position, TurningSpeed); Direction = MathFunctions.ScaleDirection(Direction); }
protected override void ShootingPattern(GameTime gameTime) { EnemyStrongBlueLaser bullet = new EnemyStrongBlueLaser(Game, spriteSheet); bullet.Position = Position; bullet.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); bullet.Initialize(); bullet.Speed *= 0.4f; Game.stateManager.shooterState.gameObjects.Add(bullet); }
//public override void Draw(SpriteBatch spriteBatch) //{ // if (!IsKilled) // { // if (lastTimeShot >= ShootingDelay - 1000 && ShootObject != null) // spriteBatch.Draw(shooting.CurrentFrame.Texture, Position, shooting.CurrentFrame.SourceRectangle, Color.White, 0.0f, CenterPoint, 1.0f, SpriteEffects.None, DrawLayer); // else // { // base.Draw(spriteBatch); // } // } //} // //private void UpdateAnimation(GameTime gameTime) //{ // if (lastTimeShot >= ShootingDelay - 1000) // shooting.Update(gameTime); //} protected override void ShootingPattern(GameTime gameTime) { EnemyGreenBullet bullet = new EnemyGreenBullet(Game, spriteSheet); bullet.PositionX = PositionX; bullet.PositionY = PositionY; bullet.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); bullet.Initialize(); bullet.Duration = 1000; Game.stateManager.shooterState.gameObjects.Add(bullet); }
protected override void ShootingPattern(GameTime gameTime) { EnemyWeakBlueLaser laser1 = new EnemyWeakBlueLaser(Game, spriteSheet); laser1.PositionX = PositionX; laser1.PositionY = PositionY; laser1.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); laser1.Initialize(); laser1.Duration *= 1.5f; Game.stateManager.shooterState.gameObjects.Add(laser1); }
public override void Setup(GameObjectVertical obj) { if (leftToRight) { obj.DirectionX = 1f; } else { obj.DirectionX = -1; } obj.DirectionY = 0.2f; obj.Direction = MathFunctions.ScaleDirection(obj.Direction); }
protected override void ShootingPattern(GameTime gameTime) { int activationTimeMilliseconds = 500; EnemyMine mine = new EnemyMine(Game, spriteSheet, player); mine.Initialize(); mine.Position = Position; mine.SetActivationTime(activationTimeMilliseconds); mine.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); mine.Speed = 0.10f; mine.Duration = 1000; Game.stateManager.shooterState.gameObjects.Add(mine); }
protected override void SecondaryShootingPattern(GameTime gameTime) { int numberOfShots = 8; for (int n = 0; n < numberOfShots; n++) { EnemyStrongBlueLaser bullet = new EnemyStrongBlueLaser(Game, spriteSheet); bullet.Position = Position; bullet.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); bullet.Direction = MathFunctions.SpreadDir(bullet.Direction, Math.PI / 16); bullet.Initialize(); bullet.SetSpreadSpeed(random); bullet.Speed *= 0.35f; Game.stateManager.shooterState.gameObjects.Add(bullet); } }
protected override void SecondaryShootingPattern(GameTime gameTime) { int activationTimeMilliseconds = 500; EnemyMine mine = new EnemyMine(Game, spriteSheet, player); mine.Initialize(); mine.SetActivationTime(activationTimeMilliseconds); mine.Position = Position; mine.Direction = MathFunctions.ScaleDirection(ShootObject.Position - Position); mine.Speed = 0.15f; float distance = MathFunctions.ObjectDistance(this, ShootObject); // Shoots at a location close to the players current mine.Duration = distance / mine.Speed * 0.9f; Game.stateManager.shooterState.gameObjects.Add(mine); }
protected override void ShootingPattern(GameTime gameTime) { int nbrOfShots = 12; double spread = Math.PI / 8; Vector2 initDir = MathFunctions.ScaleDirection(ShootObject.Position - Position); for (int n = 0; n < nbrOfShots; n++) { EnemyWeakRedLaser bullet = new EnemyWeakRedLaser(Game, spriteSheet); bullet.PositionX = PositionX; bullet.PositionY = PositionY; bullet.Direction = MathFunctions.SpreadDir(initDir, spread); bullet.Initialize(); bullet.Duration *= 0.8f; bullet.Speed *= 0.8f; bullet.SetSpreadSpeed(random); Game.stateManager.shooterState.gameObjects.Add(bullet); } }
private void UpdateFollowObject(GameTime gameTime) { Direction = MathFunctions.ChangeDirection(gameTime, Direction, Position, player.Position, turningSpeed); Direction = MathFunctions.ScaleDirection(Direction); }
public void SetDirectionAgainstTarget(GameObjectVertical shooter, GameObjectVertical target) { Direction = MathFunctions.ScaleDirection(target.Position - shooter.Position); }
public static void GameObjectsCollision(GameObjectVertical gameObject1, GameObjectVertical gameObject2) { if (MathFunctions.AreObjectsOfTypes <PlayerBullet, EnemyShip>(gameObject1, gameObject2)) { if (gameObject1 is PlayerBullet) { CollideBulletEnemy((PlayerBullet)gameObject1, (EnemyShip)gameObject2); } else { CollideBulletEnemy((PlayerBullet)gameObject2, (EnemyShip)gameObject1); } } else if (MathFunctions.AreObjectsOfTypes <EnemyBullet, AlliedShip>(gameObject1, gameObject2)) { if (gameObject1 is EnemyBullet) { CollideBulletAlly((EnemyBullet)gameObject1, (AlliedShip)gameObject2); } else { CollideBulletAlly((EnemyBullet)gameObject2, (AlliedShip)gameObject1); } } else if (MathFunctions.AreObjectsOfTypes <PlayerVerticalShooter, EnemyShip>(gameObject1, gameObject2)) { if (gameObject1 is PlayerVerticalShooter) { CollidePlayerEnemy((PlayerVerticalShooter)gameObject1, (EnemyShip)gameObject2); } else { CollidePlayerEnemy((PlayerVerticalShooter)gameObject2, (EnemyShip)gameObject1); } } else if (MathFunctions.AreObjectsOfTypes <PlayerVerticalShooter, EnemyBullet>(gameObject1, gameObject2)) { if (gameObject1 is PlayerVerticalShooter) { CollidePlayerBullet((PlayerVerticalShooter)gameObject1, (EnemyBullet)gameObject2); } else { CollidePlayerBullet((PlayerVerticalShooter)gameObject2, (EnemyBullet)gameObject1); } } else if (MathFunctions.AreObjectsOfTypes <EnemyShip, AlliedShip>(gameObject1, gameObject2)) { if (gameObject1 is EnemyShip) { CollideEnemyAlly((EnemyShip)gameObject1, (AlliedShip)gameObject2); } else { CollideEnemyAlly((EnemyShip)gameObject2, (AlliedShip)gameObject1); } } else if (MathFunctions.AreObjectsOfTypes <AreaDamage, PlayerVerticalShooter>(gameObject1, gameObject2)) { if (gameObject1 is AreaDamage) { CollideAreaDamage((AreaDamage)gameObject1, (PlayerVerticalShooter)gameObject2); } else { CollideAreaDamage((AreaDamage)gameObject2, (PlayerVerticalShooter)gameObject1); } } else if (MathFunctions.AreObjectsOfTypes <AreaDamage, AlliedShip>(gameObject1, gameObject2)) { if (gameObject1 is AreaDamage) { CollideAreaDamage((AreaDamage)gameObject1, (AlliedShip)gameObject2); } else { CollideAreaDamage((AreaDamage)gameObject2, (AlliedShip)gameObject1); } } else if (MathFunctions.AreObjectsOfTypes <AreaDamage, EnemyShip>(gameObject1, gameObject2)) { if (gameObject1 is AreaDamage) { CollideAreaDamage((AreaDamage)gameObject1, (EnemyShip)gameObject2); } else { CollideAreaDamage((AreaDamage)gameObject2, (EnemyShip)gameObject1); } } else if (MathFunctions.AreObjectsOfTypes <AreaShieldCollision, PlayerBullet>(gameObject1, gameObject2)) { if (gameObject1 is AreaShieldCollision) { CollideAreaCollision((AreaShieldCollision)gameObject1, (PlayerBullet)gameObject2); } else { CollideAreaCollision((AreaShieldCollision)gameObject2, (PlayerBullet)gameObject1); } } else if (MathFunctions.AreObjectsOfTypes <Bullet, Bullet>(gameObject1, gameObject2)) { CollideBulletBullet((Bullet)gameObject1, (Bullet)gameObject2); } // Neutral - friend/enemy/bullet/enemybullet // Is this ever used? else if ((gameObject1 is AlliedShip || gameObject1 is EnemyShip || gameObject1 is PlayerBullet || gameObject1 is EnemyBullet) && gameObject2.ObjectClass == "neutral") { gameObject1.HP -= gameObject2.Damage; gameObject2.HP -= gameObject1.Damage; gameObject1.Direction = -1 * new Vector2(gameObject2.PositionX - gameObject1.PositionX, gameObject2.PositionY - gameObject1.PositionY); gameObject1.Direction = MathFunctions.ScaleDirection(gameObject1.Direction); gameObject1.DisableFollowObject = 500; if (gameObject1.HP <= 0) { gameObject1.IsKilled = true; } if (gameObject2.HP <= 0) { gameObject2.IsKilled = true; } } else if (gameObject1.ObjectClass == "neutral" && (gameObject2 is AlliedShip || gameObject2 is EnemyShip || gameObject2 is PlayerBullet || gameObject2 is EnemyBullet)) { gameObject1.HP -= gameObject2.Damage; gameObject2.HP -= gameObject1.Damage; gameObject1.Direction *= -1; gameObject2.Direction *= -1; gameObject2.DisableFollowObject = 500; if (gameObject1.HP <= 0) { gameObject1.IsKilled = true; } if (gameObject2.HP <= 0) { gameObject2.IsKilled = true; } } }
public void SetDirectionY(float yFactor) { Vector2 newDir = new Vector2(scaledDirection.X, yFactor); scaledDirection = MathFunctions.ScaleDirection(newDir); }
public void SetDirectionX(float xFactor) { Vector2 newDir = new Vector2(xFactor, scaledDirection.Y); scaledDirection = MathFunctions.ScaleDirection(newDir); }
// Set direction from vector public void SetDirection(Vector2 direction) { scaledDirection = MathFunctions.ScaleDirection(direction); }