/// <summary> /// Render /// </summary> public override void Render() { var demo = (DemoReel)RB.Game; RB.Clear(DemoUtil.IndexToRGB(1)); DrawNoisePad(4, 4); DrawPiano(4, 200); DrawMusicPlayer(350, 4); mNextButton.Render(); mPrevButton.Render(); if (RB.PointerPosValid()) { RB.DrawSprite(4, RB.PointerPos()); } }
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); }
/// <summary> /// Get tile position at current pointer position. This takes into account camera position. /// </summary> /// <returns>Tile position</returns> public static Vector2i GetMouseTilePos() { var game = (RetroDungeoneerGame)RB.Game; if (!RB.PointerPosValid()) { return(new Vector2i(-1, -1)); } var mousePos = RB.PointerPos() + mCamera.GetPos(); mousePos.x -= (RB.DisplaySize.width / 2) - (game.assets.spriteSheet.grid.cellSize.width / 2); mousePos.y -= (RB.DisplaySize.height / 2) - (game.assets.spriteSheet.grid.cellSize.height / 2); var tilePos = new Vector2i(mousePos.x / game.assets.spriteSheet.grid.cellSize.width, mousePos.y / game.assets.spriteSheet.grid.cellSize.height); if (tilePos.x < 0 || tilePos.y < 0 || tilePos.x >= game.map.size.width || tilePos.y >= game.map.size.height) { return(new Vector2i(-1, -1)); } return(tilePos); }
/// <summary> /// Render /// </summary> public override void Render() { var demo = (DemoReel)RB.Game; RB.Clear(DemoUtil.IndexToRGB(1)); mFormatStr.Set("@C// Test gamepad input for two players\n"); mFormatStr.Append("@Kif @N(@[email protected](@MRetroBlit.@NBTN_A, @[email protected]_ONE) {\n"); mFormatStr.Append(" @C// Handle button A down for player one\n@N"); mFormatStr.Append("}\n"); mFormatStr.Append("@Kif @N(@[email protected](@MRetroBlit.@NBTN_LEFT, @[email protected]_TWO) {\n"); mFormatStr.Append(" @C// Handle button LEFT transitioning from \"up\" to \"down\"\n@N"); mFormatStr.Append("}\n"); mFormatStr.Append("@Kif @N(@[email protected](@MRetroBlit.@NBTN_MENU, @[email protected]_ANY) {\n"); mFormatStr.Append(" @C// Handle button MENU transitioning from \"down\" to \"up\"\n@N"); mFormatStr.Append("}"); RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); DrawGamepad(260, 15, RB.PLAYER_ONE); DrawGamepad(400, 15, RB.PLAYER_TWO); DrawMouse(540, 8); RB.DrawLine(new Vector2i(16, 85), new Vector2i(RB.DisplaySize.width - 16, 85), DemoUtil.IndexToRGB(2)); mFormatStr.Set("@C// Test keyboard input\n"); mFormatStr.Append("@Kif @N(@[email protected](@[email protected])) {\n"); mFormatStr.Append(" @C// Handle Left Shift down\n@N"); mFormatStr.Append("}\n\n"); mFormatStr.Append("@C// Retrieve the string of characters typed since last update\n"); mFormatStr.Append("@Kstring@n userInput += @[email protected]();"); RB.Print(new Vector2i(50, 92), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); mFormatStr.Set("@C// Get pointer position (mouse or touch)\n"); mFormatStr.Append("@[email protected](@L4@N, @[email protected]());\n\n"); mFormatStr.Append("@C// Test pointer button input\n"); mFormatStr.Append("@Kif @N(@[email protected](@[email protected]_POINTER_A)) {\n"); mFormatStr.Append(" @C// Handle Pointer Button A down\n@N"); mFormatStr.Append("}\n"); RB.Print(new Vector2i(350, 92), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); DrawKeyboard(mKeyboardOffset.x, mKeyboardOffset.y); DrawInputString(14, 155); mNextButton.Render(); mPrevButton.Render(); if (RB.PointerPosValid()) { RB.DrawSprite(4, RB.PointerPos()); } if (!UnityEngine.Input.mousePresent) { for (int i = 0; i < 4; i++) { if (RB.PointerPosValid(i)) { RB.DrawEllipse(RB.PointerPos(i), new Vector2i(64, 64), mTouchColor[i]); } } } }