protected void CreateCreature(Vector2 position)
        {
            VerticalShooterShip creature = RetrieveCreatureFromEnum(enemyType);
            VerticalShooterShip ship     = VerticalCreationLogic(position, CreationFlag.VECTOR_POSITION);

            Game.stateManager.shooterState.gameObjects.Add(ship);
        }
        private VerticalShooterShip CreateReturnCreature(Vector2 position)
        {
            VerticalShooterShip creature = RetrieveCreatureFromEnum(enemyType);

            creature          = StandardCreatureSetup(creature);
            creature.Position = position;
            return(creature);
        }
Beispiel #3
0
        public CreaturePackage(Game1 Game, Sprite spriteSheet,
                               VerticalShooterShip creature, float timing)
        {
            this.Game        = Game;
            this.spriteSheet = spriteSheet;

            this.creature = creature;
            this.timing   = timing;

            this.initPos = creature.Position;
            this.initHP  = creature.HP;
        }
        public override List <CreaturePackage> RetrieveCreatures()
        {
            List <CreaturePackage> creatures = new List <CreaturePackage>();

            for (float t = 0; t < Duration; t += SpawnDelay)
            {
                VerticalShooterShip crit = ReturnCreature();
                creatures.Add(new CreaturePackage(Game, spriteSheet, crit, (int)t));
            }

            return(creatures);
        }
        private VerticalShooterShip StandardCreatureSetup(VerticalShooterShip creature)
        {
            creature.Initialize();
            creature.Direction = new Vector2(0, 1.0f);

            if (setupCreature != null)
            {
                creature.HP    *= setupCreature.HPFactor;
                creature.Speed *= setupCreature.speedFactor;

                if (setupCreature.newMovement != Movement.None)
                {
                    if (setupCreature.newMovement != Movement.BossStop_X)
                    {
                        creature.SetMovement(setupCreature.newMovement);
                    }
                    else
                    {
                        creature.SetBossMovement(setupCreature.YStopPosition);
                    }
                }
            }

            //Extra logic for allys
            if (creature is AlliedShip)
            {
                ((AlliedShip)creature).SetFormationArea(new Rectangle((int)(creature.PositionX), 500, 1, 7));

                if (creature is AllianceFighterAlly || creature is RebelFighterAlly)
                {
                    ((AlliedShip)creature).CreateAI(AIBehaviour.Standard);
                }
                else if (creature is FreighterAlly)
                {
                    ((AlliedShip)creature).CreateAI(AIBehaviour.NoWeapon);
                }
                else
                {
                    throw new ArgumentException("Unknown ally type!");
                }
            }

            // Slightly alters the draw layer to give all gameobjects individual layers
            creature.DrawLayer += (float)(MathFunctions.GetExternalRandomDouble() * 0.01);

            return(creature);
        }
        protected void CreateCreature(float xPos = -1f)
        {
            CreationFlag flag;

            if (xPos == -1f)
            {
                flag = CreationFlag.WITHOUT_POSITION;
            }
            else
            {
                flag = CreationFlag.X_POSITION;
            }

            if (xPos == -1f)
            {
                xPos = level.RelativeOrigin + (float)(random.NextDouble() * level.LevelWidth);
            }

            Vector2 xVector = new Vector2(xPos, 0);

            VerticalShooterShip ship = VerticalCreationLogic(xVector, flag);

            Game.stateManager.shooterState.gameObjects.Add(ship);
        }
