示例#1
0
        public void FireProjectile(Weapon weapon, Ship source, Ship target, float damage, Vector2 positionOffset)
        {
            var newProjectile = Projectiles.New();

            newProjectile.SetType(weapon.ProjectileType, source);
            newProjectile.TargetType         = target.TargetType;
            newProjectile.Damage             = damage;
            newProjectile.Position           = source.Position + positionOffset + new Vector2(WorldData.RNG.Next(-25, 25), WorldData.RNG.Next(-25, 25));
            newProjectile.IsPlayerProjectile = source.IsPlayerShip;
            newProjectile.CenterOrigin();

            newProjectile.TargetRotation = AIHelper.GetAngleToTarget(newProjectile.Position, source.Rotation, target.Position);

            if (newProjectile.TurnSpeed == 0)
            {
                // todo : lead target for non missiles
                newProjectile.Rotation = newProjectile.TargetRotation;
            }
            else
            {
                newProjectile.Rotation       = source.Rotation;
                newProjectile.Target         = target;
                newProjectile.TargetRotation = AIHelper.GetAngleToTarget(newProjectile.Position, newProjectile.Rotation, newProjectile.Target.Position);
            }

            if (newProjectile.TurnSpeed == 0)
            {
                var camPos       = GameplayState.Camera.GetPosition() + GameplayState.Camera.GetOrigin();
                var viewDistance = GameplayState.Graphics.PresentationParameters.BackBufferWidth / GameplayState.Camera.Zoom;

                var distance = Vector2.Distance(newProjectile.Position, camPos);

                if (distance < viewDistance)
                {
                    ModManager.Instance.SoundManager.PlaySound("SFXLaser", (int)SoundType.SoundEffect, false, true, 0.5f);
                }
            }
        }
示例#2
0
 public float GetAngleToTarget(Vector2 target)
 {
     return(AIHelper.GetAngleToTarget(Position, Rotation, target));
 }
示例#3
0
        public void Update(GameTime gameTime)
        {
            for (var i = 0; i <= Projectiles.LastActiveIndex; i++)
            {
                var projectile = Projectiles[i];

                projectile.Lifetime -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (projectile.Lifetime <= 0)
                {
                    DeadProjectiles.Add(projectile);
                    continue;
                }
            }

            for (var i = 0; i < DeadProjectiles.Count; i++)
            {
                var projectile = DeadProjectiles[i];

                if (projectile.DeathType == ProjectileDeathType.Explosion)
                {
                    GameplayState.EffectsManager.AddExplosion(projectile);

                    var camPos       = GameplayState.Camera.GetPosition() + GameplayState.Camera.GetOrigin();
                    var viewDistance = GameplayState.Graphics.PresentationParameters.BackBufferWidth / GameplayState.Camera.Zoom;

                    var distance = Vector2.Distance(projectile.Position, camPos);

                    if (distance < viewDistance)
                    {
                        ModManager.Instance.SoundManager.PlaySound("SFXImpact", (int)SoundType.SoundEffect, false, true);
                    }
                }

                Projectiles.Delete(projectile);
            }

            DeadProjectiles.Clear();

            for (var i = 0; i <= Projectiles.LastActiveIndex; i++)
            {
                var projectile = Projectiles[i];

                if (projectile.Target != null && projectile.TurnSpeed > 0)
                {
                    projectile.TargetRotation = AIHelper.GetAngleToTarget(projectile.Position, projectile.Rotation, projectile.Target.Position);
                }

                projectile.ApplyMovement(gameTime);

                var checkList = GameplayState.WorldManager.PlayerShips;
                if (projectile.IsPlayerProjectile)
                {
                    checkList = GameplayState.WorldManager.EnemyShips;
                }

                bool collision = false;

                // todo : raycasting for better collisions
                for (var s = 0; s < checkList.Count && !collision; s++)
                {
                    var target = checkList[s];

                    if (target.TargetType != projectile.TargetType)
                    {
                        continue;
                    }

                    if (target.IsShieldActive)
                    {
                        collision = Vector2.Distance(projectile.Position, target.Position) <= target.ShieldRadius;
                    }
                    else
                    {
                        collision = Vector2.Distance(projectile.Position, target.Position) <= (target.ShieldRadius * 0.8f);
                    }

                    if (collision)
                    {
                        target.TakeDamage(projectile.Damage);
                        DeadProjectiles.Add(projectile);
                        DeadProjectileAnchors.Add(target);
                    }
                }
            }

            for (var i = 0; i < DeadProjectiles.Count; i++)
            {
                var projectile = DeadProjectiles[i];
                var anchor     = DeadProjectileAnchors[i];

                if (projectile.DeathType == ProjectileDeathType.Explosion)
                {
                    GameplayState.EffectsManager.AddExplosion(projectile, anchor, 4.0f);

                    var camPos       = GameplayState.Camera.GetPosition() + GameplayState.Camera.GetOrigin();
                    var viewDistance = GameplayState.Graphics.PresentationParameters.BackBufferWidth / GameplayState.Camera.Zoom;

                    var distance = Vector2.Distance(projectile.Position, camPos);

                    if (distance < viewDistance)
                    {
                        ModManager.Instance.SoundManager.PlaySound("SFXImpact", (int)SoundType.SoundEffect, false, true);
                    }
                }
                else
                {
                    GameplayState.EffectsManager.AddExplosion(projectile, Color.Cyan, anchor, 1.5f, 800.0f);
                }

                Projectiles.Delete(projectile);
            }

            DeadProjectiles.Clear();
            DeadProjectileAnchors.Clear();
        }