public bool CheckCollision(Apple apple)
        {
            if (Collision.CollisionBox(BallModel.GetBall(), apple))
            {
                apples.Remove(apple);
                return(true);
            }

            return(false);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }