Exemplo n.º 1
0
        public override void LoadServer(NetSceneDeltaState deltaScene)
        {
            float   startOffset       = 30;
            float   ballSize          = 18;
            var     defaultPaddleSize = new Vector2(18, 70);
            Vector2 worldSize         = Engine.Configuration.RenderSize;

            NetworkPlayer p1 = ServerGame?.Players[0];
            NetworkPlayer p2 = ServerGame?.Players[1];

            _pad1StartingPos = new Vector3(startOffset, worldSize.Y / 2 - defaultPaddleSize.Y / 2, 0);
            _pad1            = new PongPaddle("PaddleOne")
            {
                Position = _pad1StartingPos,
                Size     = defaultPaddleSize,
                Owner    = new NetworkPlayerHandle(p1?.Id),
            };
            AddObject(_pad1);

            _pad2StartingPos = new Vector3(worldSize.X - startOffset - defaultPaddleSize.X, worldSize.Y / 2 - defaultPaddleSize.Y / 2, 0);
            _pad2            = new PongPaddle("PaddleTwo")
            {
                Position = _pad2StartingPos,
                Size     = defaultPaddleSize,
                Owner    = new NetworkPlayerHandle(p2?.Id),
            };
            AddObject(_pad2);

            _ballStartingPos = new Vector3(worldSize.X / 2 - ballSize / 2, worldSize.Y / 2 - ballSize / 2, 0);
            var ball = new PongBall("Ball")
            {
                Position = _ballStartingPos,
                Size     = new Vector2(ballSize)
            };

            AddObject(ball);

            var upperWall = new NetworkTransform("UpperWall")
            {
                Position = new Vector3(-100, 0, 0),
                Size     = new Vector2(worldSize.X + 200, 10)
            };
            var lowerWall = new NetworkTransform("LowerWall")
            {
                Position = new Vector3(-100, worldSize.Y - 10, 0),
                Size     = new Vector2(worldSize.X + 200, 10)
            };

            AddObject(upperWall);
            AddObject(lowerWall);

            _betweenMatchTimer = new After(250);
            _betweenMatchTimer.End();

            _collisionSystem = new PongCollisionProvider(this);

            base.LoadServer(deltaScene);
        }