예제 #1
0
        public GameObjectVertical FindAimObject()
        {
            if (ShootObject == null)
            {
                var targetsWithinRange = GetTargetsWithinRange(SightRange);

                if (targetsWithinRange.Count > 0)
                {
                    shootObject = targetsWithinRange[0];
                    foreach (GameObjectVertical obj in targetsWithinRange)
                    {
                        if (MathFunctions.ObjectDistance(this, obj) < MathFunctions.ObjectDistance(this, shootObject))
                        {
                            shootObject = obj;
                        }
                    }
                }
            }
            else
            {
                if (!CollisionDetection.IsPointInsideCircle(ShootObject.Position, Position, SightRange))
                {
                    ShootObject = null;
                }
            }
            return(ShootObject);
        }
예제 #2
0
        private void CheckCollision(int objectCount)
        {
            for (int n = 0; n < objectCount; n++)
            {
                for (int m = n + 1; m < objectCount; m++)
                {
                    GameObjectVertical obj1 = gameObjects[n];
                    GameObjectVertical obj2 = gameObjects[m];

                    if (MathFunctions.IsOneOfType <AreaDamage>(obj1, obj2))
                    {
                        PerformAreaDamage(obj1, obj2);
                    }
                    else if (MathFunctions.IsOneOfType <AreaShieldCollision>(obj1.AreaCollision, obj2.AreaCollision) &&
                             MathFunctions.IsOneOfType <PlayerBullet>(obj1, obj2))
                    {
                        PerformShieldAreaCollision(obj1, obj2);
                    }

                    if (obj1.CollisionBounding.Intersects(obj2.CollisionBounding))
                    {
                        CollisionHandlingVerticalShooter.GameObjectsCollision(obj1, obj2);
                    }
                }
            }
        }
예제 #3
0
        public GameObjectVertical FindFollowObject()
        {
            if (FollowObject == null)
            {
                List <GameObjectVertical> objectList = Game.stateManager.shooterState.gameObjects;

                foreach (String type in FollowObjectTypes)
                {
                    foreach (GameObjectVertical obj in objectList)
                    {
                        if (obj.ObjectClass.Equals(type))
                        {
                            if (CollisionDetection.IsPointInsideCircle(obj.Position, Position, SightRange))
                            {
                                followObject = obj;
                            }
                        }
                    }
                }
            }
            else
            {
                if (!CollisionDetection.IsPointInsideCircle(FollowObject.Position, Position, SightRange))
                {
                    FollowObject = null;
                }
            }
            return(null);
        }
예제 #4
0
        //------------------------

        /**
         * The functions LocateTarget, FindTargetsWithSameX and CheckYRelation checks if there is a
         * suitable target present. A suitable target has the same x-position as the shooting object, and a y-position
         * that either is higher or lower depending on the variable "targetingUpwards"
         */
        private GameObjectVertical LocateTarget(Vector2 shooterPos)
        {
            GameObjectVertical        newTarget = null;
            List <GameObjectVertical> sameXList = FindTargetsWithSameX(shooterPos);

            if (sameXList.Count > 0)
            {
                newTarget = sameXList[0];
                foreach (GameObjectVertical obj in sameXList)
                {
                    if (shooterPos.Y - obj.PositionY < shooterPos.Y - newTarget.PositionY)
                    {
                        newTarget = obj;
                    }
                }
            }

            if (newTarget != null)
            {
                return(newTarget);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        private void ClearDeadObjects(int objectCount)
        {
            for (int n = 0; n < objectCount; n++)
            {
                GameObjectVertical obj1 = gameObjects[n];

                if (obj1.IsKilled || obj1.IsOutside)
                {
                    deadGameObjects.Add(obj1);

                    if (obj1.IsKilled && obj1 is EnemyShip)
                    {
                        currentLevel.LevelLoot += ((EnemyShip)obj1).GetLoot();
                        currentLevel.enemiesKilled++;

                        if (obj1.LastHitBy == Tracker.Player &&
                            !(obj1 is Meteorite))
                        {
                            currentLevel.enemiesKilledByPlayer++;
                        }
                    }

                    if ((obj1.IsOutside && obj1 is EnemyShip))
                    {
                        currentLevel.enemiesLetThrough++;
                    }
                }
            }

            for (int n = 0; n < deadGameObjects.Count; n++)
            {
                gameObjects.Remove(deadGameObjects[n]);
            }
            deadGameObjects.Clear();
        }
예제 #6
0
        private void InflictDamage(GameObjectVertical obj)
        {
            BeamBullet beamBullet = new BeamBullet(game, spriteSheet);

            beamBullet.Damage = damage;
            ((CombatGameObject)obj).InflictDamage(beamBullet);
        }
예제 #7
0
        public override void Update(GameTime gameTime, GameObjectVertical obj)
        {
            if (!endReached)
            {
                if (obj.PositionY > 50)
                {
                    if (isLeft)
                    {
                        obj.DirectionX = 1f;
                    }
                    else
                    {
                        obj.DirectionX = -1f;
                    }
                }
            }

            if (isLeft && obj.PositionX > endX)
            {
                endReached     = true;
                obj.DirectionX = 0;
            }
            else if (!isLeft && obj.PositionX < endX)
            {
                endReached     = true;
                obj.DirectionX = 0;
            }
        }
예제 #8
0
        private void ApplyDamage(GameObjectVertical obj)
        {
            float damage       = ShipInventoryManager.equippedShield.GetShieldDamage(obj) * StatsManager.damageFactor;
            float HPdamage     = 0;
            float shieldDamage = 0;

            if (Shield > damage)
            {
                shieldDamage = damage;
                Shield      -= shieldDamage;
                Game.AddGameObjToShooter(ShieldEffectGenerator.GenerateStandardShieldEffect(Game, spriteSheet, this));

                Game.soundEffectsManager.PlaySoundEffect(SoundEffects.ShieldHit);
            }
            else
            {
                HPdamage     = damage - Shield;
                shieldDamage = Shield;
                HP          -= HPdamage;
                Shield       = 0;

                Game.soundEffectsManager.PlaySoundEffect(obj.getDeathSoundID());
            }

            if (Level.IsLogging)
            {
                Level.AddShipDamage(HPdamage);
                Level.AddShieldDamage(shieldDamage);
            }
        }
예제 #9
0
        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);
        }
