예제 #1
0
        public virtual void Update(GameTime gameTime)
        {
            Player p = entities[0] as Player;

            if (p.SwitchedFromShield)
            {
                for (int j = 0; j < entities.Count; j++)
                {
                    if (entities[j] is Shield)
                    {
                        entities.Remove(entities[j]);
                        j = 0;
                    }
                }
                p.SwitchedFromShield = false;
            }
            for (int i = 0; i < entities.Count; i++)
            {
                if (!entities[i].isDead)
                {
                    if (entities[i] is ChargeBall)
                    {
                        ChargeBall cb = entities[i] as ChargeBall;
                        cb.Update(gameTime, p.Position, p.Rotation);
                    }
                    if (entities[i] is Laser)
                    {
                        Laser l = entities[i] as Laser;
                        l.Update(gameTime, p.Position, p.Rotation);
                    }
                    if (entities[i] is Boss)
                    {
                        Boss b = entities[i] as Boss;
                        b.Update(gameTime, p.Position);
                    }
                    if (entities[i] is ClotSide)
                    {
                        ClotSide cs = entities[i] as ClotSide;
                        cs.Update(gameTime, velocity);
                    }
                    if (entities[i] is Infector)
                    {
                        Infector inf = entities[i] as Infector;
                        inf.Update(gameTime, p.Position);
                    }
                    if (entities[i] is TokenPickup)
                    {
                        TokenPickup tp = entities[i] as TokenPickup;
                        tp.Update(gameTime);
                    }
                    if (entities[i] is PlayerWeapon)
                    {
                        PlayerWeapon w = entities[i] as PlayerWeapon;
                        w.Update(gameTime, p.Position, p.Rotation);
                    }
                    if (entities[i] is BotWeapon)
                    {
                        BotWeapon bw = entities[i] as BotWeapon;
                        bw.Update(gameTime, p.Position, p.Rotation);
                    }
                    if (entities[i] is Shield)
                    {
                        Shield s = entities[i] as Shield;
                        s.Update(gameTime, p.Velocity, p.controls.isPlayerFiring());
                    }
                    if (entities[i] is LatchingCell || entities[i] is MeleeBot || entities[i] is MissileBot)
                    {
                        if (entities[i] is LatchingCell)
                        {
                            LatchingCell lc = entities[i] as LatchingCell;
                            lc.Update(gameTime, p.Position);
                        }
                        else if (entities[i] is MeleeBot)
                        {
                            MeleeBot mb = entities[i] as MeleeBot;
                            mb.Update(gameTime, p.Position);
                        }
                        else
                        {
                            MissileBot missBot = entities[i] as MissileBot;
                            missBot.Update(gameTime, p.Position);
                        }
                    }
                    entities[i].Update(gameTime);
                }
                else
                {
                    if (entities[i] is EnemiesAndPlayer)
                    {
                        EnemiesAndPlayer ep = entities[i] as EnemiesAndPlayer;
                        if (ep.killedBy())
                        {
                            p.addScore(ep.Score);
                            p.AddPowerup(15);
                            if (ep is MeleeBot || ep is MissileBot)
                            {
                                if (random.Next(2) == 0)
                                {
                                    Add(new TokenPickup(content, ep.Position));
                                }
                            }
                        }
                    }
                    entities.Remove(entities[i]);
                }
            }
        }
