예제 #1
0
 /// <summary>
 ///   Helper for checking if a button was newly pressed during this update.
 /// </summary>
 public bool IsNewButtonPress(Buttons button)
 {
     return(GamePadState.IsButtonDown(button) && PreviousGamePadState.IsButtonUp(button));
 }
예제 #2
0
        public override void Update(GameTime gameTime)
        {
            PreviousPose          = CurrentPose;
            PreviousFacing        = CurrentFacing;
            PreviousGamePadState  = CurrentGamePadState;
            PreviousKeyboardState = CurrentKeyboardState;
            PreviousMouseState    = CurrentMouseState;
            WasShooting           = IsShooting;

            if (Active == true)
            {
                HealthBar.Update(Health);
                SpecialBar.Update(new Vector2(87, 100));

                foreach (Emitter emitter in FlashEmitterList)
                {
                    emitter.Position.X = BarrelEnd.X;
                    emitter.Update(gameTime);
                }
                FlashEmitterList.RemoveAll(Emitter => Emitter.Active == false);

                foreach (Emitter emitter in EmitterList)
                {
                    //emitter.Position = Position;
                    emitter.Update(gameTime);
                }
                EmitterList.RemoveAll(Emitter => Emitter.Active == false);

                #region Control States
                CurrentGamePadState  = GamePad.GetState(PlayerIndex);
                CurrentKeyboardState = Keyboard.GetState();
                CurrentMouseState    = Mouse.GetState();

                Sticks    = CurrentGamePadState.ThumbSticks;
                MoveStick = Sticks.Left;
                AimStick  = Sticks.Right;
                #endregion

                #region Jump
                if (CurrentGamePadState.IsButtonDown(CurrentJumpButton) &&
                    PreviousGamePadState.IsButtonUp(CurrentJumpButton) &&
                    DoubleJumped == false)
                {
                    NumJumps++;

                    if (InAir == true)
                    {
                        DoubleJumped = true;
                        Velocity.Y  -= 15f;
                    }
                    else
                    {
                        //NOT SURE ABOUT HAVING BOTH THIS AND THE SMOKE PUFF WHEN LANDING.
                        //I LIKE THE SMOKE MORE SO I'M LEAVING THIS OUT FOR NOW

                        //Emitter jumpEmitter1 = new Emitter(Game1.HitEffectParticle, new Vector2(Position.X + 5, Position.Y + DestinationRectangle.Height / 2),
                        //     new Vector2(90, 180), new Vector2(5, 8), new Vector2(500, 500), 1f, false, new Vector2(0, 0),
                        //     new Vector2(0, 0), new Vector2(0.1f, 0.1f), Color.White, Color.White, 0f, 0.1f, 100, 5, false,
                        //     Vector2.Zero, true, null, null, null, null, null, null, true, new Vector2(0.15f, 0.15f), null, null, null, null, null, true);


                        //Emitter jumpEmitter2 = new Emitter(Game1.HitEffectParticle, new Vector2(Position.X + 5, Position.Y + DestinationRectangle.Height / 2),
                        //    new Vector2(0, 90), new Vector2(5, 8), new Vector2(500, 500), 1f, false, new Vector2(0, 0),
                        //    new Vector2(0, 0), new Vector2(0.1f, 0.1f), Color.White, Color.White, 0f, 0.1f, 100, 5, false,
                        //    Vector2.Zero, true, null, null, null, null, null, null, true, new Vector2(0.15f, 0.15f), null, null, null, null, null, true);

                        //EmitterList.Add(jumpEmitter1);
                        //EmitterList.Add(jumpEmitter2);

                        Velocity.Y = -15f;
                    }
                }
                #endregion

                if (CurrentGamePadState.IsButtonDown(Buttons.LeftStick) &&
                    PreviousGamePadState.IsButtonUp(Buttons.LeftStick))
                {
                    Health.X = 0;
                }

                #region Move stick left
                if (MoveStick.X < -0.15f)
                {
                    AimDirection.X = -1f;
                    CurrentFacing  = Facing.Left;
                }
                #endregion

                #region Move stick right
                if (MoveStick.X > 0.15f)
                {
                    AimDirection.X = 1f;
                    CurrentFacing  = Facing.Right;
                }
                #endregion

                if (Math.Abs(MoveStick.X) > 0.15f)
                {
                    Velocity.X += (MoveStick.X * 3f);
                }

                if (CurrentPose == Pose.Standing)
                {
                    Size = new Vector2(59, 98);
                }
                else
                {
                    Size = new Vector2(59, 74);
                }

                Velocity.Y += Gravity * ((float)gameTime.ElapsedGameTime.TotalSeconds * 60f);

                base.Update(gameTime);

                #region Collision Reactions
                if (PushesBottomTile == true)
                {
                    if (InAir == true)
                    {
                        Emitter jumpEmitter1 = new Emitter(Game1.ToonSmoke1, new Vector2(Position.X - 2, Position.Y + DestinationRectangle.Height / 2),
                                                           new Vector2(110, 180), new Vector2(2, 5), new Vector2(300, 500), 1f, false, new Vector2(-7, 7),
                                                           new Vector2(0, 0), new Vector2(0.03f, 0.05f), Color.White, Color.White, 0f, 0.1f, 100, 9, false,
                                                           Vector2.Zero, true, null, null, null, null, null, null, false, new Vector2(0.08f, 0.08f), null, null, null, false, false, true);

                        Emitter jumpEmitter2 = new Emitter(Game1.ToonSmoke1, new Vector2(Position.X + 2, Position.Y + DestinationRectangle.Height / 2),
                                                           new Vector2(20, 90), new Vector2(2, 5), new Vector2(300, 500), 1f, false, new Vector2(-7, 7),
                                                           new Vector2(0, 0), new Vector2(0.03f, 0.05f), Color.White, Color.White, 0f, 0.1f, 100, 9, false,
                                                           Vector2.Zero, true, null, null, null, null, null, null, false, new Vector2(0.08f, 0.08f), null, null, null, false, false, true);


                        EmitterList.Add(jumpEmitter1);
                        EmitterList.Add(jumpEmitter2);
                    }

                    Velocity.Y   = 0;
                    InAir        = false;
                    DoubleJumped = false;
                }
                else
                {
                    InAir = true;
                }

                if (PushesTopTile == true)
                {
                    Velocity.Y = 0;
                }

                if (PushesLeftTile == true ||
                    PushesRightTile == true)
                {
                    Velocity.X = 0;
                }
                #endregion

                #region Stop Moving
                if (MoveStick.X == 0)
                {
                    if (InAir == false)
                    {
                        Velocity.X = 0f;
                    }
                    else
                    {
                        Velocity.X *= 0.98f;
                    }
                }
                #endregion

                #region Limit Speed
                if (Velocity.X > MaxSpeed.X)
                {
                    Velocity.X = MaxSpeed.X;
                }

                if (Velocity.X < -MaxSpeed.X)
                {
                    Velocity.X = -MaxSpeed.X;
                }

                //if (Velocity.Y < -25)
                //{
                //    Velocity.Y = -25;
                //}

                //if (Velocity.Y > 25)
                //{
                //    Velocity.Y = 25;
                //}
                #endregion

                Shoot(gameTime);

                #region Grenade
                if (GrenadeTiming.X >= GrenadeTiming.Y)
                {
                    if (CurrentGamePadState.IsButtonDown(CurrentGrenadeButton) &&
                        PreviousGamePadState.IsButtonUp(CurrentGrenadeButton))
                    {
                        CreatePlayerGrenade();
                        GrenadeTiming.X = 0;

                        if (CurrentGrenade != GrenadeType.Regular)
                        {
                            GrenadeAmmo--;

                            if (GrenadeAmmo == 0)
                            {
                                CurrentGrenade = GrenadeType.Regular;
                            }
                        }
                    }
                }
                else
                {
                    GrenadeTiming.X += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                }
                #endregion

                #region Trap
                if (CurrentGamePadState.IsButtonDown(CurrentTrapButton) &&
                    PreviousGamePadState.IsButtonUp(CurrentTrapButton))
                {
                    if (TrapAmmo > 0)
                    {
                        //CreatePlaceTrap(Position, TrapType.Mine);
                        CreatePlaceTrap();
                    }
                }
                #endregion

                #region Change Animation Direction
                switch (CurrentFacing)
                {
                    #region Left
                case Facing.Left:
                {
                    AimDirection = new Vector2(-1, 0);

                    if (InAir == false)
                    {
                        if (Velocity.X != 0)
                        {
                            CurrentAnimation = RunLeftAnimation;
                        }
                        else
                        {
                            if (CurrentPose == Pose.Standing)
                            {
                                CurrentAnimation = StandLeftAnimation;
                            }
                            else
                            {
                                CurrentAnimation = CrouchLeftAnimation;
                            }
                        }
                    }
                    else
                    {
                        if (Velocity.Y > 2)
                        {
                            CurrentAnimation = JumpLeftDownAnimation;
                        }
                        else
                        {
                            CurrentAnimation = JumpLeftAnimation;
                        }
                    }
                }
                break;
                    #endregion

                    #region Right
                case Facing.Right:
                {
                    AimDirection = new Vector2(1, 0);

                    if (InAir == false)
                    {
                        if (Velocity.X != 0)
                        {
                            CurrentAnimation = RunRightAnimation;
                        }
                        else
                        {
                            if (CurrentPose == Pose.Standing)
                            {
                                CurrentAnimation = StandRightAnimation;
                            }
                            else
                            {
                                CurrentAnimation = CrouchRightAnimation;
                            }
                        }
                    }
                    else
                    {
                        if (Velocity.Y > 2)
                        {
                            CurrentAnimation = JumpRightDownAnimation;
                        }
                        else
                        {
                            CurrentAnimation = JumpRightAnimation;
                        }
                    }
                }
                break;
                    #endregion
                }
                #endregion

                DestinationRectangle = new Rectangle((int)(Position.X - CurrentAnimation.FrameSize.X / 2),
                                                     (int)(Position.Y - CurrentAnimation.FrameSize.Y / 2),
                                                     (int)CurrentAnimation.FrameSize.X,
                                                     (int)CurrentAnimation.FrameSize.Y);

                BoundingBox = new BoundingBox(new Vector3(Position - (CurrentAnimation.FrameSize / 2), 0),
                                              new Vector3(Position + (CurrentAnimation.FrameSize / 2), 0));

                #region Update Animations
                if (CurrentAnimation != null)
                {
                    CurrentAnimation.Position = Position;
                    CurrentAnimation.Update(gameTime, DestinationRectangle);
                }
                #endregion

                #region Item Collisions
                if (ItemList != null)
                {
                    ItemList.ForEach(Item =>
                    {
                        bool removeItem = true;

                        if (Item.CollisionRectangle.Intersects(CollisionRectangle))
                        {
                            switch (Item.ItemType)
                            {
                            case ItemType.Shield:
                                {
                                    ShieldActive = true;
                                    removeItem   = true;
                                }
                                break;

                            case ItemType.Shotgun:
                                {
                                    CurrentGun = GunType.Shotgun;
                                    ShotTiming = new Vector2(0, 1000);
                                    removeItem = true;
                                }
                                break;

                            case ItemType.RocketLauncher:
                                {
                                    CurrentGun = GunType.RocketLauncher;
                                    ShotTiming = new Vector2(0, 2000);
                                    removeItem = true;
                                }
                                break;

                            case ItemType.MachineGun:
                                {
                                    ShotTiming = new Vector2(0, 200);
                                    CurrentGun = GunType.MachineGun;
                                    removeItem = true;
                                }
                                break;
                            }

                            if (removeItem == true)
                            {
                                ItemList.Remove(Item);
                            }
                        }
                    });
                }
                #endregion

                #region Trap Collisions
                if (TrapList != null)
                {
                    TrapList.ForEach(Trap =>
                    {
                        if (Trap.Active == true)
                        {
                            switch (Trap.TrapType)
                            {
                            case TrapType.TripMine:
                                {
                                    if ((Trap as TripMine).SourcePlayer != this && (Trap as TripMine).Laser.Ray.Intersects(BoundingBox) != null)
                                    {
                                        //Mine was triggered. Time to explode
                                        Health.X   -= 50;
                                        Trap.Active = false;
                                    }
                                }
                                break;
                            }
                        }

                        //if (Trap.Active == true && Trap.CollisionRectangle.Intersects(CollisionRectangle))
                        //{
                        //    //switch (Trap.TrapType)
                        //    //{
                        //    //#region Fire
                        //    //case TrapType.Fire:
                        //    //        {

                        //    //        }
                        //    //        break;
                        //    //    #endregion
                        //    //}

                        //    Health.X -= 20;
                        //    Trap.Reset();
                        //}
                    });
                }
                #endregion

                #region Projectile Collisions
                if (ProjectileList != null)
                {
                    ProjectileList.ForEach(Projectile =>
                    {
                        if (Projectile.PlayerIndex != PlayerIndex &&
                            Projectile.CollisionRectangle.Intersects(CollisionRectangle))
                        {
                            LastDamageSource = (int)Projectile.PlayerIndex;

                            Projectile.Active = false;

                            if (ShieldActive == true)
                            {
                                ShieldActive = false;
                            }
                            else
                            {
                                Health.X = 0;
                            }
                        }
                    });
                }
                #endregion

                #region Player Died
                if (Health.X <= 0)
                {
                    //#region Flag behaviour
                    //switch (CurrentFlagState)
                    //{
                    //    case FlagState.NoFlag:
                    //        break;

                    //    case FlagState.HasRed:
                    //        {
                    //            RedFlag replacementFlag = new RedFlag() { Position = Position };
                    //            replacementFlag.Initialize();

                    //            ItemList.Add(replacementFlag);
                    //            CurrentFlagState = FlagState.NoFlag;
                    //        }
                    //        break;

                    //    case FlagState.HasBlue:
                    //        {
                    //            BlueFlag replacementFlag = new BlueFlag() { Position = Position };
                    //            replacementFlag.Initialize();

                    //            ItemList.Add(replacementFlag);
                    //            CurrentFlagState = FlagState.NoFlag;
                    //        }
                    //        break;
                    //}
                    //#endregion

                    Deaths++;
                    IsShooting  = false;
                    WasShooting = false;
                    CreatePlayerDied();
                    UnscrambleButtons();
                }
                #endregion

                #region Debuffs
                if (_CurrentDebuff.Active == true)
                {
                    _CurrentDebuff.Update(gameTime);

                    //The debuff has expired based on the previous Update
                    if (_CurrentDebuff.Active == false)
                    {
                        switch (_CurrentDebuff.DebuffType)
                        {
                        case DebuffType.ScrambleButtons:
                        {
                            UnscrambleButtons();
                        }
                        break;
                        }
                    }
                }
                #endregion

                BarrelEnd = Position + new Vector2(AimDirection.X * 28, 10);
            }
        }