예제 #10
0
        public void Update(GameTime gameTime, GameObjectVertical shootObject)
        {
            if (shootObject == null)
            {
                return;
            }

            if (shootingMode == ShootingMode.Regular)
            {
                lastTimeShot += gameTime.ElapsedGameTime.Milliseconds;

                if (lastTimeShot >= shootingDelay)
                {
                    isReadyToShoot = true;
                    lastTimeShot  -= shootingDelay;
                }
            }
            else if (shootingMode == ShootingMode.Batches)
            {
                if (shotsInBatch > 0)
                {
                    lastTimeShot += gameTime.ElapsedGameTime.Milliseconds;
                }
                else
                {
                    lastBatch += gameTime.ElapsedGameTime.Milliseconds;
                }

                if (lastBatch > batchDelay)
                {
                    shotsInBatch = batchSize;
                    lastBatch    = 0;
                }

                if (lastTimeShot >= shootingDelay)
                {
                    shotsInBatch--;

                    //ShootingPattern(gameTime);
                    isReadyToShoot = true;
                    lastTimeShot  -= shootingDelay;
                }
            }
            else if (shootingMode == ShootingMode.Single)
            {
                if (!hasShot)
                {
                    lastTimeShot += gameTime.ElapsedGameTime.Milliseconds;

                    if (lastTimeShot >= shootingDelay)
                    {
                        hasShot = true;
                        //ShootingPattern(gameTime);
                        isReadyToShoot = true;
                        lastTimeShot  -= shootingDelay;
                    }
                }
            }
        }
예제 #11
0
        public virtual void Initialize()
        {
            bounding     = new Rectangle();
            followObject = null;

            if (ObjectName == null)
            {
                ObjectName = "";
            }
        }
예제 #12
0
        public override void Setup(GameObjectVertical obj)
        {
            obj.FollowObjectTypes.Add("ally");
            obj.FollowObjectTypes.Add("player");

            if (obj.TurningSpeed == 0)
            {
                obj.TurningSpeed = 5;
            }
        }
        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);
            }
        }
예제 #14
0
        public override void Setup(GameObjectVertical obj)
        {
            Vector2 centerDir = new Vector2(0, 1.0f);

            double dirRadians = MathFunctions.RadiansFromDir(centerDir);

            dirRadians += random.NextDouble() * 3 * Math.PI / 24 - Math.PI / 24;

            obj.Direction = MathFunctions.DirFromRadians(dirRadians);
        }
예제 #15
0
        public override void InflictDamage(GameObjectVertical obj)
        {
            if (TempInvincibility > 0)
            {
                return;
            }

            OnKilled();
            IsKilled = true;
            base.InflictDamage(obj);
        }
예제 #16
0
        public override void InflictDamage(GameObjectVertical obj)
        {
            if (TempInvincibility > 0)
            {
                return;
            }

            base.OnDamage();
            ApplyDamage(obj);
            TempInvincibility = CollisionHandlingVerticalShooter.TEMP_INVINCIBILITY;
        }
        public static Explosion GenerateRandomExplosion(Game1 game, Sprite spriteSheet,
                                                        GameObjectVertical source)
        {
            Explosion tempExplosion = new Explosion(game, spriteSheet);

            int   nbrParticles = random.Next(8, 16);
            float size         = source.BoundingWidth + source.BoundingHeight;

            tempExplosion.GenerateExplosionParticles(game, spriteSheet, source, nbrParticles, size, randomDir: true);

            return(tempExplosion);
        }
        public override void SetTarget(GameObjectVertical closestEnemy)
        {
            if (closestEnemy is Meteorite15 ||
                closestEnemy is Meteorite20 ||
                closestEnemy is Meteorite25 ||
                closestEnemy is Meteorite30)
            {
                return;
            }

            base.SetTarget(closestEnemy);
        }
