Example #1
0
 private void CheckCollision()
 {
     foreach (Entity entity in PlayerManager.EntityManager.Entities.ToList())
     {
         if (Hitbox.Intersects(entity.Hitbox) && entity.PositionZ <= PositionZ + 10 && entity.PositionZ >= PositionZ - 10)
         {
             if (entity.GetType() == typeof(PassBall))
             {
                 PassBall ball = (PassBall)entity;
                 if (!ball.InFlight || ball.SourcePlayer.PlayerIndex != Player.PlayerIndex)
                 {
                     HasBall = true;
                     entity.MarkForDelete = true;
                     PassEffectTimer      = 180;
                     ShootAttack         *= 5;
                 }
             }
         }
     }
 }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            // really just 1?
            //int framesPassed = (int)Math.Ceiling(gameTime.ElapsedGameTime.TotalSeconds * 60F);
            int framesPassed = 1;

            Hitbox.X           = (int)Position.X + HitboxXDisplacement;
            Hitbox.Y           = (int)Position.Y + HitboxYDisplacement - (int)PositionZ;
            PickAggroBox.X     = (int)Hitbox.X - 50;
            PickAggroBox.Y     = (int)Hitbox.Y - 50;
            PickDefendingBox.X = (int)Hitbox.X - 25;
            PickDefendingBox.Y = (int)Hitbox.Y - 25;
            if (PassEffectTimer > 0 && (PassEffectTimer -= framesPassed) <= 0)
            {
                PassEffectTimer = 0;
                ShootAttack    /= 5;
            }
            if (!(CharacterState == CharacterStates.PickState || CharacterState == CharacterStates.StunnedState) && PickHealth < MaxPickHealth)
            {
                PickHealthRegenerationTimer -= framesPassed;
            }
            if (PickHealthRegenerationTimer <= 0)
            {
                PickHealthRegenerationTimer = 60;
                PickHealth += PickHealthRegenerationRate;
                if (PickHealth > MaxPickHealth)
                {
                    PickHealth = MaxPickHealth;
                }
            }
            CheckCollision();
            if (CharacterState != CharacterStates.DamagedState)
            {
                ProcessIncomingDamage();
            }
            if (FacingLeft)
            {
                AttackHitbox.X = (int)(Hitbox.X - AttackRange.X);
            }
            else
            {
                AttackHitbox.X = (int)Position.X + HitboxXDisplacement + Hitbox.Width;
            }
            AttackHitbox.Y = (int)Position.Y + 70;
            CurrentAnimation.Update(gameTime);
            switch (CharacterState)
            {
            case CharacterStates.ShootState:
                if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.ShootMode) != ActionStates.Held)
                {
                    CharacterState = CharacterStates.DefaultState;
                    PlayerManager.GetPlayer(Player.PlayerIndex).Target.Visible = false;
                    break;
                }
                if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Attack) == ActionStates.Pressed)
                {
                    PlayerManager.GetPlayer(Player.PlayerIndex).Target.Visible = false;
                    SelectAnimation(ShootingAnimation);
                    CharacterState = CharacterStates.ShootingState;
                }
                break;

            case CharacterStates.ShootingState:
                StateTimer += framesPassed;
                if (StateTimer == (ShootingAnimation.NumFrames - 1) * ShootingAnimation.Frequency)
                {
                    ShootBall shootBall = new ShootBall(Tint);
                    int       disp      = 150;
                    if (FacingLeft)
                    {
                        disp = 50;
                    }
                    shootBall.SourcePosition      = new Vector2(Position.X + disp, Hitbox.Top);
                    shootBall.DestinationPosition = new Vector2(PlayerManager.GetPlayer(Player.PlayerIndex).Target.Hitbox.Center.X, PlayerManager.GetPlayer(Player.PlayerIndex).Target.Hitbox.Center.Y);
                    shootBall.Velocity.X          = (shootBall.DestinationPosition.X - shootBall.SourcePosition.X) / 60;
                    shootBall.Velocity.Y          = -(shootBall.DestinationPosition.Y - .5F * 60 * 60 / 2 - shootBall.SourcePosition.Y) / 60;
                    shootBall.ReleaseTime         = gameTime.TotalGameTime;
                    PlayerManager.EntityManager.Entities.Add(shootBall);
                }
                if (StateTimer >= ShootingAnimation.NumFrames * ShootingAnimation.Frequency - 1)
                {
                    StateTimer     = 0;
                    CharacterState = CharacterStates.DefaultState;
                }
                break;

            case CharacterStates.PickState:
                Defending = false;
                if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Pick) != ActionStates.Held)
                {
                    CharacterState = CharacterStates.DefaultState;
                    break;
                }

                foreach (Player player in PlayerManager.Players)
                {
                    if (player.Character.Hitbox.Intersects(PickDefendingBox))
                    {
                        Defending = true;
                        break;
                    }
                }
                break;

            case CharacterStates.PassState:
                ProcessMovement(Speed);
                Position += Velocity;
                if (Velocity.X < 0)
                {
                    FacingLeft = true;
                }
                else if (Velocity.X > 0)
                {
                    FacingLeft = false;
                }
                if (Velocity.X != 0 || Velocity.Y != 0)
                {
                    SelectAnimation(RunningAnimation);
                }
                else
                {
                    SelectAnimation(StandingAnimation);
                }
                if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Pass) != ActionStates.Held)
                {
                    CharacterState = CharacterStates.DefaultState;
                    break;
                }

                LinkedListNode <Buttons> passButtonNode = InputManager.PassButtons.First;
                foreach (Player targetPlayer in PlayerManager.Players)
                {
                    if (targetPlayer.PlayerIndex == Player.PlayerIndex)
                    {
                        continue;
                    }
                    if (targetPlayer.Character.CharacterState == CharacterStates.StunnedState)
                    {
                        passButtonNode = passButtonNode.Next;
                        continue;
                    }
                    if (InputManager.GetButtonActionState(Player.PlayerIndex, passButtonNode.Value) == ActionStates.Pressed)
                    {
                        PassBall ball = new PassBall(Tint);
                        ball.Position     = new Vector2(Hitbox.Center.X, Hitbox.Center.Y);
                        ball.SourcePlayer = Player;
                        ball.TargetPlayer = targetPlayer;
                        ball.ReleaseTime  = gameTime.TotalGameTime;
                        PlayerManager.EntityManager.Entities.Add(ball);
                        HasBall = false;
                        //SelectAnimation(StandingAnimation);
                        CharacterState = CharacterStates.DefaultState;
                        passButtonNode = passButtonNode.Next;
                    }
                }
                break;

            case CharacterStates.AttackState:
                StateTimer += framesPassed;
                if (StateTimer >= AttackingAnimation.NumFrames * AttackingAnimation.Frequency)
                {
                    StateTimer     = 0;
                    CharacterState = CharacterStates.DefaultState;
                }
                break;

            case CharacterStates.DamagedState:
                StateTimer += framesPassed;
                //if (StateTimer >= DamagedAnimation.NumFrames * DamagedAnimation.Frequency - 1)
                if (StateTimer >= 20)
                {
                    StateTimer     = 0;
                    CharacterState = CharacterStates.DefaultState;
                }
                break;

            case CharacterStates.StunnedState:
                StateTimer += framesPassed;
                if (StateTimer >= AttackingAnimation.NumFrames * AttackingAnimation.Frequency)
                {
                    StateTimer     = 0;
                    CharacterState = CharacterStates.DefaultState;
                }
                break;

            case CharacterStates.JumpingState:
                StateTimer += framesPassed;
                ProcessMovement(Speed);
                Position.X += Velocity.X;
                PositionZ  += VelocityZ;
                VelocityZ  -= 1F;
                if (PassEffectTimer > 180 - JumpingAnimation.NumFrames * JumpingAnimation.Frequency * (2 / 3) &&
                    InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.ShootMode) == ActionStates.Pressed)
                {
                    // alley oop or dunk or some crazy thing
                }
                if (StateTimer > JumpingAnimation.NumFrames * JumpingAnimation.Frequency)
                {
                    PositionZ      = 0;
                    StateTimer     = 0;
                    CharacterState = CharacterStates.DefaultState;
                }
                break;

            case CharacterStates.DeadState:
                MarkForDelete = true;
                break;

            case CharacterStates.DefaultState:
                ProcessMovement(Speed);
                Position += Velocity;
                if (Velocity.X < 0)
                {
                    FacingLeft = true;
                }
                else if (Velocity.X > 0)
                {
                    FacingLeft = false;
                }
                if (Velocity.X != 0 || Velocity.Y != 0)
                {
                    SelectAnimation(RunningAnimation);
                }
                else
                {
                    SelectAnimation(StandingAnimation);
                }
                if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Pass) == ActionStates.Pressed &&
                    PlayerManager.Players.Count > 1 && HasBall)
                {
                    //SelectAnimation(PassAnimation);
                    CharacterState = CharacterStates.PassState;
                }
                else if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.ShootMode) == ActionStates.Pressed)
                {
                    CharacterState = CharacterStates.ShootState;
                    SelectAnimation(PrimeShotAnimation);
                    int disp;
                    if (FacingLeft)
                    {
                        disp = -5;
                    }
                    else
                    {
                        disp = 5;
                    }
                    PlayerManager.GetPlayer(Player.PlayerIndex).Target.Position = new Vector2(Hitbox.Center.X - 100 / 2 + disp, Hitbox.Center.Y - 100 / 2);
                    PlayerManager.GetPlayer(Player.PlayerIndex).Target.Visible  = true;
                }
                else if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Attack) == ActionStates.Pressed)
                {
                    SelectAnimation(AttackingAnimation);
                    CharacterState = CharacterStates.AttackState;
                }
                else if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Pick) == ActionStates.Pressed)
                {
                    SelectAnimation(PickingAnimation);
                    CharacterState = CharacterStates.PickState;
                }
                else if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Jump) == ActionStates.Pressed)
                {
                    SelectAnimation(JumpingAnimation);
                    VelocityZ      = 1F * JumpingAnimation.NumFrames * JumpingAnimation.Frequency / 2;
                    CharacterState = CharacterStates.JumpingState;
                }
                break;
            }
        }
