public void CheckCollision(Duel_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 = Duel_Character.Action.Knockback; checkingPlayer.CurrentAction = Duel_Character.Action.Knockback; } } } } }
public bool collides(Duel_Character otherPlayer) { if(Vector2.Distance(position + size/2 ,otherPlayer.position + ((otherPlayer.size)/2)) <= size.Y ){ return true; } return false; }
private void PlayerInput(Duel_Character player, GamePadState padState, Keys up, Keys down, Keys right, Keys left, float elapsedTime, int auto) { player.velocity = new Vector2(-ACCELERATION, 0); if (player.isInvulnerable) player.CurrentAction = Duel_Character.Action.Knockback; else if (player.dying) { //Dont allow input } else { if (player.velocity.Length() <= 4) { if (currentKeyboardState.IsKeyDown(up) || padState.IsButtonDown(currentButton) || (auto == 1 && player.pushed == false)) { if (!player.pushed) { //player.CurrentAction = Duel_Character.Action.Knockback; player.ChangeFrames(1000.0f); player.velocity = new Vector2(MAX_SPEED, 0); } player.pushed = true; } else { player.pushed = false; } } } }
public void LoadContent(ContentManager Content, Vector2 center) { characters = new Duel_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"); for (int i = 1; i < 4; i++) { if (players[i] != null ) { if (players[i].Score > players[id1].Score) { id2 = id1; id1 = i; } else if (i == 1) { id2 = i; } else if (players[i].Score > players[id2].Score) { id2 = i; } } } characters[id1] = new Duel_Character(); characters[id1].Initialize(players[id1].sprite, center + new Vector2(400, 0), Vector2.Zero); characters[id1].team = 0; characters[id2] = new Duel_Character(); characters[id2].Initialize(players[id2].sprite, center + new Vector2(-400, 0), Vector2.Zero); characters[id2].team = 1; characters[id2].effect = SpriteEffects.FlipHorizontally; }