Beispiel #7
0
        public void Process(GameTime gameTime)
        {
            //Always updates the closest enemy, used for setting target
            closestObject = MathFunctions.ReturnClosestObject(ship, ship.SightRange,
                                                              Game.stateManager.shooterState.gameObjects, "enemy");

            if (target == null)
            {
                behaviour.SetTarget(closestObject);
            }

            else
            {
                targetYDistance = ship.BoundingY - (target.BoundingY + target.BoundingHeight);
                targetXDistance = ship.PositionX - (target.BoundingX + target.BoundingWidth);
                if (targetXDistance < 0)
                {
                    targetXDistance *= -1;
                }

                //Removes target when dead or too far from AI-controlled ship
                if (target.IsOutside || target.IsKilled || targetYDistance < -100 || targetXDistance > 400)
                {
                    if (Behaviour.IgnoreList.Contains(target))
                    {
                        Behaviour.GarbageIgnoreList.Add(target);
                        Behaviour.UpdateIgnoreList();
                    }

                    target = null;
                }
            }

            //Calls the behaviour and asks which action to take
            behaviour.Action();
        }
        private VerticalShooterShip VerticalCreationLogic(Vector2 position, CreationFlag flag)
        {
            VerticalShooterShip creature = RetrieveCreatureFromEnum(enemyType);

            if (flag != CreationFlag.VECTOR_POSITION)
            {
                if (!(creature is AllianceHangar))
                {
                    position.Y -= 50; // Setting a startup marginal to not "pop" on the screen
                }
                else
                {
                    position.Y -= 150;
                }
            }

            if (Game1.ScreenSize.Y > 600)
            {
                position.Y += (Game1.ScreenSize.Y - 600) / 2;
            }

            switch (flag)
            {
            case CreationFlag.WITHOUT_POSITION:
            {
                xPos = level.RelativeOrigin + (float)(random.NextDouble() * level.LevelWidth);
                break;
            }

            case CreationFlag.X_POSITION:
            {
                xPos = level.RelativeOrigin + position.X;
                break;
            }

            case CreationFlag.VECTOR_POSITION:
            {
                xPos = level.RelativeOrigin + position.X;
                break;
            }

            default:
            {
                throw new ArgumentException("New unhandled flag-variant is probably present");
            }
            }

            creature.PositionX = xPos;

            if (creature is AlliedShip)
            {
                creature.PositionY = 600;
            }
            else
            {
                creature.PositionY = position.Y;
            }

            creature = StandardCreatureSetup(creature);
            creature.SetLevelWidth(level.LevelWidth);
            creature.MovementSetup();

            return(creature);
        }
        protected VerticalShooterShip RetrieveCreatureFromEnum(EnemyType identifier)
        {
            VerticalShooterShip creature = null;

            switch (identifier)
            {
            // Allies
            case EnemyType.allianceFighterAlly:
            {
                creature = new AllianceFighterAlly(Game, spriteSheet, player);
                break;
            }

            case EnemyType.freighterAlly:
            {
                creature = new FreighterAlly(Game, spriteSheet, player);
                break;
            }

            case EnemyType.rebelFighterAlly:
            {
                creature = new RebelFighterAlly(Game, spriteSheet, player);
                break;
            }

                // Neutral
                #region neutral
            case EnemyType.big_R:
            {
                creature = new AllianceBigFighterMkI(Game, spriteSheet, player);
                break;
            }

            case EnemyType.bigMissile_R:
            {
                creature = new AllianceBigMissileEnemy(Game, spriteSheet, player);
                break;
            }

            case EnemyType.turret:
            {
                creature = new Turret(Game, spriteSheet, player);
                break;
            }

            case EnemyType.meteor:
            {
                int rNbr = random.Next(4);

                switch (rNbr)
                {
                case 0:
                {
                    creature = new Meteorite15(Game, spriteSheet, player);
                    break;
                }

                case 1:
                {
                    creature = new Meteorite20(Game, spriteSheet, player);
                    break;
                }

                case 2:
                {
                    creature = new Meteorite25(Game, spriteSheet, player);
                    break;
                }

                case 3:
                {
                    creature = new Meteorite30(Game, spriteSheet, player);
                    break;
                }

                default:
                {
                    throw new ArgumentException("Check the randomized range");
                }
                }
                break;
            }

            case EnemyType.homingBullet_R:
            {
                creature = new AllianceHomingShotEnemy(Game, spriteSheet, player);
                break;
            }

            case EnemyType.homingMissile_R:
            {
                creature = new AllianceHomingMissileEnemy(Game, spriteSheet, player);
                break;
            }

            case EnemyType.medium:
            {
                creature = new RebelMediumSizedEnemy(Game, spriteSheet, player);
                break;
            }

            case EnemyType.smallShooter_R:
            {
                creature = new AllianceSmallShooter(Game, spriteSheet, player);
                break;
            }
                #endregion

                // Rebel
                #region rebel
            case EnemyType.R_mosquito:
            {
                creature = new RebelMosquito(Game, spriteSheet, player);
                break;
            }

            case EnemyType.R_thickShooter:
            {
                creature = new RebelThickShooter(Game, spriteSheet, player);
                break;
            }

            case EnemyType.R_smallSniper:
            {
                creature = new RebelSmallSniper(Game, spriteSheet, player);
                break;
            }

            case EnemyType.R_lightMinelayer:
            {
                creature = new RebelLightMinelayer(Game, spriteSheet, player);
                break;
            }

            case EnemyType.R_homingMissile:
            {
                creature = new RebelHomingMissile(Game, spriteSheet, player);
                break;
            }

            case EnemyType.R_bomber:
            {
                creature = new RebelBomber(Game, spriteSheet, player);
                break;
            }

            case EnemyType.R_burster:
            {
                creature = new RebelBurster(Game, spriteSheet, player);
                break;
            }

            case EnemyType.R_minelayer:
            {
                creature = new RebelMinelayer(Game, spriteSheet, player);
                break;
            }

            case EnemyType.R_smallAttack:
            {
                creature = new RebelSmallAttackShip(Game, spriteSheet, player);
                break;
            }

            case EnemyType.R_missileAttackShip:
            {
                creature = new RebelMissileAttack(Game, spriteSheet, player);
                break;
            }

            case EnemyType.R_fatzo:
            {
                creature = new RebelFatzo(Game, spriteSheet, player);
                break;
            }
                #endregion

                // Alliance
                #region alliance
            case EnemyType.A_drone:
            {
                creature = new AllianceDrone(Game, spriteSheet, player);
                break;
            }

            case EnemyType.A_smallLaserShip:
            {
                creature = new AllianceSmallLaserShip(Game, spriteSheet, player);
                break;
            }

            case EnemyType.A_singleHoming:
            {
                creature = new AllianceSingleHoming(Game, spriteSheet, player);
                break;
            }

            case EnemyType.A_shielder:
            {
                creature = new AllianceShielder(Game, spriteSheet, player);
                break;
            }

            case EnemyType.A_attackStealth:
            {
                creature = new AllianceStealthAttackShip(Game, spriteSheet, player);
                break;
            }

            case EnemyType.A_lightBeamer:
            {
                creature = new AllianceLightBeamer(Game, spriteSheet, player);
                break;
            }

            case EnemyType.A_multipleShot:
            {
                creature = new AllianceMultipleShot(Game, spriteSheet, player);
                break;
            }

            case EnemyType.A_stealthShip:
            {
                creature = new AllianceStealthShip(Game, spriteSheet, player);
                break;
            }

            case EnemyType.A_heavyBeamer:
            {
                creature = new AllianceHeavyBeamer(Game, spriteSheet, player);
                break;
            }

            case EnemyType.A_ballistic:
            {
                creature = new AllianceBallistic(Game, spriteSheet, player);
                break;
            }

            case EnemyType.A_hangar:
            {
                creature = new AllianceHangar(Game, spriteSheet, player);
                break;
            }
                #endregion

            default:
            {
                throw new ArgumentException("Argument not implemented!");
            }
            }

            return(creature);
        }
