Esempio n. 1
0
 public CampaignSection(int i, Vector3 o)
 {
     _index = i;
     _origin = o;
     _door = null;
     _overheadLights = new List<Light>();
     _population = new List<BaseAlien>();
     _weaponDepot = null;
     _currentTitle = "";
 }
Esempio n. 2
0
 public void SetWeaponDepot(WeaponDepot weaponDepot)
 {
     _weaponDepot = weaponDepot;
 }
Esempio n. 3
0
        public override void Update(float ms)
        {
            if (health <= 0)
            {
                health     = 0;
                this.alive = false;

                if (currentFiringAnimation != Animation_States.death)
                {
                    currentFiringAnimation = Animation_States.death;
                    upPlayer.StartClip(currentFiringAnimation);
                    lowPlayer.StartClip(currentFiringAnimation);
                }
                else if (upPlayer.GetLoopCount() > 1)
                {
                    this.dead = true;
                }

                UpdateAnimation(ms);
                UpdateMajorTransforms(ms);
            }
            else
            {
                IProjectile p = Globals.gameInstance.alienProjectileManager.CheckHit(this);
                if (p != null)
                {
                    p.PreDestroy();
                    p.Destroy();
                    this.health -= p.GetDamage();
                    //if (this._health <= 0)
                    //{
                    //    this._state = AlienState.DYING;
                    //    this._aplayer.StartClip(Animation_States.death);
                    //    Globals.audioManager.PlayGameSound("aliendeath1");
                    //}
                }

                double temp = this.oldHealth;
                this.oldHealth = this.health;

                if (temp == health && health >= 0 && health < 100)
                {
                    this.health = this.health + ((ms / 1000) * 0.6);
                }
                Vector3 newposition = new Vector3(_position.X, _position.Y, _position.Z);

                // 1. == Update Movement
                // movement is done via analog sticks
                Vector2 vleft  = Globals.inputController.getAnalogVector(AnalogStick.Left, playerIndex);
                Vector2 vright = Globals.inputController.getAnalogVector(AnalogStick.Right, playerIndex);
                // 1.1 = Update player rotation based on RIGHT analog stick
                if (vright.LengthSquared() > 0.01f)
                {
                    // get target angle
                    float targetrotation = (float)Math.Atan2(vright.Y, vright.X) - MathHelper.PiOver2;

                    // get difference
                    float deltarotation = targetrotation - rotation;

                    // sanitise
                    if (deltarotation > Math.PI)
                    {
                        deltarotation -= MathHelper.TwoPi;
                    }
                    if (deltarotation < -Math.PI)
                    {
                        deltarotation += MathHelper.TwoPi;
                    }

                    // add difference
                    rotation += (ms / 300) * deltarotation;

                    // sanitise rotation
                    if (rotation > MathHelper.TwoPi)
                    {
                        rotation -= MathHelper.TwoPi;
                    }
                    if (rotation < -MathHelper.TwoPi)
                    {
                        rotation += MathHelper.TwoPi;
                    }
                }

                // 1.2 = Update player movement based on LEFT analog stick
                if (vleft.LengthSquared() > 0.1f)
                {
                    Vector3 pdelta = new Vector3(vleft.X, 0, -vleft.Y);
                    pdelta.Normalize();
                    // modifies the horizantal direction
                    newposition += pdelta * ms / 300;

                    // 1.3 = If no rotation was changed, pull player angle toward forward vector
                    if (vright.LengthSquared() < 0.01f)
                    {
                        // get target angle
                        float targetrotation = (float)Math.Atan2(vleft.Y, vleft.X) - MathHelper.PiOver2;

                        // get difference
                        float deltarotation = targetrotation - rotation;

                        // sanitise
                        if (deltarotation > Math.PI)
                        {
                            deltarotation -= MathHelper.TwoPi;
                        }
                        if (deltarotation < -Math.PI)
                        {
                            deltarotation += MathHelper.TwoPi;
                        }

                        // add difference
                        rotation += (ms / 300) * deltarotation;

                        // sanitise rotation
                        if (rotation > MathHelper.TwoPi)
                        {
                            rotation -= MathHelper.TwoPi;
                        }
                        if (rotation < -MathHelper.TwoPi)
                        {
                            rotation += MathHelper.TwoPi;
                        }
                    }

                    moving = Animation_States.run;
                }
                else
                {
                    moving = Animation_States.idle;
                }

                if (Globals.inputController.isTriggerDown(Triggers.Right, playerIndex))
                {
                    if (currentWeapon > -1 && weapons[currentWeapon].CanFire())
                    {
                        weapons[currentWeapon].Fire(rotation + MathHelper.PiOver2);
                        shooting = Animation_States.shoot;
                    }
                }

                if (Globals.inputController.isButtonPressed(Microsoft.Xna.Framework.Input.Buttons.Y, playerIndex))
                {
                    int nw = (currentWeapon + 1) % 5;

                    SwitchWeapon(nw);
                }

                if (Globals.inputController.isButtonPressed(Microsoft.Xna.Framework.Input.Buttons.X, playerIndex))
                {
                    // check game section
                    WeaponDepot wd = Globals.gameInstance.campaignManager.GetNearestActiveDepot(_position);
                    if (wd != null)
                    {
                        SwitchWeapon(wd.GetIndex());
                        wd.Deactivate();
                    }
                }


                // collision stuff
                if (_position != newposition)
                {
                    // First test X collision
                    // Xmovement can collide with walls or doors
                    // first check the doors, this is fast
                    collisionRectangle.Left = newposition.X - boundingBoxSize;
                    collisionRectangle.Top  = _position.Z - boundingBoxSize;
                    if (Globals.gameInstance.cellCollider.RectangleCollides(collisionRectangle))
                    {
                        // if it does collide, pull it back
                        newposition.X = _position.X;
                    }

                    if (Globals.gameInstance.campaignManager.RectangleCollidesDoor(collisionRectangle))
                    {
                        newposition.X = _position.X;
                    }

                    // Then test Z collision
                    collisionRectangle.Left = _position.X - boundingBoxSize;
                    collisionRectangle.Top  = newposition.Z - boundingBoxSize;
                    if (Globals.gameInstance.cellCollider.RectangleCollides(collisionRectangle))
                    {
                        // if it does collide, pull it back
                        newposition.Z = _position.Z;
                    }

                    collisionRectangle.Left = newposition.X - boundingBoxSize;
                    collisionRectangle.Top  = newposition.Z - boundingBoxSize;
                    if (Globals.gameInstance.campaignManager.CollideCurrentEntities(this))
                    {
                        newposition = _position;
                    }

                    //lastly check the distance between players
                    if (Globals.gameInstance.players.Length > 1)
                    {
                        int otherPlayer = Math.Abs((int)playerIndex - 1);
                        if (Math.Abs(Globals.gameInstance.players[otherPlayer]._position.X - newposition.X) > CameraController.MAX_DISTANCE_BETWEEN_PLAYERS)
                        {
                            newposition.X = _position.X;
                        }
                    }

                    // if there is still a new position
                    if (_position != newposition)
                    {
                        _position = newposition;

                        modelReceipt.graph.Renew(modelReceipt);
                        light1receipt.graph.Renew(light1receipt);
                        light2receipt.graph.Renew(light2receipt);
                        light3receipt.graph.Renew(light3receipt);
                    }
                }

                UpdateAnimation(ms);
                UpdateMajorTransforms(ms);

                if (currentWeapon > -1)
                {
                    weapons[currentWeapon].SetTransform(upPlayer.GetWorldTransforms()[31], mesh.Transform);
                    weapons[currentWeapon].receipt.graph.Renew(weapons[currentWeapon].receipt);

                    if (weapons[currentWeapon].AnimationComplete())
                    {
                        shooting = 0;
                    }
                }
                // Update Top half of body
                if (currentFiringAnimation != moving + shooting + weapon)
                {
                    currentFiringAnimation = moving + shooting + weapon;
                    upPlayer.StartClip(currentFiringAnimation);
                }

                //Update Bottom half of body
                if (currentAnimation != moving + weapon)
                {
                    currentAnimation = moving + weapon;
                    lowPlayer.StartClip(currentAnimation);
                }
            }
        }