Beispiel #1
0
        /// <summary>
        /// Update
        /// </summary>
        public void Update()
        {
            if (RB.KeyPressed(mKeyCode))
            {
                if (!mPressed && mButtonPressedCB != null)
                {
                    mButtonPressedCB(this, mUserData);
                }

                mPressed = true;
            }
            else if (RB.KeyReleased(mKeyCode))
            {
                if (mPressed && mButtonReleasedCB != null)
                {
                    mButtonReleasedCB(this, mUserData);
                }

                mPressed = false;
            }

            if (mTouchArmed)
            {
                if (RB.ButtonDown(RB.BTN_POINTER_A) && mHitRect.Contains(RB.PointerPos()))
                {
                    if (!mPressed && mButtonPressedCB != null)
                    {
                        mButtonPressedCB(this, mUserData);
                    }

                    mPressed = true;
                    mTouched = true;
                }
                else if ((!RB.ButtonDown(RB.BTN_POINTER_A) || !mHitRect.Contains(RB.PointerPos())) && mTouched)
                {
                    if (mPressed && mButtonReleasedCB != null)
                    {
                        mButtonReleasedCB(this, mUserData);
                    }

                    mTouched = false;
                    mPressed = false;
                }
            }
            else if (!RB.ButtonDown(RB.BTN_POINTER_A))
            {
                mTouchArmed = true;
            }
        }
