Ejemplo n.º 1
0
        public override void Update(ManagerHelper mH)
        {
            if (frameIndex < totalFrames)
            {
                frameIndex = (int)((float)frameCounter / drawFrames * totalFrames);

                //Spawn fire
                if (mH.GetRandom().NextDouble() < 0.3)
                {
                    mH.GetParticleManager()
                    .AddFire(GetOriginPosition(),
                             PathHelper.Direction((float)(mH.GetRandom().NextDouble() * Math.PI * 2)) * 100, 1, 0.05f, 1,
                             0.1f);
                }

                if (mH.GetGametype() is Survival)
                {
                    foreach (NPC a in mH.GetNPCManager().GetAllies(NPC.AffliationTypes.black))
                    {
                        if (NPCManager.IsNPCInRadius(a, GetOriginPosition(), 64) && !doomedDots.Contains(a))
                        {
                            doomedDots.Add(a);

                            if (!a.GetFireStatus())
                            {
                                a.ChangeFireStatus();
                                dotsSetOnFire.Add(a);
                            }
                            a.ChangeHealth(-30, mH.GetNPCManager().GetCommander(NPC.AffliationTypes.red));
                        }
                    }
                }
                else
                {
                    foreach (NPC a in mH.GetNPCManager().GetNPCs())
                    {
                        if (a.GetAffiliation() != affiliation && NPCManager.IsNPCInRadius(a, GetOriginPosition(), 64) && !doomedDots.Contains(a))
                        {
                            doomedDots.Add(a);

                            if (!a.GetFireStatus())
                            {
                                a.ChangeFireStatus();
                                dotsSetOnFire.Add(a);
                            }
                            a.ChangeHealth(-70, mH.GetNPCManager().GetCommander(NPC.AffliationTypes.red));
                        }
                    }
                }
            }

            //Deal Damage
            for (int i = 0; i < doomedDots.Count; i++)
            {
                NPC a = doomedDots[i];
                if (!mH.GetNPCManager().GetNPCs().Contains(a))
                {
                    doomedDots.Remove(a);
                    i--;
                    continue;
                }

                //Spawn fire
                if (mH.GetRandom().NextDouble() < 0.1f)
                {
                    mH.GetParticleManager()
                    .AddFire(a.GetOriginPosition(),
                             PathHelper.Direction((float)(mH.GetRandom().NextDouble() * Math.PI * 2)) * 30, 1, 0.05f, 1,
                             0.1f);
                }

                if (frameCounter % burnFrames == 0)
                {
                    a.ChangeHealth(-2, mH.GetNPCManager().GetCommander(NPC.AffliationTypes.red));
                }
            }

            frameCounter++;
            this.scale = scale * modifer;

            base.Update(mH);
        }
Ejemplo n.º 2
0
 public void AddStandardSmoke(Vector2 p, float v)
 {
     AddParticle("Effects/smoke_standard", p,
                 PathHelper.Direction((float)(managers.GetRandom().NextDouble() * MathHelper.TwoPi)) * v, 1, 0.01f, 1, 3);
 }
