Beispiel #1
0
        public Enemy(Game game, ContentManager content, GraphicsDeviceManager graphics, UnitTypes.EnemyType enemyType, Space space, Vector3 StartingPosition)
            : base(game, content, graphics)
        {
            tank.IsEnemy = true;
            this.enemyType = enemyType;
            this.space = space;
            rotate = Vector3.Zero;
            isHited = false;
            wanderMovesCount = 0;

            tank_box = new Sphere(StartingPosition, 35, 50);//new Box(StartingPosition, 60, 40, 70, 50);
            space.Add(tank_box);
            tank_box.Tag = this;
            tank_box.EventManager.InitialCollisionDetected += tankCollision;
            tank_box.CollisionRules.Group = EnemyTankCollisionGroup;
            this.game = game;

            Velocity = 2;
            tank.Velocity = 10;

            EnemyCannon = new EnemyCannon(game, tank,this);
            EnemyCannonBallManager = new EnemyCannonBallManager(game);
            game.Components.Add(EnemyCannonBallManager);

            randomWanderTarget = Vector3.Zero;
            MaxSteeringForce = 1000;
            WanderOn = true;
            ObstacleAvoidOn = true;
            ChasingOn = false;
            wallAvoidanceOn = true;
            Turn = false;

            FuzzyBrain = new FuzzyEngine();

            SelectedTankParameters = FuzzyBrain.FuzzyParameters;
        }
 void Start()
 {
     _cannon = GetComponent <EnemyCannon>();
     _ship   = GetComponentInParent <ShipCondition>();
     _delay  = Random.Range(3f, 5f);
 }
