Ejemplo n.º 1
0
        private void InitTankBullet(TankView tank, Size sizeTank)
        {
            Random random = new Random();

            if (random.Next(300) < 10)
            {
                Position posBullet = new Position()
                {
                    x = tank.Pos.x + sizeTank.width / 2 - Bullet.size.width / 2,
                    y = tank.Pos.y + sizeTank.height / 2 - Bullet.size.height / 2
                };
                Entities.Bullets.Add(new BulletView(posBullet, tank.Direction, true));
            }
        }
Ejemplo n.º 2
0
        public void ChangeTankDirection(TankView tank, Direction direction)
        {
            switch (direction)
            {
            case Direction.LEFT:
                tank.Direction = Direction.RIGHT;
                break;

            case Direction.RIGHT:
                tank.Direction = Direction.LEFT;
                break;

            case Direction.UP:
                tank.Direction = Direction.DOWN;
                break;

            case Direction.DOWN:
                tank.Direction = Direction.UP;
                break;
            }
        }
Ejemplo n.º 3
0
        private void MoveTank(TankView tank)
        {
            switch (tank.Direction)
            {
            case Direction.LEFT:
                tank.Pos.x -= Speed;
                break;

            case Direction.RIGHT:
                tank.Pos.x += Speed;
                break;

            case Direction.UP:
                tank.Pos.y -= Speed;
                break;

            case Direction.DOWN:
                tank.Pos.y += Speed;
                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);
                }
            }
        }