예제 #3
0
 public bool GamepadButtonPressed(Buttons button)
 {
     return(CurrentGamePadState.IsButtonDown(button) && PreviousGamePadState.IsButtonUp(button));
 }
예제 #4
0
        public void Shoot(GameTime gameTime)
        {
            switch (CurrentGun)
            {
                #region RocketLauncher
            case GunType.RocketLauncher:
            {
                if (PreviousGamePadState.IsButtonUp(CurrentShootButton) &&
                    CurrentGamePadState.IsButtonDown(CurrentShootButton))
                {
                    switch (CurrentFacing)
                    {
                    case Facing.Left:
                        OnPlayerShootHappened(new Vector2(-35, 0));
                        //CreatePlayerShoot(new Vector2(-35, 0));
                        break;

                    case Facing.Right:
                        //CreatePlayerShoot(new Vector2(35, 0));
                        OnPlayerShootHappened(new Vector2(35, 0));
                        break;
                    }

                    NumShots++;
                }
            }
            break;
                #endregion

                #region Shotgun
            case GunType.Shotgun:
            {
                if (PreviousGamePadState.IsButtonUp(CurrentShootButton) &&
                    CurrentGamePadState.IsButtonDown(CurrentShootButton))
                {
                    Vector2 direction = Vector2.Zero;

                    switch (CurrentFacing)
                    {
                    case Facing.Left:
                        direction = new Vector2(-1, 0);
                        break;

                    case Facing.Right:
                        direction = new Vector2(1, 0);
                        break;
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        float angle = MathHelper.ToRadians((float)Math.Atan2(direction.Y, direction.X) + Random.Next(-15, 15));

                        direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * AimDirection.X;

                        LightProjectile newProjectile = new ShotgunProjectile(BarrelEnd, direction, 1);
                        CreateLightProjectile(newProjectile, this);
                    }

                    NumShots++;
                }
            }
            break;
                #endregion

                #region MachineGun
            case GunType.MachineGun:
            {
                if (ShotTiming.X < ShotTiming.Y)
                {
                    ShotTiming.X += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                }

                if (PreviousGamePadState.IsButtonDown(CurrentShootButton) &&
                    CurrentGamePadState.IsButtonDown(CurrentShootButton) &&
                    ShotTiming.X >= ShotTiming.Y)
                {
                    Vector2 direction = Vector2.Zero;

                    switch (CurrentFacing)
                    {
                    case Facing.Left:
                        direction = new Vector2(-1, 0);
                        break;

                    case Facing.Right:
                        direction = new Vector2(1, 0);
                        break;
                    }

                    //float angle = MathHelper.ToRadians((float)Math.Atan2(direction.Y, direction.X) + Random.Next(-15, 15));
                    float thing = Random.Next(-2, 2);
                    direction = new Vector2(MathHelper.ToRadians((float)Math.Cos(thing)), MathHelper.ToRadians((float)Math.Sin(thing))) + AimDirection;

                    LightProjectile newProjectile = new MachineGunProjectile(BarrelEnd, direction, 1);
                    CreateLightProjectile(newProjectile, this);

                    ShotTiming.X = 0;
                    NumShots++;
                }
            }
            break;
                #endregion
            }
        }
예제 #5
0
 /// <summary>
 /// Gets whether the given button was just pressed down.
 /// </summary>
 /// <param name="button">The given button.</param>
 /// <returns>True if the button was just pressed down, false otherwise.</returns>
 public static bool GetButtonDown(Buttons button)
 {
     return(PreviousGamePadState.IsButtonUp(button) && CurrentGamePadState.IsButtonDown(button));
 }