Ejemplo n.º 1
0
        private void CheckKolobokCollisoins()
        {
            KolobokView kolobok = Entities.Kolobok;

            if (kolobok.Pos.x < 0)
            {
                kolobok.Pos.x = 0;
            }
            else if (kolobok.Pos.x > MapWidth - kolobok.size.width)
            {
                kolobok.Pos.x = MapWidth - kolobok.size.width;
            }

            if (kolobok.Pos.y < 0)
            {
                kolobok.Pos.y = 0;
            }
            else if (kolobok.Pos.y > MapHeight - kolobok.size.height)
            {
                kolobok.Pos.y = MapHeight - kolobok.size.height;
            }

            foreach (var apple in Entities.Apples)
            {
                if (BoxCollides(apple.Pos, Apple.size, kolobok.Pos, kolobok.size))
                {
                    Entities.Apples.Remove(apple);
                    Score++;
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        /*
         * private void InitWalls()
         * {
         * Position pos = new Position() { x = 60, y = 60 };
         * for (int i = 0; i < 2; i++)
         * {
         *     Entities.Walls.Add(new WallView(pos));
         *     pos.y += 50;
         * }
         *
         * pos.x = 60;
         * pos.y = 260;
         * for (int i = 0; i < 2; i++)
         * {
         *     Entities.Walls.Add(new WallView(pos));
         *     pos.y += 50;
         * }
         *
         * pos.x = 60;
         * pos.y = 360;
         * for (int i = 0; i < 3; i++)
         * {
         *     Entities.Walls.Add(new DestroyWallView(pos));
         *     pos.x += 50;
         * }
         *
         * pos.x = 170;
         * pos.y = 60;
         * for (int i = 0; i < 4; i++)
         * {
         *     Entities.Walls.Add(new DestroyWallView(pos));
         *     pos.y += 50;
         * }
         *
         * pos.x = 280;
         * pos.y = 60;
         * for (int i = 0; i < 7; i++)
         * {
         *     Entities.Walls.Add(new WallView(pos));
         *     pos.y += 50;
         * }
         *
         * pos.x = 690;
         * pos.y = 60;
         * for (int i = 0; i < 6; i++)
         * {
         *     Entities.Walls.Add(new WallView(pos));
         *     pos.y += 50;
         * }
         *
         * pos.x = 330;
         * pos.y = 130;
         * for (int i = 0; i < 6; i++)
         * {
         *     Entities.Walls.Add(new WaterView(pos));
         *     pos.x += 50;
         * }
         *
         * pos.x = 390;
         * pos.y = 250;
         * for (int i = 0; i < 6; i++)
         * {
         *     Entities.Walls.Add(new WallView(pos));
         *     pos.x += 50;
         * }
         * }
         */
        public void Shoot()
        {
            KolobokView kolobok = Entities.Kolobok;
            Position    pos     = new Position()
            {
                x = kolobok.Pos.x + kolobok.size.width / 2 - Bullet.size.width / 2,
                y = kolobok.Pos.y + kolobok.size.height / 2 - Bullet.size.height / 2
            };

            Entities.Bullets.Add(new BulletView(pos, kolobok.Direction, false));
        }
Ejemplo n.º 3
0
        private void CheckTanksCollisions()
        {
            foreach (var tank in Entities.Tanks)
            {
                Size        sizeTank = Tank.size;
                KolobokView kolobok  = Entities.Kolobok;

                if (BoxCollides(tank.Pos, sizeTank, kolobok.Pos, kolobok.size))
                {
                    GameOver();
                    return;
                }

                if ((tank.Pos.x < 0) ||
                    (tank.Pos.x > MapWidth - Tank.size.width) ||
                    (tank.Pos.y < 0) ||
                    (tank.Pos.y > MapHeight - Tank.size.height))
                {
                    ChangeTankDirection(tank, tank.Direction);
                    MoveTank(tank);
                }

                foreach (var wall in Entities.Walls)
                {
                    Position posWall  = wall.Pos;
                    Size     sizeWall = wall.size;
                    Random   random   = new Random();

                    if (BoxCollides(tank.Pos, sizeTank, posWall, sizeWall))
                    {
                        ChangeTankDirection(tank, tank.Direction);
                        MoveTank(tank);
                        tank.Direction = (Direction)random.Next(4);
                        break;
                    }
                }

                foreach (var otherTank in Entities.Tanks)
                {
                    if (otherTank != tank)
                    {
                        if (BoxCollides(tank.Pos, sizeTank, otherTank.Pos, sizeTank))
                        {
                            ChangeTankDirection(tank, tank.Direction);
                            MoveTank(tank);
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void TankShoot(TankView tank, Size sizeTank, KolobokView kolobok)
        {
            Position pos  = new Position();
            Size     size = new Size();

            pos.x = 0;
            pos.y = tank.Pos.y;

            size.width  = tank.Pos.x + sizeTank.width;
            size.height = sizeTank.height;

            if (BoxCollides(pos, size, kolobok.Pos, kolobok.size))
            {
                if (!IsWallCollisions(pos, size))
                {
                    ChangeTankDirection(tank, Direction.RIGHT);
                    InitTankBullet(tank, sizeTank);
                }
            }

            pos.x = tank.Pos.x;
            pos.y = tank.Pos.y;

            size.width  = MapWidth - tank.Pos.x + sizeTank.width;
            size.height = sizeTank.height;

            if (BoxCollides(pos, size, kolobok.Pos, kolobok.size))
            {
                if (!IsWallCollisions(pos, size))
                {
                    ChangeTankDirection(tank, Direction.LEFT);
                    InitTankBullet(tank, sizeTank);
                }
            }

            pos.x = tank.Pos.x;
            pos.y = tank.Pos.y;

            size.width  = sizeTank.width;
            size.height = MapHeight - tank.Pos.y + sizeTank.height;

            if (BoxCollides(pos, size, kolobok.Pos, kolobok.size))
            {
                if (!IsWallCollisions(pos, size))
                {
                    ChangeTankDirection(tank, Direction.UP);
                    InitTankBullet(tank, sizeTank);
                }
            }

            pos.x = tank.Pos.x;
            pos.y = 0;

            size.width  = sizeTank.width;
            size.height = tank.Pos.y + sizeTank.height;

            if (BoxCollides(pos, size, kolobok.Pos, kolobok.size))
            {
                if (!IsWallCollisions(pos, size))
                {
                    ChangeTankDirection(tank, Direction.DOWN);
                    InitTankBullet(tank, sizeTank);
                }
            }
        }