Beispiel #2
0
        private void DrawGamepad(int x, int y, int playerNum)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y));

            int color1       = playerNum == RB.PLAYER_ONE ? 22 : 15;
            int color2       = playerNum == RB.PLAYER_ONE ? 21 : 14;
            int colorOutline = 0;

            DrawGamepadShoulder(25, -9, "LS", RB.ButtonDown(RB.BTN_LS, playerNum), color2, colorOutline);
            DrawGamepadShoulder(88, -9, "RS", RB.ButtonDown(RB.BTN_RS, playerNum), color2, colorOutline);

            RB.DrawEllipseFill(new Vector2i(26, 28), new Vector2i(26, 28), DemoUtil.IndexToRGB(color1));
            RB.DrawEllipseFill(new Vector2i(102, 28), new Vector2i(26, 28), DemoUtil.IndexToRGB(color1));

            RB.DrawEllipse(new Vector2i(26, 28), new Vector2i(26, 28), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawEllipse(new Vector2i(102, 28), new Vector2i(26, 28), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawRect(new Rect2i(26, 0, 76, 57), DemoUtil.IndexToRGB(colorOutline));

            RB.DrawRectFill(new Rect2i(26, 1, 76, 55), DemoUtil.IndexToRGB(color1));

#if ABXY_SWITCHED
            DrawGamepadABXY(87, 29, "Y", RB.ButtonDown(RB.BTN_Y, playerNum), color2, colorOutline);
            DrawGamepadABXY(113, 29, "A", RB.ButtonDown(RB.BTN_A, playerNum), color2, colorOutline);
            DrawGamepadABXY(100, 16, "X", RB.ButtonDown(RB.BTN_X, playerNum), color2, colorOutline);
            DrawGamepadABXY(100, 41, "B", RB.ButtonDown(RB.BTN_B, playerNum), color2, colorOutline);
#else
            DrawGamepadABXY(100, 16, "Y", RB.ButtonDown(RB.BTN_Y, playerNum), color2, colorOutline);
            DrawGamepadABXY(100, 41, "A", RB.ButtonDown(RB.BTN_A, playerNum), color2, colorOutline);
            DrawGamepadABXY(87, 29, "X", RB.ButtonDown(RB.BTN_X, playerNum), color2, colorOutline);
            DrawGamepadABXY(113, 29, "B", RB.ButtonDown(RB.BTN_B, playerNum), color2, colorOutline);
#endif

            DrawGamepadMenu(55, 20, RB.ButtonDown(RB.BTN_MENU, playerNum), color2, colorOutline);
            DrawGamepadSystem(57, 37, RB.ButtonDown(RB.BTN_SYSTEM, playerNum), color2, colorOutline);

            DrawGamepadDPad(
                10,
                14,
                (RB.ButtonDown(RB.BTN_UP, playerNum) ? RB.BTN_UP : 0) | (RB.ButtonDown(RB.BTN_DOWN, playerNum) ? RB.BTN_DOWN : 0) | (RB.ButtonDown(RB.BTN_LEFT, playerNum) ? RB.BTN_LEFT : 0) | (RB.ButtonDown(RB.BTN_RIGHT, playerNum) ? RB.BTN_RIGHT : 0),
                color2,
                colorOutline);

            RB.CameraReset();
        }
Beispiel #3
0
        /// <summary>
        /// Update velocity
        /// </summary>
        protected override void UpdateVelocity()
        {
            float   movementSpeed = 0.01f;
            Vector2 movementForce = new Vector2();

            SuperFlagRun game  = (SuperFlagRun)RB.Game;
            SceneGame    scene = (SceneGame)game.CurrentScene;

            if (scene.GetWinner() == 0)
            {
                if (RB.ButtonDown(RB.BTN_LEFT, mPlayerNum))
                {
                    movementForce.x -= movementSpeed;
                    mDirX            = -1;
                }
                else if (RB.ButtonDown(RB.BTN_RIGHT, mPlayerNum))
                {
                    mDirX            = 1;
                    movementForce.x += movementSpeed;
                }

                if (RB.ButtonDown(RB.BTN_ABXY, mPlayerNum))
                {
                    if (!mJumpKeyDown && mPhysics.IsOnGround)
                    {
                        mPhysics.Jump();
                        mJumpKeyDown = true;
                    }
                }

                if (!RB.ButtonDown(RB.BTN_ABXY, mPlayerNum))
                {
                    mJumpKeyDown = false;
                }
            }

            if (!mJumpKeyDown)
            {
                mPhysics.Velocity = new Vector2(mPhysics.Velocity.x, Mathf.Max(-1, mPhysics.Velocity.y));
            }

            mPhysics.AddForce(new Vector2(0, PlatformPhysics.GRAVITY));

            mPhysics.AddMovementForce(movementForce * mPhysics.MoveAccel);
        }
Beispiel #4
0
        private bool IsVirtualKeyPressed(KeyboardKey key)
        {
            bool pressed = false;

            if (RB.ButtonDown(RB.BTN_POINTER_ANY))
            {
                for (int i = 0; i < 4 && !pressed; i++)
                {
                    if (RB.PointerPosValid(i) && RB.ButtonDown(mPointerButtons[i]))
                    {
                        var pos = RB.PointerPos(i);
                        if (key.Rect.Contains(pos - mKeyboardOffset))
                        {
                            pressed = true;
                        }
                    }
                }
            }

            // If not pressed, but was pressed then "type" it
            if (!pressed && key.WasPointerPressed)
            {
                var c = (char)key.Code1;
                if (mShiftPressed)
                {
                    c = ((char)key.Code2).ToString().ToUpperInvariant()[0];
                }

                c = mLookup[(int)c];

                if (c > '\0' && c <= '~')
                {
                    ProcessStringInput(c.ToString());
                }
            }

            key.WasPointerPressed = pressed;
            return(pressed);
        }
Beispiel #5
0
        /// <summary>
        /// Update
        /// </summary>
        public override void Update()
        {
            base.Update();

            if (RB.ButtonDown(RB.BTN_POINTER_A))
            {
                if (mDragging)
                {
                    int dragDelta = RB.PointerPos().x - mPrevPointerPos.x;
                    mPos.x += dragDelta;

                    Rect.x = mPos.x - (Rect.width / 2);

                    int minMargin = RB.SpriteSize(0).width / 2;
                    if (Rect.x < minMargin)
                    {
                        Rect.x = minMargin;
                    }
                    else if (Rect.x + Rect.width > RB.DisplaySize.width - minMargin)
                    {
                        Rect.x = RB.DisplaySize.width - minMargin - Rect.width;
                    }
                }

                mPrevPointerPos = RB.PointerPos();
                mDragging       = true;
            }
            else
            {
                mDragging = false;
            }

            if (mExtended)
            {
                if (Rect.width < mExtendedRect.width)
                {
                    Rect.x--;
                    Rect.width += 2;
                }
            }
            else
            {
                if (Rect.width > mBaseRect.width)
                {
                    Rect.x++;
                    Rect.width -= 2;
                }
            }

            if (mLaser)
            {
                mLaserOffset -= 0.1f;
                if (mLaserOffset < 0)
                {
                    mLaserOffset = 0;
                }

                if (RB.ButtonPressed(RB.BTN_POINTER_A))
                {
                    Shoot();
                }
            }
            else
            {
                mLaserOffset += 0.1f;
                if (mLaserOffset > 1)
                {
                    mLaserOffset = 1;
                }
            }

            // Rest mPos after collision rect corrections
            mPos = new Vector2i((int)Rect.center.x, (int)Rect.center.y);
        }
Beispiel #6
0
        private void DrawMouse(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y));

            int color1       = 4;
            int color2       = 3;
            int colorOutline = 0;

            RB.DrawEllipseFill(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(color1));
            RB.DrawEllipseFill(new Vector2i(26, 54), new Vector2i(26, 20), DemoUtil.IndexToRGB(color1));
            RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawEllipse(new Vector2i(26, 54), new Vector2i(26, 20), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawRect(new Rect2i(0, 15, 53, 54 - 15), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(color1));

            RB.DrawLine(new Vector2i(52 / 3, 2), new Vector2i(52 / 3, 30), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawLine(new Vector2i(52 / 3 * 2, 2), new Vector2i(52 / 3 * 2, 30), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawLine(new Vector2i(0, 30), new Vector2i(52, 30), DemoUtil.IndexToRGB(colorOutline));

            if (RB.ButtonDown(RB.BTN_POINTER_A))
            {
                RB.ClipSet(new Rect2i(-RB.CameraGet().x + 1, -RB.CameraGet().y, (52 / 3) - 1, 30));
                RB.DrawEllipseFill(new Vector2i(26, 16), new Vector2i(26, 15), DemoUtil.IndexToRGB(5));
                RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline));
                RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(5));
                RB.ClipReset();
            }

            if (RB.ButtonDown(RB.BTN_POINTER_B))
            {
                RB.ClipSet(new Rect2i(-RB.CameraGet().x + 35, -RB.CameraGet().y, 52 / 3, 30));
                RB.DrawEllipseFill(new Vector2i(26, 16), new Vector2i(26, 15), DemoUtil.IndexToRGB(5));
                RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline));
                RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(5));
                RB.ClipReset();
            }

            if (RB.ButtonDown(RB.BTN_POINTER_C))
            {
                RB.ClipSet(new Rect2i(-RB.CameraGet().x + 18, -RB.CameraGet().y, (52 / 3) - 1, 30));
                RB.DrawEllipseFill(new Vector2i(26, 16), new Vector2i(26, 15), DemoUtil.IndexToRGB(5));
                RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline));
                RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(5));
                RB.ClipReset();
            }

            if (RB.ButtonDown(RB.BTN_POINTER_A))
            {
                RB.Print(new Vector2i(9, 16), DemoUtil.IndexToRGB(colorOutline), "A");
            }
            else
            {
                RB.Print(new Vector2i(8, 15), DemoUtil.IndexToRGB(colorOutline), "A");
            }

            if (RB.ButtonDown(RB.BTN_POINTER_C))
            {
                RB.Print(new Vector2i(25, 16), DemoUtil.IndexToRGB(colorOutline), "C");
            }
            else
            {
                RB.Print(new Vector2i(24, 15), DemoUtil.IndexToRGB(colorOutline), "C");
            }

            if (RB.ButtonDown(RB.BTN_POINTER_B))
            {
                RB.Print(new Vector2i(41, 16), DemoUtil.IndexToRGB(colorOutline), "B");
            }
            else
            {
                RB.Print(new Vector2i(40, 15), DemoUtil.IndexToRGB(colorOutline), "B");
            }

            RB.DrawRectFill(new Rect2i(23, 36, 8, 24), DemoUtil.IndexToRGB(color2));
            int barSize = (int)(6 * mScrollDeltaAnim / 2.0f);

            barSize = Mathf.Clamp(barSize, -12, 12);

            if (barSize > 0)
            {
                RB.DrawRectFill(new Rect2i(23, 48 - barSize, 8, barSize), DemoUtil.IndexToRGB(5));
            }
            else if (barSize < 0)
            {
                RB.DrawRectFill(new Rect2i(23, 48, 8, -barSize), DemoUtil.IndexToRGB(5));
            }

            RB.DrawRect(new Rect2i(23, 36, 8, 24), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawLine(new Vector2i(24, 48), new Vector2i(29, 48), DemoUtil.IndexToRGB(colorOutline));

            RB.CameraReset();
        }
        /// <summary>
        /// Update, handles switching to next scene, and quitting the demo
        /// </summary>
        public virtual void Update()
        {
            var demo = (StressTest)RB.Game;

            if (RB.KeyPressed(KeyCode.Return) || (UnityEngine.Input.mousePresent && RB.ButtonPressed(RB.BTN_POINTER_A)) || RB.ButtonPressed(RB.BTN_A))
            {
                demo.NextScene();
            }

            if ((UnityEngine.Input.mousePresent && RB.ButtonPressed(RB.BTN_POINTER_B)) || RB.ButtonPressed(RB.BTN_X))
            {
                demo.PreviousScene();
            }

            if (RB.ButtonPressed(RB.BTN_SYSTEM))
            {
                Application.Quit();
            }

            if (!UnityEngine.Input.mousePresent)
            {
                if (RB.ButtonReleased(RB.BTN_POINTER_A, RB.PLAYER_ANY))
                {
                    mTouchTimestamp[0] = (long)RB.Ticks;
                }

                if (RB.ButtonReleased(RB.BTN_POINTER_B, RB.PLAYER_ANY))
                {
                    mTouchTimestamp[1] = (long)RB.Ticks;
                }

                if (RB.ButtonReleased(RB.BTN_POINTER_C, RB.PLAYER_ANY))
                {
                    mTouchTimestamp[2] = (long)RB.Ticks;
                }

                if (RB.ButtonReleased(RB.BTN_POINTER_D, RB.PLAYER_ANY))
                {
                    mTouchTimestamp[3] = (long)RB.Ticks;
                }

                // If all fingers are up then check how many fingers have close timestamps
                if (!RB.ButtonDown(RB.BTN_POINTER_A, RB.PLAYER_ANY) &&
                    !RB.ButtonDown(RB.BTN_POINTER_B, RB.PLAYER_ANY) &&
                    !RB.ButtonDown(RB.BTN_POINTER_C, RB.PLAYER_ANY) &&
                    !RB.ButtonDown(RB.BTN_POINTER_D, RB.PLAYER_ANY))
                {
                    int fingerCount = 0;
                    for (int i = 0; i < 4; i++)
                    {
                        long delta = (long)RB.Ticks - (long)mTouchTimestamp[i];
                        if (delta >= 0 && delta < 5)
                        {
                            fingerCount++;
                        }
                    }

                    if (fingerCount == 1)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            mTouchTimestamp[i] = long.MaxValue;
                        }

                        demo.NextScene();
                    }
                    else if (fingerCount > 1)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            mTouchTimestamp[i] = long.MaxValue;
                        }

                        demo.PreviousScene();
                    }
                }
            }
        }