Beispiel #3
0
        private void Gameplay_Update(int GameState, GameTime pGameTime, ContentManager Content)
        {
            if (keyboard != previousKeyboard && keyboard.IsKeyDown(Keys.Escape) && pause)
            {
                this.Game_State = 0;
            }

            if (keyboard.IsKeyDown(Keys.Escape))
            {
                pause      = true;
                this.Pause = mstate.Position;
            }


            if (keyboard != previousKeyboard && keyboard.IsKeyDown(Keys.Enter) && pause)
            {
                pause = false;
                Mouse.SetPosition(Pause.X, Pause.Y);
            }

            if (!pause)
            {
                foreach (Enemy var1 in enemyFighter)
                {
                    var1.Update(pGameTime);
                }
                foreach (Sprite HUD in hud)
                {
                    HUD.Update(pGameTime);
                }
                foreach (Right_HUD R_H in R_hud)
                {
                    R_H.Update(pGameTime);
                }

                SSV.Update(pGameTime);
                cone.Update(pGameTime);

                //Enemies Update
                foreach (Fighter Enemies in EnemyFighter)
                {
                    Point ID = Enemies.Update(pGameTime);
                    if (ID != Point.Zero)
                    {
                        TargetID = ID;
                    }
                    Enemies.UpdatePositionAngle(cone);
                    if (Enemies.FireWeapon)
                    {
                        int i = 0;
                        if (EnemyMissile.Count != 0)
                        {
                            while (i < EnemyMissile.Count && EnemyMissile[i] != null)
                            {
                                i++;
                            }
                        }
                        Missile var = new Missile(content, this, i, new Point(0, 0));
                        EnemyMissile.Insert(i, var);
                        EnemyMissile[i].SpawnAt(Enemies.Position);
                        EnemyMissile[i].SetDestination(new Vector2(640, 360));
                        Enemies.FireWeapon = false;
                    }
                    if (!Enemies.IsActive)
                    {
                        EnemyFighterDump.Add(Enemies);
                    }
                }
                EnemyFighter = EnemyFighter.Except(EnemyFighterDump).ToList();

                foreach (Frigate Enemies in EnemyFrigate)
                {
                    Point ID = Enemies.Update(pGameTime);
                    if (ID != Point.Zero)
                    {
                        TargetID = ID;
                    }
                    Enemies.UpdatePositionAngle(cone);
                    if (Enemies.FireWeapon)
                    {
                        int i = 0;
                        if (EnemySlug.Count != 0)
                        {
                            while (i < EnemySlug.Count && EnemySlug[i] != null)
                            {
                                i++;
                            }
                        }
                        Slug var = new Slug(content, this);
                        EnemySlug.Insert(i, var);
                        EnemySlug[i].SpawnAt(Enemies.Position);
                        EnemySlug[i].SetDestination(new Vector2(640, 360));
                        Enemies.FireWeapon = false;
                    }
                    if (!Enemies.IsActive)
                    {
                        EnemyFrigateDump.Add(Enemies);
                    }
                }
                EnemyFrigate = EnemyFrigate.Except(EnemyFrigateDump).ToList();

                foreach (Carrier Enemies in EnemyCarrier)
                {
                    Point ID = Enemies.Update(pGameTime);
                    if (ID != Point.Zero)
                    {
                        TargetID = ID;
                    }
                    Enemies.UpdatePositionAngle(cone);
                    if (Enemies.FireWeapon)
                    {
                        AddFigther(content, Enemies.Position, new Vector2(640, 360));
                        Enemies.FireWeapon = false;
                    }
                    if (!Enemies.IsActive)
                    {
                        EnemyCarrierDump.Add(Enemies);
                    }
                }
                EnemyCarrier = EnemyCarrier.Except(EnemyCarrierDump).ToList();

                foreach (Dreadnought Enemies in EnemyDreadnought)
                {
                    Point ID = Enemies.Update(pGameTime);
                    if (ID != Point.Zero)
                    {
                        TargetID = ID;
                    }
                    Enemies.UpdatePositionAngle(cone);
                    if (Enemies.FireWeapon)
                    {
                        int i = 0;
                        if (EnemyCannon.Count != 0)
                        {
                            while (i < EnemyCannon.Count && EnemyCannon[i] != null)
                            {
                                i++;
                            }
                        }
                        Cannon var = new Cannon(content, this, new Point(0, 0), 10);
                        EnemyCannon.Insert(i, var);
                        EnemyCannon[i].SpawnAt(Enemies.Position);
                        Enemies.FireWeapon = false;
                    }
                    if (!Enemies.IsActive)
                    {
                        EnemyDreadnoughtDump.Add(Enemies);
                    }
                }
                EnemyDreadnought = EnemyDreadnought.Except(EnemyDreadnoughtDump).ToList();

                //endEnemies Update

                //Weapons Update

                foreach (Missile Missile in EnemyMissile)
                {
                    Point ID = Missile.Update(GetPositionByID(Missile.TargetID));
                    if (ID != Point.Zero)
                    {
                        TargetID = ID;
                    }

                    if (Missile.Friendly == false && Missile.IsMoving == false)
                    {
                        Missile.Destroy = true;
                        enemyMissileDump.Add(Missile);
                        HB_hp -= 1;
                    }
                    else if (Missile.Friendly && !Missile.IsMoving)
                    {
                        DamageTarget(Missile.TargetID, 1);
                    }
                }

                enemyMissile = enemyMissile.Except(enemyMissileDump).ToList();

                foreach (Laser Lsr in Lasers)
                {
                    Lsr.Update();
                }

                foreach (Slug Slug in EnemySlug)
                {
                    Slug.Update();

                    if (Slug.Friendly == false && Slug.IsMoving == false)
                    {
                        Slug.Destroy = true;
                        enemySlugDump.Add(Slug);
                        HB_hp -= 5;
                    }
                    else if (Slug.Friendly && !Slug.IsMoving)
                    {
                        DamageTarget(Slug.TargetID, 2);
                    }
                }

                enemySlug = enemySlug.Except(enemySlugDump).ToList();

                foreach (Cannon Cannon in EnemyCannon)
                {
                    Cannon.Update();

                    //Add destroy here.
                }

                enemySlug = enemySlug.Except(enemySlugDump).ToList();

                //endWeapons Update

                ladar.Update(pGameTime, cone.Lockin, cone.stopAngle_M);

                if (SpawnBlock == 200)
                {
                    SpawnEnemy(Content);
                    SpawnBlock = 0;
                }
                else
                {
                    SpawnBlock += 1;
                }

                //PlayerWeapons

                PlayerWpn[0].Update();
                PlayerWpn[1].Update();
                PlayerWpn[2].Update();
                PlayerWpn[3].Update();
                PlayerWpn[4].Update();

                if (keyboard.IsKeyDown(Keys.D1))
                {
                    if (PlayerWpn[0].CanFire)
                    {
                        int i = 0;
                        if (EnemyMissile.Count != 0)
                        {
                            while (i < EnemyMissile.Count && EnemyMissile[i] != null)
                            {
                                i++;
                            }
                        }
                        Missile var = new Missile(content, this, i, TargetID);
                        EnemyMissile.Insert(i, var);
                        EnemyMissile[i].SpawnAt(new Vector2(640, 360));
                        EnemyMissile[i].SetDestination(GetPositionByID(TargetID));
                        EnemyMissile[i].Friendly = true;
                        PlayerWpn[0].FireWeapon();
                    }
                }
                else if (keyboard.IsKeyDown(Keys.D2))
                {
                    if (PlayerWpn[1].CanFire)
                    {
                        int i = 0;
                        if (Lasers.Count != 0)
                        {
                            while (i < Lasers.Count && Lasers[i] != null)
                            {
                                i++;
                            }
                        }
                        Laser var = new Laser(content, this, TargetID, 10);
                        Lasers.Insert(i, var);
                        Lasers[i].SpawnAt(new Vector2(640, 360));
                        PlayerWpn[1].FireWeapon();
                    }
                }
                else if (keyboard.IsKeyDown(Keys.D3))
                {
                    if (PlayerWpn[2].CanFire)
                    {
                        int i = 0;
                        if (EnemySlug.Count != 0)
                        {
                            while (i < EnemySlug.Count && EnemySlug[i] != null)
                            {
                                i++;
                            }
                        }
                        Slug var = new Slug(content, this);
                        EnemySlug.Insert(i, var);
                        EnemySlug[i].SpawnAt(new Vector2(640, 360));
                        EnemySlug[i].SetDestination(GetPositionByID(TargetID));
                        PlayerWpn[2].FireWeapon();
                    }
                }
                else if (keyboard.IsKeyDown(Keys.D4))
                {
                    if (PlayerWpn[3].CanFire)
                    {
                        int i = 0;
                        if (EnemyCannon.Count != 0)
                        {
                            while (i < EnemyCannon.Count && EnemyCannon[i] != null)
                            {
                                i++;
                            }
                        }
                        Cannon var = new Cannon(content, this, TargetID, 10);
                        EnemyCannon.Insert(i, var);
                        EnemyCannon[i].SpawnAt(new Vector2(640, 360));
                        PlayerWpn[3].FireWeapon();
                        DamageTarget(TargetID, 3);
                    }
                }
                else if (keyboard.IsKeyDown(Keys.D5))
                {
                    if (PlayerWpn[4].CanFire)
                    {
                        foreach (Fighter var1 in EnemyFighter)
                        {
                            DamageTarget(var1.ID, 4);
                        }
                        foreach (Frigate var1 in EnemyFrigate)
                        {
                            DamageTarget(var1.ID, 4);
                        }
                        foreach (Carrier var1 in EnemyCarrier)
                        {
                            DamageTarget(var1.ID, 4);
                        }
                        foreach (Dreadnought var1 in EnemyDreadnought)
                        {
                            DamageTarget(var1.ID, 4);
                        }
                    }
                }

                //End Player Weapons

                //Dreadnought Countdown
                foreach (Dreadnought Dreadnought in EnemyDreadnought)
                {
                    if (Dreadnought.IsMoving == false)
                    {
                        Dreadnought.cannonCountdown -= 1;
                        //Console.WriteLine(Dreadnought.cannonCountdown);
                    }

                    if (Dreadnought.cannonCountdown == 0)
                    {
                        Dreadnought.cannonCountdown = 100;
                    }
                }
                //end Dreadnought Countdown
            }
        }