Beispiel #1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);


            Window.Current.CoreWindow.KeyUp += Menu_KeyUp;
            ToggleCurser();

            var gameInfo = (GameInfo)e.Parameter;

            var gameName = gameInfo.gameName;

            var inputs = new MouseKeyboardInputs(lockCurser, playerId);

            game = new Game2();

            zoomer = new MouseZoomer(GameHolder.ActualWidth, GameHolder.ActualHeight, fieldDimensions, (GameState gs) =>
            {
                return(gs.players.Where(x => x.Key == playerId).Select(x => x.Value.PlayerBody.Position)
                       .Union(new[] { gs.GameBall.Posistion })
                       .ToArray());
            });
            //zoomer = new FullField(GameHolder.ActualWidth, GameHolder.ActualHeight, fieldDimensions.xMax / 2.0, fieldDimensions.yMax / 2.0);
            renderGameState = new RenderGameState2(/*Canvas,*/ zoomer, LeftScore, RightScore);

            var signalRHandler = SingleSignalRHandler.GetOrThrow();
            var color          = GetColor();

            signalRHandler.Send(gameName, new AddPlayerEvent(
                                    playerId,
                                    "",
                                    BodyA,
                                    color[0],
                                    color[1],
                                    color[2],
                                    0xff,
                                    color[0],
                                    color[1],
                                    color[2],
                                    new Physics2.Vector(fieldDimensions.xMax / 2.0, fieldDimensions.yMax / 2.0)
                                    ));

            inputs.Init().ContinueWith(_ =>
            {
                signalRHandler.Send(gameName, Inputs(inputs));
            });

            var dontWait = MainLoop(signalRHandler.JoinChannel(new JoinChannel(gameName)));
        }
Beispiel #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            Window.Current.CoreWindow.KeyUp += Menu_KeyUp;

            //zoomer = new ShowAllPositions(GameHolder.ActualWidth, GameHolder.ActualHeight, fieldDimensions);


            //rge = new RenderGameEvents(GameArea, Fps, LeftScore, RightScore, zoomer, frame, fieldDimensions);

            //if (lockCurser.Thing)
            //{
            //    Window.Current.CoreWindow.PointerPosition = new Windows.Foundation.Point(
            //        (Window.Current.CoreWindow.Bounds.Left + Window.Current.CoreWindow.Bounds.Right) / 2.0,
            //        (Window.Current.CoreWindow.Bounds.Top + Window.Current.CoreWindow.Bounds.Bottom) / 2.0);
            //    Window.Current.CoreWindow.PointerCursor = null;
            //}
            //else
            //{
            //    Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 0);
            //}

            var gameInfo = (GameInfo)e.Parameter;

            var gameName = gameInfo.gameName;

            game = new Game2();


            var teamSize = 5;

            var ourTeam = new Guid[teamSize].Select(x => Guid.NewGuid()).ToArray();

            //zoomer = new MouseZoomer(GameHolder.ActualWidth, GameHolder.ActualHeight, fieldDimensions, (GameState gs)=> {


            //    return gs.players.Where(x =>  x.Key == ourTeam[0]).Select(x => x.Value.PlayerBody.Position)
            //    .Union(new[] { gs.GameBall.Posistion })
            //    .ToArray();

            //});


            // this blocks like a mofo
            // we don't want anything to get a peice of the main thread while we are setting up
            try
            {
                //if (gameInfo.controlScheme == ControlScheme.MouseAndKeyboard)
                //{
                //    var body = ourTeam.First();
                //    var inputs = new MouseKeyboardInputs(lockCurser, body);
                //    await inputs.Init();
                //    await CreatePlayer(body, inputs, new byte[3] { 0x88, 0x00, 0xff });
                //}

                //foreach (var body in ourTeam)//.Skip(1)
                //{
                //    var inputs = new AIInputs(game.gameState, body, ourTeam.Except(new Guid[] { body }).ToArray(), fieldDimensions, false);
                //    await inputs.Init();
                //    await CreatePlayer(body, inputs, new byte[3] { 0x00, 0x00, 0xff });
                //}


                //https://stackoverflow.com/questions/48997243/uwp-gamepad-gamepads-is-empty-even-though-a-controller-is-connected
                //var x = 0;
                //while (x < 10)
                //{
                //    var db = Gamepad.Gamepads.Count;
                //    Task.Delay(100).Wait();
                //    x++;
                //}


                //var gps = Gamepad.Gamepads.ToArray();
                //foreach (var (gamePad, key) in gps.Zip(ourTeam.Take(gps.Length), (x, y) => (x, y)))
                //{
                //    var body = key;// Guid.NewGuid();
                //    var inputs = CreateController(gamePad, body);
                //    inputs.Init().Wait();
                //    CreatePlayer(body, inputs).Wait();
                //}

                var body   = ourTeam.First();
                var inputs = new MouseKeyboardInputs(lockCurser, body);
                await inputs.Init();
                await CreatePlayer(body, inputs, new byte[3] {
                    0x88, 0x00, 0xff
                });

                {
                    var team = new AITeam(game.gameState, ourTeam, fieldDimensions, false);

                    foreach (var(key, input) in team.GetPlayers().Skip(1 /*gps.Length*/))
                    {
                        input.Init().Wait();
                        CreatePlayer(key, input, new byte[3] {
                            0x00, 0x00, 0xff
                        }).Wait();
                    }
                }

                var theirTeam = new Guid[teamSize].Select(x => Guid.NewGuid()).ToArray();

                {
                    var team = new AITeam(game.gameState, theirTeam, fieldDimensions, true);

                    foreach (var(key, input) in team.GetPlayers())
                    {
                        input.Init().Wait();
                        CreatePlayer(key, input, new byte[3] {
                            0xff, 0x00, 0x00
                        }).Wait();
                    }
                }
            }
            catch (Exception ex)
            {
                await OnDisconnect(ex);
            }

            var ourBody = localPlayers.Read().First().LocalId;

            zoomerLeft  = new Zoomer(CanvasLeft.ActualWidth, CanvasLeft.ActualHeight, ourBody, .0025);
            zoomerRight = new Zoomer(CanvasRight.ActualWidth, CanvasRight.ActualHeight, ourBody, .01);
            //renderGameState = new RenderGameState(GameArea, zoomer, LeftScore, RightScore);
            renderGameStateLeft  = new RenderGameState2(/*Canvas,*/ zoomerLeft, LeftScore, RightScore);
            renderGameStateRight = new RenderGameState2(/*Canvas,*/ zoomerRight, LeftScore, RightScore);

            Task.Run(async() =>
            {
                try {
                    MainLoop();
                }
                catch (Exception ex)
                {
                    await OnDisconnect(ex);
                }
            });
        }