Beispiel #10
0
        public void Avoid()
        {
            foreach (GameObjectVertical obj in Game.stateManager.shooterState.gameObjects)
            {
                if (obj.ObjectClass == "enemy" || obj.ObjectClass == "enemyBullet")
                {
                    if (CollisionDetection.IsPointInsideCircle(obj.Position, ship.Position, AvoidRadius))
                    {
                        AvoidList.Add(obj);
                    }
                }
            }

            if (AvoidList.Count > 0)
            {
                objToAvoid = MathFunctions.ReturnClosestObject(ship, AvoidRadius, AvoidList);
            }

            if (objToAvoid == target)
            {
                Behaviour.GarbageIgnoreList.Add(target);
                Behaviour.UpdateIgnoreList();
                target = null;
            }

            if (AvoidList.Count > 0 && objToAvoid != null)
            {
                //enemy is to the right on AI-ship's center
                if (objToAvoid.BoundingX + objToAvoid.BoundingWidth >= ship.PositionX &&
                    objToAvoid.BoundingX - 20 < ship.PositionX + ship.CenterPointX)
                {
                    if (ship.BoundingX > (Game1.ScreenSize.X - Game.stateManager.shooterState.CurrentLevel.LevelWidth) / 2 + 20)
                    {
                        ship.Move(new Vector2(-1, ship.DirectionY));
                    }
                }

                else if (objToAvoid.BoundingX < ship.PositionX &&
                         objToAvoid.BoundingX + objToAvoid.BoundingWidth + 20 > ship.BoundingX)
                {
                    if (ship.BoundingX + ship.BoundingWidth < Game.stateManager.shooterState.CurrentLevel.LevelWidth - 20)
                    {
                        ship.Move(new Vector2(1, ship.DirectionY));
                    }
                }

                else
                {
                    ship.Stop("x");
                }
            }

            for (int i = 0; i < AvoidList.Count; i++)
            {
                if (AvoidList[i].IsKilled || AvoidList[i].IsOutside ||
                    !CollisionDetection.IsPointInsideCircle(AvoidList[i].Position, ship.Position, AvoidRadius))
                {
                    GarbageAvoidList.Add(AvoidList[i]);

                    if (objToAvoid == AvoidList[i])
                    {
                        objToAvoid = null;
                    }
                }
            }

            foreach (GameObjectVertical obj in GarbageAvoidList)
            {
                AvoidList.Remove(obj);
            }

            GarbageAvoidList.Clear();
        }
 public AreaShieldCollision(Game1 game, VerticalShooterShip sourceObject, float radius)
     : base(game, sourceObject.Position)
 {
     this.sourceObject = sourceObject;
     this.radius       = radius;
 }