예제 #19
0
 public override void Update(GameTime gameTime, GameObjectVertical obj)
 {
     if (obj.PositionY >= stopY && stopTime > 0)
     {
         stopTime      -= gameTime.ElapsedGameTime.Milliseconds;
         obj.DirectionY = 0;
     }
     else
     {
         obj.DirectionY = 1;
     }
 }
        public static Explosion GenerateFixedExplosion(Game1 game, Sprite spriteSheet,
                                                       GameObjectVertical source)
        {
            Explosion tempExplosion = new Explosion(game, spriteSheet);

            int   nbrPartices = 8;
            float size        = source.BoundingWidth / 2;

            tempExplosion.GenerateExplosionParticles(game, spriteSheet, source, nbrPartices, size);

            return(tempExplosion);
        }
        public override void Setup(GameObjectVertical obj)
        {
            zigzagInterval = 0.5f;
            zigzagXdir     = 0.0f;

            if (random.NextDouble() > 0.5)
            {
                zigzagDirRight = true;
            }
            else
            {
                zigzagDirRight = false;
            }
        }
        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);
        }
예제 #23
0
        public override void InflictDamage(GameObjectVertical obj)
        {
            Game.stateManager.shooterState.backgroundObjects.Add(
                ExplosionGenerator.GenerateBulletExplosion(Game, spriteSheet, this));

            if (obj is AreaShieldCollision)
            {
                HP = 0;
            }
            else
            {
                HP -= obj.HP;
            }
        }
예제 #24
0
        public override void Setup(GameObjectVertical obj)
        {
            stopY += random.Next((int)stopYVariation) - stopYVariation / 2;

            if (!isFullstop)
            {
                stopTime = 5000;
            }
            else
            {
                stopTime = 999999999;
            }

            currentStopCount = 0;
        }
예제 #25
0
 public float GetShieldDamage(GameObjectVertical obj)
 {
     if (obj is EnemyBullet)
     {
         return(obj.Damage * bulletDamageFactor);
     }
     else if (obj is EnemyShip)
     {
         return(obj.Damage * collisionDamageFactor);
     }
     else
     {
         return(obj.Damage);
     }
 }
예제 #26
0
        private void CheckIfTargetIsClose()
        {
            GameObjectVertical obj = FindAimObject();

            if (obj != null)
            {
                if (delayIsActivated)
                {
                    isActivated = true;
                }
                else
                {
                    Explode();
                }
            }
        }
예제 #27
0
        public override void Setup(GameObjectVertical obj)
        {
            float windowMiddlePos = windowWidth / 2;

            if (obj.PositionX < windowMiddlePos)
            {
                endX   = windowMiddlePos + (windowMiddlePos - obj.PositionX);
                isLeft = true;
            }
            else
            {
                endX   = windowMiddlePos - (obj.PositionX - windowMiddlePos);
                isLeft = false;
            }
            endReached = false;
        }
예제 #28
0
        public void GenerateAbsoluteExplosion(Game1 game, Sprite spriteSheet, GameObjectVertical source, int nbrPartices, float size,
                                              float speed = 1, int fragmentDur = 1, float fragmentSpeed = 1, bool randomDir = false)
        {
            Vector2 position  = source.Position;
            Vector2 direction = source.Direction;

            ExplosionParticle[] tempParticleArray = new ExplosionParticle[nbrPartices];

            for (int i = 0; i < nbrPartices; i++)
            {
                tempParticleArray[i] = new ExplosionParticle(game, spriteSheet, position,
                                                             direction, speed, size,
                                                             randomDir, i, fragmentSpeed, fragmentDur);
            }
            particleArray = tempParticleArray;
        }
예제 #29
0
        public void GenerateExplosionParticles(Game1 game, Sprite spriteSheet, GameObjectVertical source, int nbrPartices, float size,
                                               float speedFactor = 1, float fragmentDurFactor = 1, float dirFactor = 1, bool randomDir = false)
        {
            Vector2 position  = source.Position;
            Vector2 direction = source.Direction * dirFactor;
            float   speed     = source.Speed * speedFactor;

            ExplosionParticleOverworld[] tempParticleArray = new ExplosionParticleOverworld[nbrPartices];

            for (int i = 0; i < nbrPartices; i++)
            {
                tempParticleArray[i] = new ExplosionParticleOverworld(game, spriteSheet, position,
                                                                      direction, speed, size,
                                                                      randomDir, i);
            }
            particleArray = tempParticleArray;
        }
예제 #30
0
        public static GameObjectVertical ReturnClosestObject(GameObjectVertical object1, float range, List <GameObjectVertical> objects)
        {
            GameObjectVertical tempTarget = null;
            float tempDistance            = range;

            foreach (GameObjectVertical obj in objects)
            {
                if (MathFunctions.ObjectDistance(object1, obj) < tempDistance &&
                    MathFunctions.ObjectDistance(object1, obj) < range)
                {
                    tempTarget   = obj;
                    tempDistance = MathFunctions.ObjectDistance(object1, tempTarget);
                }
            }

            return(tempTarget);
        }