Ejemplo n.º 3
0
        public override void Update(ManagerHelper mH)
        {
            //Check health
            if (ProjectileCheck(mH))
            {
                Explode(mH);
                return;
            }

#if WINDOWS
            KeyboardState keyState   = mH.GetCurrentState();
            MouseState    mouseState = Mouse.GetState();
#elif XBOX
            GamePadState theState =
                mH.GetCameraManager().GetCameras()[mH.GetCameraManager().GetPlayerInt(this.GetType())].GetState();
            GamePadState oldState =
                mH.GetCameraManager().GetCameras()[mH.GetCameraManager().GetPlayerInt(this.GetType())].GetOldState();
            #endif

            #region Shooting

#if WINDOWS
            if (mouseState.LeftButton == ButtonState.Pressed /* true*/)
            {
                if (weaponType == 0 && shootingCounter > shootingSpeed /* true*/)
                {
                    shootingCounter = 0;
                    Shoot(mH);
                }
                else if (weaponType == 1 && shootingCounter > shotgunShootingSpeed)
                {
                    shootingCounter = 0;
                    ShootShotgun(mH);
                }
            }
            else if (mouseState.RightButton == ButtonState.Pressed && grenadeCounter > grenadeSpeed)
            {
                if (grenadeType == 0)
                {
                    grenadeCounter = 0;
                    TossGrenade(mH);
                }
                else if (grenadeType == 1)
                {
                    grenadeCounter = 0;
                    LayMine(mH);
                }
            }

            //Switch weapons
            if (keyState.IsKeyDown(Keys.E) && !oldState.IsKeyDown(Keys.E))
            {
                weaponType = (weaponType == 0) ? 1 : 0;

                modeIndex = weaponType;
            }
            else if (keyState.IsKeyDown(Keys.R) && !oldState.IsKeyDown(Keys.R))
            {
                grenadeType = (grenadeType == 0) ? 1 : 0;
            }
#elif XBOX
            if (theState.IsButtonDown(Buttons.RightTrigger))
            {
                if (weaponType == 0 && shootingCounter > shootingSpeed)
                {
                    shootingCounter = 0;
                    Shoot(mH);
                }
                else if (weaponType == 1 && shootingCounter > shotgunShootingSpeed)
                {
                    shootingCounter = 0;
                    ShootShotgun(mH);
                }
            }
            else if (theState.IsButtonDown(Buttons.LeftTrigger) && grenadeCounter > grenadeSpeed)
            {
                if (grenadeType == 0)
                {
                    grenadeCounter = 0;
                    TossGrenade(mH);
                }
                else if (grenadeType == 1)
                {
                    grenadeCounter = 0;
                    LayMine(mH);
                }
            }

            //Switch weapons
            if (theState.IsButtonDown(Buttons.RightShoulder) && !oldState.IsButtonDown(Buttons.RightShoulder))
            {
                weaponType = (weaponType == 0) ? 1 : 0;

                modeIndex = weaponType;
            }
            else if (theState.IsButtonDown(Buttons.LeftShoulder) && !oldState.IsButtonDown(Buttons.LeftShoulder))
            {
                grenadeType = (grenadeType == 0) ? 1 : 0;
            }
#endif

            shootingCounter += mH.GetGameTime().ElapsedGameTime.TotalSeconds;
            grenadeCounter  += mH.GetGameTime().ElapsedGameTime.TotalSeconds;

            #endregion

            #region Ability

#if WINDOWS
            if (keyState.IsKeyDown(Keys.Space) && !oldState.IsKeyDown(Keys.Space))
            {
                UsePower(mH);
            }
#elif XBOX
            if (theState.IsButtonDown(Buttons.A) && !oldState.IsButtonDown(Buttons.A))
            {
                UsePower(mH);
            }
            #endif

            #endregion

            #region Movement

#if WINDOWS
            Vector2 dir = Vector2.Zero;

            if (keyState.IsKeyDown(Keys.W))
            {
                dir.Y = -1;
            }
            else if (keyState.IsKeyDown(Keys.S))
            {
                dir.Y = 1;
            }

            if (keyState.IsKeyDown(Keys.A))
            {
                dir.X = -1;
            }
            else if (keyState.IsKeyDown(Keys.D))
            {
                dir.X = 1;
            }


            if (dir != Vector2.Zero)
            {
                dir.Normalize();
                accelerations.Add(dir);
            }
#elif XBOX
            //Forward
            if (theState.ThumbSticks.Left.Y != 0 || theState.ThumbSticks.Left.X != 0)
            {
                accelerations.Add(new Vector2(theState.ThumbSticks.Left.X, theState.ThumbSticks.Left.Y * -1));
            }
            #endif

            #endregion

            #region Finalize Direction

            acceleration = Vector2.Zero;
            foreach (Vector2 a in accelerations)
            {
                if (!float.IsNaN(a.X) && !float.IsNaN(a.Y))
                {
                    acceleration += a;
                }
            }
            drag      = 0.1f;
            thrust    = movementSpeed * drag;
            velocity += thrust * acceleration - drag * velocity;

            accelerations.Clear();

            #endregion

            #region Rotation

#if WINDOWS
            wantedRotation =
                PathHelper.Direction(
                    CameraManager.Transform(position, mH.GetCameraManager().GetDisplacement(GetType())) + origin,
                    new Vector2(mouseState.X, mouseState.Y));
            if (wantedRotation < 0)
            {
                wantedRotation += MathHelper.TwoPi;
            }

            //Calculate turningSpeed to maximize speed and minimize jittering
            if (MathHelper.Distance(rotation, wantedRotation) < turningSpeed && turningSpeed > MathHelper.Pi / 160.0f)
            {
                turningSpeed /= 2.0f;
            }
            else if (MathHelper.Distance(rotation, wantedRotation) > turningSpeed && turningSpeed < maxTurningSpeed)
            {
                turningSpeed *= 2.0f;
            }

            //Apply turningSpeed to rotation in correct direction
            float otherRot = rotation + MathHelper.TwoPi * ((rotation > MathHelper.Pi) ? -1 : 1);
            //Same angle, different name to compensate for linear numbers
            float distADir = MathHelper.Distance(wantedRotation, rotation),
            //Archlength sorta from actual rotation
                  distBDir = MathHelper.Distance(wantedRotation, otherRot); //Archlength sorta from same angle but 2pi over

            //If the usual angle is closer
            if (distADir < distBDir)
            {
                //Do normal rotation
                if (rotation > wantedRotation)
                {
                    Turn(-1 * turningSpeed);
                }
                else if (rotation < wantedRotation)
                {
                    Turn(turningSpeed);
                }
            }
            //Otherwise
            else
            {
                //Do a rotation using the new number, which is able to give the correct turning direction
                if (otherRot > wantedRotation)
                {
                    Turn(-1.0f * turningSpeed);
                }
                else if (otherRot < wantedRotation)
                {
                    Turn(turningSpeed);
                }
            }
#elif XBOX
            if (theState.ThumbSticks.Right.X != 0 || theState.ThumbSticks.Right.Y != 0)
            {
                wantedRotation = (float)Math.Atan2(theState.ThumbSticks.Right.Y * -1, theState.ThumbSticks.Right.X);
                if (wantedRotation < 0)
                {
                    wantedRotation += (float)Math.PI * 2;
                }

                //Calculate turningSpeed to maximize speed and minimize jittering
                if (Math.Abs(rotation - wantedRotation) < turningSpeed && turningSpeed > (float)Math.PI / 160)
                {
                    turningSpeed /= 2;
                }
                else if (Math.Abs(rotation - wantedRotation) > turningSpeed && turningSpeed < maxTurningSpeed)
                {
                    turningSpeed *= 2;
                }

                //Apply turningSpeed to rotation in correct direction
                float otherRot = rotation + ((float)Math.PI * 2) * ((rotation > Math.PI) ? -1 : 1); //Same angle, different name to compensate for linear numbers
                float distADir = (float)Math.Abs(wantedRotation - rotation),                        //Archlength sorta from actual rotation
                      distBDir = (float)Math.Abs(wantedRotation - otherRot);                        //Archlength sorta from same angle but 2pi over

                //If the usual angle is closer
                if (distADir < distBDir)
                {
                    //Do normal rotation
                    if (rotation > wantedRotation)
                    {
                        Turn(-1 * turningSpeed);
                    }
                    else if (rotation < wantedRotation)
                    {
                        Turn(turningSpeed);
                    }
                }
                //Otherwise
                else
                {
                    //Do a rotation using the new number, which is able to give the correct turning direction
                    if (otherRot > wantedRotation)
                    {
                        Turn(-1 * turningSpeed);
                    }
                    else if (otherRot < wantedRotation)
                    {
                        Turn(turningSpeed);
                    }
                }
            }
            else
            {
                wantedRotation = rotation;
            }
            #endif

            #endregion

            PosUpdate(mH);

            if (indicator != null)
            {
                //Animation of indicator
                if (timer > endtime)
                {
                    indicator.SetFrameIndex(indicator.GetFrameIndex() + 1);

                    if (indicator.GetFrameIndex() > 5)
                    {
                        indicator.SetFrameIndex(0);
                    }
                    timer = 0;
                }
                else
                {
                    timer += mH.GetGameTime().ElapsedGameTime.TotalSeconds;
                }

                indicator.position = new Vector2(position.X - origin.X, position.Y - origin.Y);
                indicator.Update(mH);
            }

            ChargePower();

#if WINDOWS
            oldState = keyState;
#elif XBOX
            oldState = theState;
            #endif

            originPosition = position + origin;
        }
