//HACK: This is linked into the Win, Lose and Draw Screens too, each should have their own handling of input!
        private void StartUpdate()
        {
            //TODO: add a switch draw state on the "StartScreen" Object on leaving the state
            string[] pressedKeys = m_GameCommand.RequestData <string>(Constant.enumMessage.GET_PRESSED_KEYS);
            foreach (string key in pressedKeys)
            {
                Constant.enumKey currKey = (Constant.enumKey)Enum.Parse(typeof(Constant.enumKey), key);
                switch (currKey)
                {
                case Constant.enumKey.Return:
                    m_CurrState = 1;
                    break;

                case Constant.enumKey.Escape:
                    m_CurrState = 5;
                    break;
                }
            }
        }
Beispiel #2
0
        public void Update()
        {
            IGraphicsSettings graphicSetting = m_ScriptController.RequestData <IGraphicsSettings>(Constant.enumMessage.GET_GRAPHICS_SETTINGS).FirstOrDefault();
            //IRigidBody playerRigidBody = m_ScriptController.RequestData<IComponent>(Constant.enumMessage.GET_GAMEOBJECTCOMPONENTS, new Object[] { m_GameObject.m_GameObjectKey, new Constant.enumComponent[] { Constant.enumComponent.RIGIDBODY } }).OfType<IRigidBody>().FirstOrDefault();
            IRigidBody playerRigidBody = m_GameObject.getComponent <IRigidBody>(Constant.enumComponent.RIGIDBODY);

            if (playerRigidBody.m_Position.ReturnAnyLessThen(new Vector3(-90, -40, 0)) || playerRigidBody.m_Position.ReturnAnyGreaterThen(new Vector3(graphicSetting.m_ScreenSize.x, graphicSetting.m_ScreenSize.y, 0)))
            {
                // IPositionComponent3D playerPos = m_ScriptController.RequestData<IComponent>(Constant.enumMessage.GET_GAMEOBJECTCOMPONENTS, new Object[] { "player", new Constant.enumComponent[] { Constant.enumComponent.POSITIONCOMPONENT3D } }).OfType<IPositionComponent3D>().FirstOrDefault();
                IPositionComponent3D playerPos = m_GameObject.getComponent <IPositionComponent3D>(Constant.enumComponent.POSITIONCOMPONENT3D);
                playerPos.m_Position.x     = (graphicSetting.m_ScreenSize.x / 2) - 45;
                playerPos.m_Position.y     = graphicSetting.m_ScreenSize.y / 2;
                playerRigidBody.m_Velocity = new Vector3();
            }

            string[] pressedKeys = m_ScriptController.RequestData <string>(Constant.enumMessage.GET_PRESSED_KEYS);
            foreach (string key in pressedKeys)
            {
                Constant.enumKey currKey = (Constant.enumKey)Enum.Parse(typeof(Constant.enumKey), key);
                switch (currKey)
                {
                case Constant.enumKey.Up:
                    playerRigidBody.AddForce(0, -500, 0);;
                    break;

                case Constant.enumKey.Down:
                    playerRigidBody.AddForce(0, 500, 0);;
                    break;

                case Constant.enumKey.Left:
                    playerRigidBody.AddForce(-500, 0, 0);;
                    break;

                case Constant.enumKey.Right:
                    playerRigidBody.AddForce(500, 0, 0);;
                    break;
                }
            }
        }
        private void GameUpdate()
        {
            string[] pressedKeys = m_GameCommand.RequestData <string>(Constant.enumMessage.GET_PRESSED_KEYS);
            bool     altPressed = false, userClicked = false;

            if (m_KeyboardElapsedTime > m_InputCooldown)
            {
                foreach (string key in pressedKeys)
                {
                    Constant.enumKey currKey = (Constant.enumKey)Enum.Parse(typeof(Constant.enumKey), key);
                    switch (currKey)
                    {
                    case Constant.enumKey.Escape:
                        m_CurrState = 5;
                        break;

                    case Constant.enumKey.Return:
                        if (altPressed)
                        {
                            m_SetFullscreen = !m_SetFullscreen;
                        }
                        break;

                    case Constant.enumKey.LAlt:
                    case Constant.enumKey.RAlt:
                        altPressed = true;
                        break;
                    }
                }
                m_KeyboardElapsedTime = 0.0;
            }
            else
            {
                m_KeyboardElapsedTime += Constant.elapsedTime;
            }

            string[] pressedMouseButtons = m_GameCommand.RequestData <string>(Constant.enumMessage.GET_PRESSED_MOUSEBUTTONS);
            if (m_MouseElapsedTime > m_InputCooldown)
            {
                foreach (string button in pressedMouseButtons)
                {
                    Constant.enumMouseButton currButton = (Constant.enumMouseButton)Enum.Parse(typeof(Constant.enumMouseButton), button);
                    switch (currButton)
                    {
                    case Constant.enumMouseButton.LEFT:
                        userClicked = true;
                        break;
                    }
                }
                m_MouseElapsedTime = 0.0;
            }
            else
            {
                m_MouseElapsedTime += Constant.elapsedTime;
            }

            if (userClicked && m_CurrPlayer == 0)
            {
                Vector2 MousePos    = m_GameCommand.RequestData <Vector2>(Constant.enumMessage.GET_MOUSE_POSITION)[0];
                int[]   relativePos = GetRelativeMousePos(MousePos);
                if (relativePos != null && !IsBoardOccupied(relativePos[0], relativePos[1]))
                {
                    //m_GameCommand.SendData(Constant.enumMessage.SWITCH_SPRITES_DRAW_STATUS, new string[] {m_OObjTable[relativePos[0],relativePos[1]]});
                    SetBoardOccupied(relativePos[0], relativePos[1]);
                    SwitchPlayer();
                }
            }
            else if (m_CurrPlayer == 1)
            {
                int genx = m_Random.Next(3), geny = m_Random.Next(3);
                if (!IsBoardOccupied(genx, geny))
                {
                    //m_GameCommand.SendData(Constant.enumMessage.SWITCH_SPRITES_DRAW_STATUS, new string[] { m_XObjTable[genx, geny] });
                    SetBoardOccupied(genx, geny);
                    SwitchPlayer();
                }
            }
            CheckGameWin();
            if (m_CurrState != 1)
            {
                ClearBoard();
            }
        }