예제 #2
0
        public override void Update(GameTime gameTime)
        {
            currentWeapon.Update(gameTime, position, rotation);
            if (currentWeapon is Shield)
            {
                Shield s = currentWeapon as Shield;
                s.UpdateWeapFirePosition(Position, Rotation);
            }
            currFireTime       = currFireTime.Subtract(gameTime.ElapsedGameTime);
            betweenDodge       = betweenDodge.Subtract(gameTime.ElapsedGameTime);
            invincibleTime     = invincibleTime.Subtract(gameTime.ElapsedGameTime);
            pressedPowerUpTime = pressedPowerUpTime.Subtract(gameTime.ElapsedGameTime);
            if (isInvincible)
            {
                flickerTime = flickerTime.Subtract(gameTime.ElapsedGameTime);
            }
            if (invincibleTime.TotalSeconds <= 0)
            {
                isInvincible = false;
            }
            if (isPoweredUp)
            {
                powerUpTime = powerUpTime.Subtract(gameTime.ElapsedGameTime);
            }
            if (powerUpTime.TotalSeconds <= 0)
            {
                isPoweredUp = false;
                currentWeapon.CurrentLevel = 0;
            }
            if (cameraEnabled)
            {
                if (!bossMode)
                {
                    Camera.Instance.UpdateCamera(CameraStaticPosition, Vector3.Zero);
                }
                else
                {
                    Camera.Instance.UpdateCamera(position, Vector3.UnitY * rotation.Y);
                }
            }
            sphere   = new BoundingSphere(position, 6);
            worldMat = Matrix.CreateScale(0.1f) * Matrix.CreateRotationY(rotation.Y) * Matrix.CreateRotationZ(rotation.Z) * Matrix.CreateTranslation(position);

            if (!controls.Locked)
            {
                velocity = controls.UpdatePlayerMovement(position, rotation);
            }
            else
            {
                if (initialLock)
                {
                    velocity = new Vector3(0, 0, 1.3f);
                    if (position.Z > 0)
                    {
                        // controls.Locked = false;
                        velocity    = Vector3.Zero;
                        initialLock = false;
                    }
                }
            }

            if (velocity.X != 0.0f && velocity.Z != 0.0f)
            {
                velocity /= (float)Math.Sqrt(2); // don't want diagonal speed to be faster
            }

            if (bossMode)
            {
                oldPos = position;
            }

            if (bossMode && !controls.Locked) //move around the boss when going left/right
            {
                if (velocity.X != 0)
                {
                    velocity = getRotationVelocityAroundPoint(velocity, bossCenter);
                }
            }
            #region Player dodge logic
            if (controls.isPlayerDodgingLeft())
            {
                pressedDodgeLeft  = true;
                pressedDodgeRight = false;
            }
            if (controls.isPlayerDodgingRight())
            {
                pressedDodgeRight = true;
                pressedDodgeLeft  = false;
            }

            if (pressedDodgeLeft && !pressedDodgeRight)
            {
                if (betweenDodge.TotalSeconds <= 0)
                {
                    dodgeTime = dodgeTime.Subtract(gameTime.ElapsedGameTime);
                    if (dodgeTime.TotalSeconds > 0)
                    {
                        velocity = Vector3.UnitX * 5;
                    }
                    else
                    {
                        pressedDodgeLeft = false;
                        dodgeTime        = TimeSpan.FromSeconds(dodgeTimeSeconds);
                        betweenDodge     = TimeSpan.FromSeconds(betweenDodgeSeconds);
                    }
                }
            }

            if (pressedDodgeRight && !pressedDodgeLeft)
            {
                if (betweenDodge.TotalSeconds <= 0)
                {
                    dodgeTime = dodgeTime.Subtract(gameTime.ElapsedGameTime);
                    if (dodgeTime.TotalSeconds > 0)
                    {
                        velocity = -Vector3.UnitX * 5;
                    }
                    else
                    {
                        pressedDodgeRight = false;
                        dodgeTime         = TimeSpan.FromSeconds(dodgeTimeSeconds);
                        betweenDodge      = TimeSpan.FromSeconds(betweenDodgeSeconds);
                    }
                }
            }
            #endregion

            position += velocity;
            #region Player rotation while moving
            if (velocity.X < 0)
            {
                if (rotation.Z == 0 || rotation.Z > MathHelper.ToRadians(180))
                {
                    rotate(new Vector3(0, 0, MathHelper.ToRadians(3)));
                }
                else
                {
                    if (rotation.Z > 0 && rotation.Z <= MathHelper.ToRadians(180))
                    {
                        if (rotation.Z < MathHelper.ToRadians(30))
                        {
                            rotate(new Vector3(0, 0, MathHelper.ToRadians(3)));
                        }
                    }
                }
            }
            else if (velocity.X > 0)
            {
                if (rotation.Z == 0 || rotation.Z > 0 && rotation.Z <= MathHelper.ToRadians(180))
                {
                    rotate(new Vector3(0, 0, -MathHelper.ToRadians(3)));
                }
                else
                {
                    if (rotation.Z > MathHelper.ToRadians(180))
                    {
                        if (rotation.Z > MathHelper.ToRadians(330))
                        {
                            rotate(new Vector3(0, 0, -MathHelper.ToRadians(3)));
                        }
                    }
                }
            }
            else
            {
                if (rotation.Z > 0 && rotation.Z <= MathHelper.ToRadians(180))
                {
                    rotate(new Vector3(0, 0, -MathHelper.ToRadians(3)));
                }
                else if (rotation.Z > MathHelper.ToRadians(180))
                {
                    rotate(new Vector3(0, 0, MathHelper.ToRadians(3)));
                }
                if (MathHelper.ToDegrees(rotation.Z) < 3)
                {
                    rotation.Z = 0;
                }
            }
            #endregion

            if (position.X > 60)
            {
                position.X = 60;
            }
            if (position.X < -60)
            {
                position.X = -60;
            }

            if (!controls.Locked)
            {
                if (position.Z < -40)
                {
                    position.Z = -40;
                }
                if (position.Z > 40)
                {
                    position.Z = 40;
                }
            }

            if (controls.isPlayerFiring())
            {
                //is the player allowed to fire again since his last fire?
                if (currFireTime.TotalSeconds <= 0)
                {
                    //Reset current time
                    currFireTime = TimeSpan.FromTicks(currentWeapon.FireTime.Ticks);
                    fire();
                }
            }

            if (controls.isPlayerUsingPowerup())
            {
                if (pressedPowerUpTime.TotalSeconds <= 0)
                {
                    if (!isPoweredUp)
                    {
                        if (powerup < 394)
                        {
                            playerAVC.playSoundEffect("cancel", 1);
                        }
                        else
                        {
                            isPoweredUp = true;
                            powerUpTime = TimeSpan.FromSeconds(powerupTimeSeconds);
                            if (powerup >= 394 && powerup < 788)
                            {
                                currentWeapon.CurrentLevel = 1;
                                powerup -= 394;
                            }
                            else if (powerup >= 788 && powerup < 1182)
                            {
                                currentWeapon.CurrentLevel = 2;
                                powerup -= 788;
                            }
                            else
                            {
                                currentWeapon.CurrentLevel = 3;
                                powerup -= 1182;
                            }
                        }
                    }
                    pressedPowerUpTime = TimeSpan.FromSeconds(pressedPowerUpTimeSeconds);
                }
            }
            if (Game1.debug)
            {
                if (controls.isPlayerPowering(gameTime))
                {
                    if (currentWeapon.CurrentLevel < 3)
                    {
                        currentWeapon.CurrentLevel++;
                    }
                    else
                    {
                        currentWeapon.CurrentLevel = 0;
                    }
                }

                if (controls.isPlayerSwitching(gameTime))
                {
                    int loc = Array.IndexOf(weapList, currentWeapon.Name.ToString());
                    if (loc < weapList.Length - 1)
                    {
                        changeWeapon((PlayerWeaponName)Enum.Parse(typeof(PlayerWeaponName), weapList[loc + 1], true));
                    }
                    else
                    {
                        changeWeapon((PlayerWeaponName)Enum.Parse(typeof(PlayerWeaponName), weapList[0], true));
                    }
                }
            }
        }