Ejemplo n.º 4
0
        public override void Update(ManagerHelper mH)
        {
            List <NPC.AffliationTypes> currentContestors = Controllers(mH);

            //Remove old suitors
            for (int i = 0; i < conquestCounters.Count; i++)
            {
                if (!currentContestors.Contains(conquestCounters.Keys.ElementAt(i)))
                {
                    conquestCounters.Remove(conquestCounters.Keys.ElementAt(i));
                    i--;
                }
            }

            foreach (SpawnPoint sP in spawns)
            {
                if (affiliation != NPC.AffliationTypes.grey)
                {
                    sP.affilation = affiliation;
                }
                else
                {
                    sP.affilation = NPC.AffliationTypes.black;
                }
            }

            //Add new suitors
            foreach (NPC.AffliationTypes t in currentContestors)
            {
                if (!conquestCounters.ContainsKey(t))
                {
                    conquestCounters.Add(t, 0);
                }
            }

            if (conquestCounters.Count == 1)
            {
                if (!conquestCounters.Keys.Contains(affiliation))
                {
                    if (conquestCounters.Values.ElementAt(0) > conquestTime)
                    {
                        if (affiliation == NPC.AffliationTypes.grey)
                        {
                            affiliation = conquestCounters.Keys.First();

                            string smokeAsset = "";

                            //Set up image
                            switch (affiliation)
                            {
                            case NPC.AffliationTypes.red:
                                frameIndex = 1;
                                smokeAsset = "Effects/smoke_red";
                                break;

                            case NPC.AffliationTypes.blue:
                                frameIndex = 2;
                                smokeAsset = "Effects/smoke_blue";
                                break;

                            case NPC.AffliationTypes.green:
                                frameIndex = 3;
                                smokeAsset = "Effects/smoke_green";
                                break;

                            case NPC.AffliationTypes.yellow:
                                frameIndex = 4;
                                smokeAsset = "Effects/smoke_yellow";
                                break;
                            }

                            //Spawn Explosion
                            mH.GetParticleManager().AddExplosion(GetOriginPosition(), affiliation, 0);

                            for (int i = 0; i < NUM_SMOKES; i++)
                            {
                                mH.GetParticleManager().AddParticle(smokeAsset, GetOriginPosition(),
                                                                    PathHelper.Direction((float)(mH.GetRandom().NextDouble() * Math.PI * 2)) * 50, 1, 0.01f, 1, 0.05f);
                            }
                        }
                        else
                        {
                            affiliation = NPC.AffliationTypes.grey;
                            frameIndex  = 0;
                            conquestCounters.Clear();

                            //Spawn Explosion
                            mH.GetParticleManager().AddExplosion(GetOriginPosition(), affiliation, 0);
                        }
                    }
                    else
                    {
                        NPC.AffliationTypes tempConquestor = conquestCounters.Keys.ElementAt(0);
                        Double tempTimer = conquestCounters.Values.ElementAt(0);
                        conquestCounters.Remove(tempConquestor);
                        conquestCounters.Add(tempConquestor, tempTimer + mH.GetGameTime().ElapsedGameTime.TotalSeconds);

                        if (mH.GetRandom().NextDouble() < (tempTimer / conquestTime * 0.2f))
                        {
                            mH.GetParticleManager()
                            .AddFire(GetOriginPosition(),
                                     PathHelper.Direction((float)(mH.GetRandom().NextDouble() * Math.PI * 2)) * 50, 1, 0.01f,
                                     1, 0.1f);
                        }
                    }
                }
            }

            base.Update(mH);
        }
