private void CheckCollision(TetrisObject[,] target) { foreach (TetrisObject item in target) { if (item.alive && item.Rect.Intersects(shot.Rect)) { TargetHit = true; ShotPos = shot.Pos; shot = null; break; } } }
public void Action(TetrisObject[,] playerOneBlock, TetrisObject[,] playerTwoBlock, InputManager iM, bool gamePad, GameTime gameTime) { if (PlayerIndexBazooka == playerOneIndex) { sender = playerOneBlock; reciever = playerTwoBlock; } else { reciever = playerOneBlock; sender = playerTwoBlock; } Keys fire = Keys.Up; if (!gamePad && PlayerIndexBazooka == playerOneIndex) { fire = Keys.W; } if (gamePad && iM.JustPressed(fireOrb, PlayerIndexBazooka) && !fired) { if (sender != null) { posStartMiddle = new Vector2( (((sender[ sender.GetLength(0) - 1, 0 ].PosX + tileSeize) - (sender[0, 0].PosX)) / 2), (((sender[ sender.GetLength(1) - 1, 0 ].PosY + tileSeize) - (sender[0, 0].PosY)) / 2)); shot = new AnimatedObject(Vector2.Zero, TextureManager.spriteSheetShot, new Point(7, 1)); shot.Pos = sender[0, 0].Pos + posStartMiddle; fired = true; } } if (!gamePad && iM.JustPressed(fire) && !fired) { if (sender != null) { posStartMiddle = new Vector2( (((sender[ sender.GetLength(0) - 1, 0 ].PosX + tileSeize) - (sender[0, 0].PosX)) / 2), (((sender[ sender.GetLength(1) - 1, 0 ].PosY + tileSeize) - (sender[0, 0].PosY)) / 2)); shot = new AnimatedObject(Vector2.Zero, TextureManager.spriteSheetShot, new Point(7, 1)); shot.Pos = sender[0, 0].Pos + posStartMiddle; fired = true; } } if (fired && !TargetHit) { SeekOtherPlayer(reciever); CheckCollision(reciever); } if (shot != null) { shot.CycleSpriteSheet(gameTime); } }