Example #3
0
        private void ProcessDamage()
        {
            foreach (Player player in PlayerManager.Players)
            {
                if (player.Character.AttackHitbox.Intersects(Hitbox) && player.Character.CharacterState == CharacterStates.AttackState)
                {
                    Health -= 10;
                    if (Health <= 0)
                    {
                        EnemyState = EnemyStates.Dead;
                    }
                    else
                    {
                        SelectAnimation(DamagedAnimation);
                        EnemyState = EnemyStates.Damaged;
                    }
                }
            }
            foreach (Entity entity in PlayerManager.EntityManager.Entities.ToList())
            {
                if (Hitbox.Intersects(entity.Hitbox))
                {
                    if (entity.GetType() == typeof(ShootBall))
                    {
                        ShootBall ball         = (ShootBall)entity;
                        Point     targetCenter = ShootTarget.Sprite.Bounds.Center;
                        if (Hitbox.Contains(ball.DestinationPosition.X + targetCenter.X, ball.DestinationPosition.Y + targetCenter.Y))
                        {
                            // select damaged animation
                            Health -= PlayerManager.GetPlayer(ball.SourcePlayer).Character.ShootAttack;
                            if (Health <= 0)
                            {
                                EnemyState = EnemyStates.Dead;
                            }
                            else
                            {
                                SelectAnimation(DamagedAnimation);
                                EnemyState = EnemyStates.Damaged;
                            }
                        }
                    }

                    //bounce passball
                    if (entity.GetType() == typeof(PassBall))
                    {
                        PassBall ball       = (PassBall)entity;
                        Point    ballCenter = PassBall.Sprite.Bounds.Center;
                        if (Hitbox.Contains(ball.Position.X + ballCenter.X, ball.Position.Y + ballCenter.Y))
                        {
                            //change angle of incidence
                            //maybe swap?
                            float tempX = ball.Velocity.X;
                            float tempY = ball.Velocity.Y;
                            ball.Velocity.X = tempX;
                            ball.Velocity.Y = tempY;
                        }
                    }
                }

                if (DisruptPassHitbox.Intersects(entity.Hitbox))
                {
                    //checks if the passball intersects with swatter's arm
                    if (entity.GetType() == typeof(PassBall))
                    {
                        PassBall ball       = (PassBall)entity;
                        Point    ballCenter = PassBall.Sprite.Bounds.Center;

                        /*if(DisruptPassHitbox.Contains(ball.Position.X + ballCenter.X, ball.Position.Y + ballCenter.Y) && ball.Knocked == false)
                         * {
                         *  EnemyState = EnemyStates.Swat;
                         *  ball.Knocked = true;
                         *  ball.SourcePosition = Position;
                         *  ball.DestinationPosition = PlayerManager.GetPlayer(Player.PlayerIndex).Target.Position;
                         *  ball.Velocity.X = (PlayerManager.GetPlayer(Player.PlayerIndex.get()).Target.Position.X - Position.X) / 60;
                         *  ball.Velocity.Y = -(PlayerManager.GetPlayer(Player.PlayerIndex).Target.Position.Y - .5F * 60 * 60 / 2 - Position.Y) / 60;
                         *
                         * }*/
                    }
                }
            }
        }