Ejemplo n.º 5
0
        public void Set(NPC n, int f, ManagerHelper mH)
        {
            #region Setup

            gutFrame = f;

            string tempAsset = "";

            if (n is Grunt)
            {
                switch (n.GetAffiliation())
                {
                case NPC.AffliationTypes.red:
                    tempAsset = "Effects/Guts/Red/deadGruntRed";
                    break;

                case NPC.AffliationTypes.blue:
                    tempAsset = "Effects/Guts/Blue/deadGruntBlue";
                    break;

                case NPC.AffliationTypes.green:
                    tempAsset = "Effects/Guts/Green/deadGruntGreen";
                    break;

                case NPC.AffliationTypes.yellow:
                    tempAsset = "Effects/Guts/Yellow/deadGruntYellow";
                    break;
                }
            }
            else if (n is Gunner)
            {
                switch (n.GetAffiliation())
                {
                case NPC.AffliationTypes.red:
                    tempAsset = "Effects/Guts/Red/deadGunnerRed";
                    break;

                case NPC.AffliationTypes.blue:
                    tempAsset = "Effects/Guts/Blue/deadGunnerBlue";
                    break;

                case NPC.AffliationTypes.green:
                    tempAsset = "Effects/Guts/Green/deadGunnerGreen";
                    break;

                case NPC.AffliationTypes.yellow:
                    tempAsset = "Effects/Guts/Yellow/deadGunnerYellow";
                    break;
                }
            }
            else if (n is Juggernaut)
            {
                switch (n.GetAffiliation())
                {
                case NPC.AffliationTypes.red:
                    tempAsset = "Effects/Guts/Red/deadJuggRed";
                    break;

                case NPC.AffliationTypes.blue:
                    tempAsset = "Effects/Guts/Blue/deadJuggBlue";
                    break;

                case NPC.AffliationTypes.green:
                    tempAsset = "Effects/Guts/Green/deadJuggGreen";
                    break;

                case NPC.AffliationTypes.yellow:
                    tempAsset = "Effects/Guts/Yellow/deadJuggYellow";
                    break;
                }
            }
            else if (n is Bombardier)
            {
                switch (n.GetAffiliation())
                {
                case NPC.AffliationTypes.red:
                    tempAsset = "Effects/Guts/Red/deadBombRed";
                    break;

                case NPC.AffliationTypes.blue:
                    tempAsset = "Effects/Guts/Blue/deadBombBlue";
                    break;

                case NPC.AffliationTypes.green:
                    tempAsset = "Effects/Guts/Green/deadBombGreen";
                    break;

                case NPC.AffliationTypes.yellow:
                    tempAsset = "Effects/Guts/Yellow/deadBombYellow";
                    break;
                }
            }
            else if (n is Sniper)
            {
                switch (n.GetAffiliation())
                {
                case NPC.AffliationTypes.red:
                    tempAsset = "Effects/Guts/Red/deadSniperRed";
                    break;

                case NPC.AffliationTypes.blue:
                    tempAsset = "Effects/Guts/Blue/deadSniperBlue";
                    break;

                case NPC.AffliationTypes.green:
                    tempAsset = "Effects/Guts/Green/deadSniperGreen";
                    break;

                case NPC.AffliationTypes.yellow:
                    tempAsset = "Effects/Guts/Yellow/deadSniperYellow";
                    break;
                }
            }
            else if (n is Medic)
            {
                switch (n.GetAffiliation())
                {
                case NPC.AffliationTypes.red:
                    tempAsset = "Effects/Guts/Red/deadMedicRed";
                    break;

                case NPC.AffliationTypes.blue:
                    tempAsset = "Effects/Guts/Blue/deadMedicBlue";
                    break;

                case NPC.AffliationTypes.green:
                    tempAsset = "Effects/Guts/Green/deadMedicGreen";
                    break;

                case NPC.AffliationTypes.yellow:
                    tempAsset = "Effects/Guts/Yellow/deadMedicYellow";
                    break;
                }
            }
            else if (n is Specialist)
            {
                switch (n.GetAffiliation())
                {
                case NPC.AffliationTypes.red:
                    tempAsset = "Effects/Guts/Red/deadSpecialistRed";
                    break;

                case NPC.AffliationTypes.blue:
                    tempAsset = "Effects/Guts/Blue/deadSpecialistBlue";
                    break;

                case NPC.AffliationTypes.green:
                    tempAsset = "Effects/Guts/Green/deadSpecialistGreen";
                    break;

                case NPC.AffliationTypes.yellow:
                    tempAsset = "Effects/Guts/Yellow/deadSpecialistYellow";
                    break;
                }
            }
            else if (n is Commander)
            {
                if (n is RedCommander || n is RedPlayerCommander)
                {
                    tempAsset = "Effects/Guts/Red/deadCommanderRed";
                }
                else if (n is BlueCommander || n is BluePlayerCommander)
                {
                    tempAsset = "Effects/Guts/Blue/deadCommanderBlue";
                }
                else if (n is GreenCommander || n is GreenPlayerCommander)
                {
                    tempAsset = "Effects/Guts/Green/deadCommanderGreen";
                }
                else if (n is YellowCommander || n is YellowPlayerCommander)
                {
                    tempAsset = "Effects/Guts/Yellow/deadCommanderYellow";
                }
            }

            Turn(n.GetRotation());

            //Randomly turn right or left
            turnRight = (mH.GetRandom().Next(2) == 0);

            //Make the gun frame move slower
            if (f == 3)
            {
                velocity *= 0.5f;
            }

            #endregion

            base.Set(tempAsset, n.GetOriginPosition(),
                     PathHelper.Direction(n.GetRotation() + (float)(mH.GetRandom().NextDouble() - 0.5)) * n.velocity.Length(),
                     3, 0.05f, 1, 0, mH);

            frameIndex = gutFrame;
        }