private void UpdateCurrentWorld(T worldId, bool tryFindOld)
        {
            CreateWorldActionNullCheck();

            // Get a world with the passed identification
            var world = tryFindOld && visitedWorlds.ContainsKey(worldId)
                ? visitedWorlds[worldId]
                : CreateWorldAction(worldId);

            if (!tryFindOld && !visitedWorlds.ContainsKey(worldId))
            {
                // If chosen to create a new world, also add it to the
                // dictionary of all visited worlds
                visitedWorlds.Add(worldId, world);
            }
            else if (!tryFindOld && visitedWorlds.ContainsKey(worldId))
            {
                visitedWorlds[worldId] = world;
            }

            // Update current world
            CurrentWorldId = worldId;

            // Notify listeners
            OnNavigation?.Invoke(CurrentWorldId);
        }
Beispiel #2
0
        private void PlayerNavigate(byte[] data)
        {
            var ID = BitConverter.ToInt32(data, 0);
            var x  = BitConverter.ToInt32(data, 4);
            var y  = BitConverter.ToInt32(data, 8);

            OnNavigation?.Invoke(ID, x, y);
            Server.WriteLine($"PLAYER Navigation X:{x}, Y:{y}");
        }
Beispiel #3
0
        public override void Update(GameTime gameTime)
        {
            oldGamePadState     = currentGamePadState;
            currentGamePadState = GamePad.GetState((Microsoft.Xna.Framework.PlayerIndex)PlayerIndex);

            //Save keyboard state so all controllers can access them
            oldKeyboardState     = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();

            //Update the position of the cursor
            float directionX = 0, directionY = 0;

            if (IsKeyDown(PlayerModel.KeyboardLeft))
            {
                directionX = -1;
            }
            else if (IsKeyDown(PlayerModel.KeyboardRight))
            {
                directionX = 1;
            }

            if (IsKeyDown(PlayerModel.KeyboardUp))
            {
                directionY = -1;
            }
            else if (IsKeyDown(PlayerModel.KeyboardDown))
            {
                directionY = 1;
            }

            Vector2 stick = currentGamePadState.ThumbSticks.Left;

            if (stick.X != 0)
            {
                directionX = stick.X;
            }
            if (stick.Y != 0)
            {
                directionY = stick.Y * -1;
            }

            if (oldNavigations.Count == 0)
            {
                oldNavigations.Enqueue(new Tuple <TimeSpan, Vector2> (gameTime.TotalGameTime, new Vector2(directionX, directionY)));
                newXdirection = true;
                newYdirection = true;
            }
            else
            {
                TimeSpan lastNavigation = new TimeSpan(oldNavigations.Last().Item1.Ticks);
                if (lastNavigation.Add(new TimeSpan(0, 0, 0, 0, 50)).CompareTo(gameTime.TotalGameTime) <= 0)
                {
                    Tuple <TimeSpan, Vector2> oldNav = oldNavigations.Peek();
                    if (new TimeSpan(oldNav.Item1.Ticks).Add(new TimeSpan(0, 0, 0, 0, 200)).CompareTo(gameTime.TotalGameTime) <= 0)
                    {
                        oldNavigations.Dequeue();
                    }
                    newXdirection = Math.Abs(directionX - oldNav.Item2.X) > 0.8;
                    newYdirection = Math.Abs(directionY - oldNav.Item2.Y) > 0.8;
                    oldNavigations.Enqueue(new Tuple <TimeSpan, Vector2>(gameTime.TotalGameTime, new Vector2(directionX, directionY)));
                }
            }

            if (OnNavigation != null)
            {
                OnNavigation.Invoke(directionX, directionY, PlayerIndex, newXdirection, newYdirection);
            }


            switch (CurrentState)
            {
            case GameState.StartScreen:
                if (IsKeyDown(Keys.H) || currentGamePadState.IsButtonDown(Buttons.Back))
                {
                    Screen.popupMenuController.State = PopupState.Options;
                }
                else if (this.currentKeyboardState.GetPressedKeys().Count() != 0 || currentGamePadState.IsButtonDown(Buttons.A) || currentGamePadState.IsButtonDown(Buttons.Start))
                {
                    CurrentState = GameState.CharacterMenu;
                }
                break;
            }

            //Updates all the timers added for the keys
            float elapsed = gameTime.ElapsedGameTime.Milliseconds;

            UpdateTimer(PlayerModel.KeyboardHit, Buttons.A, directionX, directionY, elapsed, OnHitkeyDown, OnHitKeyUp, OnHitKeyPressed, ref HitDownTimer, ref HitUpTimer);

            UpdateTimer(PlayerModel.KeyboardSheild, Buttons.RightTrigger, directionX, directionY, elapsed, OnShieldkeyDown, OnShieldKeyUp, OnShieldKeyPressed, ref ShieldDownTimer, ref ShieldUpTimer);

            UpdateTimer(PlayerModel.KeyboardSuper, Buttons.X, directionX, directionY, elapsed, OnSuperkeyDown, OnSuperKeyUp, OnSuperKeyPressed, ref SuperDownTimer, ref SuperUpTimer);


            if ((IsKeyPressed(PlayerModel.KeyboardStart) || isControllerPressed(Buttons.Start)) && OnStartPress != null)
            {
                OnStartPress.Invoke(PlayerIndex);
            }

            if ((IsKeyPressed(PlayerModel.KeyboardBack) || isControllerPressed(Buttons.Back)) && OnBackPress != null)
            {
                OnBackPress.Invoke(PlayerIndex);
            }
        }
Beispiel #4
0
 private void OnInputTick(float deltaTime)
 {
     horizontalHold.UpdateTime(deltaTime);
     verticalHold.UpdateTime(deltaTime);
     OnNavigation?.Invoke(navigation);
 }