예제 #1
0
        public RoyalGameModel(int gamersInRoom)
        {
            //инициализируем полей
            Players          = new List <IPlayer>();
            gameObjects      = new Dictionary <ulong, IGameObject>();
            outgoingMessages = new ObservableQueue <IMessage>();
            incomingMessages = new ObservableQueue <IMessage>();

            AABB frameField = new AABB();

            frameField.LowerBound.Set(0, 0);
            frameField.UpperBound.Set(LengthOfSideMap, LengthOfSideMap);
            Field = new World(frameField, new Vec2(0, 0), false);
            var solver = new RoomContactListener();

            Field.SetContactListener(solver);
            CreateFrame();

            DeathZone = BuilderGameObject.CreateDeathZone(this, LengthOfSideMap);

            //создание и добавление в GameObjects и Field статических объектов карты
            List <RectangleF> occupiedArea = new List <RectangleF>();

            CreateDinamicGameObject(occupiedArea);
            CreatePlayers(gamersInRoom, occupiedArea);

            handlerIncomingMessages = new Task(Handler_IncomingMessages);
            handlerIncomingMessages.Start();
        }
예제 #2
0
        public override void Dispose()
        {
            //создаем для всех объектов тела с заданным вектором движения

            //освобожаем все объекты от держателей

            /*for (int i = 0; i < modifiers.Length; i++)
             * {
             *      if (modifiers[i] != null)
             *      {
             *              modifiers[i].Holder = null;
             *              CountObjects++;
             *      }
             * }*/

            //пока только для оружия
            PointF position = Parent.Components.GetComponent <SolidBody>().Shape.Location;

            for (int i = 0; i < weapons.Length; i++)
            {
                if (weapons[i] != null)
                {
                    weapons[i].Owner = null;
                    BuilderGameObject.CreateNewBodyForWeapon(weapons[i], CreateRandVec2(), position);
                }
            }

            Parent.Received_TryPickUp       -= Handler_TryPickUp;
            Parent.Received_TimeQuantPassed -= Handler_TimeQuantPassed;
        }
예제 #3
0
파일: Throw.cs 프로젝트: Rogachev99/PUBG
        private void Handler_MakeShot(IMessage msg)
        {
            SolidBody BodyHolder = (Parent as Weapon).Owner?.Components?.GetComponent <SolidBody>();

            if (BodyHolder == null)
            {
                return;
            }
            //получаем гранату
            IBullet grenadeBullet = magazin.GetBullet();

            if (grenadeBullet == null)
            {
                return;
            }

            //получаем позицию игрока
            Vec2 position = (Vec2)BodyHolder.Body?.GetPosition();
            //определяем импульс
            float dX = msg.Location.X - position.X;
            float dY = (msg.Location.Y - position.Y);

            //нельзя бросить дальше дальности броска
            if (System.Math.Sqrt(dX * dX + dY * dY) > strength)
            {
                return;
            }
            Vec2 impulse = new Vec2(dX, dY);

            //создаем объект гранаты
            var grenade = BuilderGameObject.CreateGrenade(Parent.Model,
                                                          (Parent as Weapon).Owner.Components.GetComponent <SolidBody>().Shape.Location, impulse, grenadeBullet);
        }
예제 #4
0
        private void CreateDinamicGameObject(List <RectangleF> occupiedArea)
        {
            //15 камней
            for (int i = 0; i < 20; i++)
            {
                RectangleF newShape = CreateAndAddNewUniqueShape(occupiedArea, BuilderGameObject.SizeStone);
                var        stone    = BuilderGameObject.CreateStone(this, newShape.Location);
            }
            //12 коробок
            for (int i = 0; i < 15; i++)
            {
                RectangleF newShape = CreateAndAddNewUniqueShape(occupiedArea, BuilderGameObject.SizeBox);
                var        box      = BuilderGameObject.CreateBox(this, newShape.Location);
            }

            //4 автомата
            for (int i = 0; i < 4; i++)
            {
                RectangleF newShape     = CreateAndAddNewUniqueShape(occupiedArea, BuilderGameObject.SizeAssaulRiffle);
                var        assaultRifle = BuilderGameObject.CreateAssaultRiffle(this, newShape.Location);
            }

            //5 шот-ганов
            for (int i = 0; i < 5; i++)
            {
                RectangleF newShape = CreateAndAddNewUniqueShape(occupiedArea, BuilderGameObject.SizeShotGun);
                var        shotGun  = BuilderGameObject.CreateShotGun(this, newShape.Location);
            }

            //5 гранат
            for (int i = 0; i < 5; i++)
            {
                RectangleF newShape = CreateAndAddNewUniqueShape(occupiedArea, BuilderGameObject.SizeGrenadeCollection);
                var        grenade  = BuilderGameObject.CreateGrenadeCollection(this, newShape.Location);
            }

            //8 пистолетов
            for (int i = 0; i < 8; i++)
            {
                RectangleF newShape = CreateAndAddNewUniqueShape(occupiedArea, BuilderGameObject.SizeGun);
                var        gun      = BuilderGameObject.CreateGun(this, newShape.Location);
            }

            //12 кустов
            for (int i = 0; i < 25; i++)
            {
                RectangleF newShape = CreateAndAddNewUniqueShape(occupiedArea, BuilderGameObject.SizeBush);
                var        bush     = BuilderGameObject.CreateBush(this, newShape.Location);
            }

            //10 деревьев
            for (int i = 0; i < 20; i++)
            {
                RectangleF newShape = CreateAndAddNewUniqueShape(occupiedArea, BuilderGameObject.SizeTree);
                var        tree     = BuilderGameObject.CreateTree(this, newShape.Location);
            }
        }
예제 #5
0
 /// <summary>
 /// Создает игроков и добавляет их на карту в список игроков и список игрвовых объектов
 /// </summary>
 private void CreatePlayers(int gamersInRoom, List <RectangleF> occupiedArea)
 {
     for (int i = 0; i < gamersInRoom; i++)
     {
         //создаем игрока
         RectangleF newShape = CreateAndAddNewUniqueShape(occupiedArea, BuilderGameObject.SizeGamer);
         var        gamer    = BuilderGameObject.CreateGamer(this, newShape.Location);
     }
     outgoingMessages.Enqueue(new ChangeCountPlayersInGame(0, Players.Count));
 }
예제 #6
0
        /// <summary>
        /// только для тестов
        /// </summary>
        public RoyalGameModel()
        {
            //инициализируем полей
            Players          = new List <IPlayer>();
            gameObjects      = new Dictionary <ulong, IGameObject>();
            outgoingMessages = new ObservableQueue <IMessage>();
            incomingMessages = new ObservableQueue <IMessage>();

            AABB frameField = new AABB();

            frameField.LowerBound.Set(0, 0);
            frameField.UpperBound.Set(LengthOfSideMap, LengthOfSideMap);
            Field = new World(frameField, new Vec2(0, 0), false);
            var solver = new RoomContactListener();

            Field.SetContactListener(solver);
            CreateFrame();

            DeathZone = BuilderGameObject.CreateDeathZone(this, LengthOfSideMap);

            handlerIncomingMessages = new Task(Handler_IncomingMessages);
            handlerIncomingMessages.Start();
        }