Beispiel #8
0
    public virtual void Update(bool hasFocus = true)
    {
        Vector2i     mousePos = RB.PointerPos() + new Vector2i(0, 1);     // + 0, 1 is workaround for weird hovering behaviour?!
        UIObj        on       = null;
        List <UIObj> objsNoLongerUnderMouse = new List <UIObj>();

        foreach (UIObj obj in objUnderMouse)
        {
            if (!obj.IsInBounds(mousePos) || !obj.isVisible)
            {
                if (objUnderMouse.Contains(obj))
                {
                    objsNoLongerUnderMouse.Add(obj);
                    obj.OnMouseExit();
                    EventBus.UIMouseExit.Invoke(obj);
                }
            }
        }
        objUnderMouse.RemoveWhere((obj) => objsNoLongerUnderMouse.Contains(obj));
        List <UIObj> uiObjsToUpdate = uiObjs;

        if (currentMsgBox != null)
        {
            uiObjsToUpdate = currentMsgBox.GetUIObjs();
        }
        foreach (UIObj obj in uiObjsToUpdate)
        {
            if (obj.HasKeybind() && RB.KeyPressed(obj.GetKeybind()))
            {
                if (obj.IsInteractable)
                {
                    EventBus.UIClick.Invoke(obj);
                    obj.OnClick();
                }
            }
            if (obj.IsInBounds(mousePos) && obj.isVisible)
            {
                if (!objUnderMouse.Contains(obj))
                {
                    objUnderMouse.Add(obj);
                    obj.OnMouseEnter();
                    EventBus.UIMouseEnter.Invoke(obj);
                }
            }
            if (obj.IsInBounds(mousePos) && obj.IsInteractable)             // && hasFocus) {
            {
                if (obj.currentState != UIObj.State.Hovered)
                {
                    EventBus.UIHoverStart.Invoke(obj);
                }
                obj.currentState = UIObj.State.Hovered;
                on = obj;
            }
            else
            if (obj.currentState != UIObj.State.Disabled)
            {
                if (obj.currentState == UIObj.State.Hovered)
                {
                    EventBus.UIHoverEnd.Invoke(obj);
                }
                obj.currentState = UIObj.State.Enabled;
            }

            obj.Update();
        }
        if (RB.ButtonPressed(RB.BTN_POINTER_A) && hasFocus)
        {
            if (on != null)
            {
                on.currentState = UIObj.State.Pressed;
                mousePressedOn  = on;
                SetFocus(on);
            }
            else
            {
                SetFocus(null);
            }
        }
        else
        if (RB.ButtonReleased(RB.BTN_POINTER_A))
        {
            if (on == mousePressedOn && on != null)
            {
                if (on.currentState == UIObj.State.Hovered)
                {
                    EventBus.UIClick.Invoke(on);
                }
                mousePressedOn.OnClick();
            }
            mousePressedOn = null;
        }
        else
        if (RB.ButtonDown(RB.BTN_POINTER_A) && hasFocus)
        {
            if (mousePressedOn != null && on == mousePressedOn)
            {
                mousePressedOn.currentState = UIObj.State.Pressed;
            }
            else
            if (on != null)
            {
                on.currentState = UIObj.State.Enabled;
            }
        }
    }