public void CheckCollision(BB_Character checkingPlayer, int counter)
        {
            for (int i = 0; i < characters.Length; i++)
            {
                if (counter != i)
                {
                    if (characters[i] != null && !characters[i].isInvulnerable)
                    {
                        if (checkingPlayer.collides(characters[i]))
                        {
                            //if (checkingPlayer.velocity == Vector2.Zero)
                            Vector2 knockDir = characters[i].position - checkingPlayer.position;
                            knockDir.Normalize();

                            checkingPlayer.knockDirection =  -1 * characters[i].velocity.Length() * knockDir;
                            characters[i].knockDirection = checkingPlayer.velocity.Length() * knockDir;

                            soundBank.PlayCue("Collision");
                            characters[i].CurrentAction = BB_Character.Action.Knockback;
                            checkingPlayer.CurrentAction = BB_Character.Action.Knockback;
                        }
                    }
                }
            }
        }
Exemple #2
0
 public bool collides(BB_Character otherPlayer)
 {
     if(Vector2.Distance(position + size/2 ,otherPlayer.position + ((otherPlayer.size)/2)) <= size.Y ){
          return true;
      }
     return false;
 }
        private void PlayerInput(BB_Character player, GamePadState padState, Keys up, Keys down, Keys right, Keys left, float elapsedTime)
        {
            if (player.isInvulnerable)
                player.CurrentAction = BB_Character.Action.Knockback;
            else if (player.dying)
            {
                //Dont allow input
            }
            else
            {
                if (player.velocity.Length() <= 4)
                {
                    //player.velocity = new Vector2(0, 0);
                    if (currentKeyboardState.IsKeyDown(left) || padState.IsButtonDown(Buttons.DPadLeft))
                    {
                        player.velocity += new Vector2(-ACCELERATION, 0);
                    }
                    if (currentKeyboardState.IsKeyDown(down) || padState.IsButtonDown(Buttons.DPadDown))
                    {
                        player.velocity += new Vector2(0, ACCELERATION);
                    }
                    if (currentKeyboardState.IsKeyDown(right) || padState.IsButtonDown(Buttons.DPadRight))
                    {
                        player.velocity += new Vector2(ACCELERATION, 0);
                    }
                    if (currentKeyboardState.IsKeyDown(up) || padState.IsButtonDown(Buttons.DPadUp))
                    {
                        player.velocity += new Vector2(0, -ACCELERATION);

                    }
                }

                //Check for max speed and normalize
                if (player.velocity.Length() >= MAX_SPEED)
                {
                    player.velocity.Normalize();
                    player.velocity = new Vector2(player.velocity.X * MAX_SPEED, player.velocity.Y * MAX_SPEED);
                }

                //Will check for no actiona and dampen out the speed
                if (!(currentKeyboardState.IsKeyDown(up) || padState.IsButtonDown(Buttons.DPadUp) ||
                    currentKeyboardState.IsKeyDown(right) || padState.IsButtonDown(Buttons.DPadRight) ||
                    currentKeyboardState.IsKeyDown(down) || padState.IsButtonDown(Buttons.DPadDown) ||
                    currentKeyboardState.IsKeyDown(left) || padState.IsButtonDown(Buttons.DPadLeft)))
                {
                    if (player.velocity.Length() != 0.0)
                    {
                        player.velocity += -player.velocity / DAMPENER;
                    }
                }
                player.CurrentAction = BB_Character.Action.Run;
            }
        }
        public void LoadContent(ContentManager Content, Vector2 center)
        {
            characters = new BB_Character[4];
            audioEngine = new AudioEngine(@"Content\Character\LumberjackBustle.xgs");

            waveBank = new WaveBank(audioEngine, @"Content\Character\Wave Bank.xwb");
            soundBank = new SoundBank(audioEngine, @"Content\Character\Sound Bank.xsb");

            players[0].sprite = Content.Load<Texture2D>(@"Character\BlueKnightSpriteSheet");
            players[1].sprite = Content.Load<Texture2D>(@"Character\PinkKnightSpriteSheet");
            players[2].sprite = Content.Load<Texture2D>(@"Character\BlackKnightSpriteSheet");
            players[3].sprite = Content.Load<Texture2D>(@"Character\GreenKnightSpriteSheet");
            characters[0] = new BB_Character();
            characters[1] = new BB_Character();
            characters[2] = new BB_Character();
            characters[3] = new BB_Character();

            int count1 = 1;
            int count2 = 1;
            for (int i = 1; i < 4; i++)
            {
                if (players[i] != null)
                {
                    if (players[i].Score > players[id1].Score)
                    {
                        id1 = i;
                    }
                    else if (players[i].Score < players[id2].Score)
                    {
                        id2 = i;
                    }
                    if (id1 == id2)
                    {
                        id2++;
                    }
                }
            }
            for (int i = 0; i < 4; i++)
            {
                if (i == id1 || i == id2)
                {
                    characters[i].Initialize(players[i].sprite,
                                    center + new Vector2(count1 * 100, -100),
                                    Vector2.Zero);
                    characters[i].team = 0;
                    count1 = -1;
                }
                else
                {
                    characters[i].Initialize(players[i].sprite,
                        center + new Vector2(count2 * 100, 100),
                        Vector2.Zero);
                    characters[i].team = 1;
                    count2 = -1;
                }
            }
        }