public bool CheckCollision(Tank tank, int x, int y, int width, int height) { if (Collision.CollisionWithBorders(tank, width, height)) { NewDirection(tank); tank.PosX -= x; tank.PosY -= y; } foreach (Block block in BlockModel.GetBlocks()) { if (Collision.CollisionBox(tank, block) && block.IsEnabled) { NewDirection(tank); tank.PosX -= x; tank.PosY -= y; } } foreach (Tank el in tanks) { if (el != tank && Collision.CollisionBox(tank, el)) { tank.PosX -= x; tank.PosY -= y; switch (tank.Direction) { case Direction.Left: tank.Direction = Direction.Right; break; case Direction.Up: tank.Direction = Direction.Down; break; case Direction.Right: tank.Direction = Direction.Left; break; case Direction.Down: tank.Direction = Direction.Up; break; } } } if (Collision.CollisionBox(BallModel.GetBall(), tank)) { return(true); } return(false); }
public bool MoveBullet(int width, int height) { if (ball.Bullet.IsEnable) { MoveBullet(ball.Bullet); if (Collision.CollisionWithBorders(ball.Bullet, width, height)) { ball.Bullet.IsEnable = false; ball.Bullet.wasDisabled = DateTime.Now; } foreach (Block block in BlockModel.GetBlocks()) { if (Collision.CollisionBox(ball.Bullet, block) && block.IsEnabled) { ball.Bullet.IsEnable = false; ball.Bullet.wasDisabled = DateTime.Now; if (block.Name == "b") { block.IsEnabled = false; } } } foreach (Tank tank in TankModel.GetTanks()) { if (Collision.CollisionBox(ball.Bullet, tank) && tank.IsEnable) { ball.Bullet.IsEnable = false; ball.Bullet.wasDisabled = DateTime.Now; tank.IsEnable = false; tank.PosX = -tank.Size; return(true); } if (Collision.CollisionBox(ball.Bullet, tank.Bullet)) { ball.Bullet.IsEnable = false; tank.Bullet.IsEnable = false; ball.Bullet.wasDisabled = DateTime.Now; tank.Bullet.wasDisabled = DateTime.Now; tank.Bullet.PosX = -tank.Size; ball.Bullet.PosX = -ball.Size; } } } return(false); }
public void CheckCollision(int x, int y, int width, int height) { if (Collision.CollisionWithBorders(ball, width, height)) { ball.PosX -= x; ball.PosY -= y; } foreach (Block block in BlockModel.GetBlocks()) { if (Collision.CollisionBox(ball, block) && block.IsEnabled) { ball.PosX -= x; ball.PosY -= y; } } }
public void CreateApple(int num, int size, int width, int height) { while (apples.Count < num) { bool canBePlaced = true; do { canBePlaced = true; apples.Add(new Apple(rnd.Next(width - size), rnd.Next(height - size), size)); foreach (Block block in BlockModel.GetBlocks()) { if (apples.Count > 0 && Collision.CollisionBox(apples.Last(), block)) { canBePlaced = false; apples.Remove(apples.Last()); } } } while (!canBePlaced); } }
public bool MoveBullet(int width, int height) { foreach (Tank tank in tanks) { if (tank.Bullet.IsEnable) { MoveBullet(tank, tank.Bullet); if (Collision.CollisionWithBorders(tank.Bullet, width, height)) { tank.Bullet.IsEnable = false; tank.Bullet.PosX = -tank.Size; tank.Bullet.wasDisabled = DateTime.Now; } if (Collision.CollisionBox(tank.Bullet, BallModel.GetBall())) { return(true); } foreach (Block block in BlockModel.GetBlocks()) { if (Collision.CollisionBox(tank.Bullet, block) && block.IsEnabled) { tank.Bullet.IsEnable = false; tank.Bullet.PosX = -tank.Size; tank.Bullet.wasDisabled = DateTime.Now; if (block.Name == "b") { block.IsEnabled = false; } } } foreach (Tank el in tanks) { if (el != tank) { if (Collision.CollisionBox(tank.Bullet, el)) { tank.Bullet.IsEnable = false; tank.Bullet.PosX = -tank.Size; tank.Bullet.wasDisabled = DateTime.Now; } if (Collision.CollisionBox(tank.Bullet, el.Bullet)) { tank.Bullet.IsEnable = false; tank.Bullet.PosX = -tank.Size; el.Bullet.IsEnable = false; el.Bullet.PosX = -el.Size; tank.Bullet.wasDisabled = DateTime.Now; el.Bullet.wasDisabled = DateTime.Now; } } } } } return(false); }