How to use the raylib.DrawRectangle function in raylib

To help you get started, we’ve selected a few raylib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RobLoach / node-raylib / templates / simple_game / simple_game.js View on Github external
r.DrawText("TITLE SCREEN", 20, 20, 40, r.DARKGREEN)
                r.DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, r.DARKGREEN)

            } break
            case 'GAMEPLAY':
            {
                // TODO: Draw GAMEPLAY screen here!
                r.DrawRectangle(0, 0, screenWidth, screenHeight, r.PURPLE)
                r.DrawText("GAMEPLAY SCREEN", 20, 20, 40, r.MAROON)
                r.DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, r.MAROON)

            } break
            case 'ENDING':
            {
                // TODO: Draw ENDING screen here!
                r.DrawRectangle(0, 0, screenWidth, screenHeight, r.BLUE);
                r.DrawText("ENDING SCREEN", 20, 20, 40, r.DARKBLUE);
                r.DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, r.DARKBLUE);

            } break
        }

    r.EndDrawing()
    //----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------

// TODO: Unload all loaded data (textures, fonts, audio) here!

r.CloseWindow()        // Close window and OpenGL context
github RobLoach / node-raylib / templates / simple_game / simple_game.js View on Github external
r.ClearBackground(r.RAYWHITE)

        switch(currentScreen)
        {
            case 'LOGO':
            {
                // TODO: Draw LOGO screen here!
                r.DrawText("LOGO SCREEN", 20, 20, 40, r.LIGHTGRAY)
                r.DrawText("WAIT for 2 SECONDS...", 290, 220, 20, r.GRAY)

            } break
            case 'TITLE':
            {
                // TODO: Draw TITLE screen here!
                r.DrawRectangle(0, 0, screenWidth, screenHeight, r.GREEN)
                r.DrawText("TITLE SCREEN", 20, 20, 40, r.DARKGREEN)
                r.DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, r.DARKGREEN)

            } break
            case 'GAMEPLAY':
            {
                // TODO: Draw GAMEPLAY screen here!
                r.DrawRectangle(0, 0, screenWidth, screenHeight, r.PURPLE)
                r.DrawText("GAMEPLAY SCREEN", 20, 20, 40, r.MAROON)
                r.DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, r.MAROON)

            } break
            case 'ENDING':
            {
                // TODO: Draw ENDING screen here!
                r.DrawRectangle(0, 0, screenWidth, screenHeight, r.BLUE);
github RobLoach / node-raylib / examples / core / core_2d_camera.js View on Github external
r.DrawRectangleRec(buildings[i], buildColors[i]);
      }

      r.DrawRectangleRec(player, r.RED);

      r.DrawLine(camera.target.x, -screenHeight*10, camera.target.x, screenHeight*10, r.GREEN);
      r.DrawLine(-screenWidth*10, camera.target.y, screenWidth*10, camera.target.y, r.GREEN);

    r.EndMode2D();

    r.DrawText("SCREEN AREA", 640, 10, 20, r.RED);

    r.DrawRectangle(0, 0, screenWidth, 5, r.RED);
    r.DrawRectangle(0, 5, 5, screenHeight - 10, r.RED);
    r.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, r.RED);
    r.DrawRectangle(0, screenHeight - 5, screenWidth, 5, r.RED);

    r.DrawRectangle( 10, 10, 250, 113, r.Fade(r.SKYBLUE, 0.5));
    r.DrawRectangleLines( 10, 10, 250, 113, r.BLUE);

    r.DrawText("Free 2d camera controls:", 20, 20, 10, r.BLACK);
    r.DrawText("- Right/Left to move Offset", 40, 40, 10, r.DARKGRAY);
    r.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, r.DARKGRAY);
    r.DrawText("- A / S to Rotate", 40, 80, 10, r.DARKGRAY);
    r.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, r.DARKGRAY);

  r.EndDrawing();
  //----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
github RobLoach / node-raylib / examples / core / core_3d_camera_first_person.js View on Github external
r.DrawPlane(r.Vector3(), r.Vector2(32, 32), r.LIGHTGRAY); // Draw ground
            r.DrawCube(r.Vector3(-16, 2.5, 0), 1, 5, 32, r.BLUE);     // Draw a blue wall
            r.DrawCube(r.Vector3(16, 2.5, 0), 1, 5, 32, r.LIME);      // Draw a green wall
            r.DrawCube(r.Vector3(0, 2.5, 16), 32, 5, 1, r.GOLD);      // Draw a yellow wall

            // Draw some cubes around
            for (let i = 0; i < MAX_COLUMNS; i++)
            {
                r.DrawCube(positions[i], 2, heights[i], 2, colors[i]);
                r.DrawCubeWires(positions[i], 2, heights[i], 2, r.MAROON);
            }

        r.EndMode3D();

        r.DrawRectangle( 10, 10, 220, 70, r.Fade(r.SKYBLUE, 0.5));
        r.DrawRectangleLines( 10, 10, 220, 70, r.BLUE);

        r.DrawText("First person camera default controls:", 20, 20, 10, r.BLACK);
        r.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, r.DARKGRAY);
        r.DrawText("- Mouse move to look around", 40, 60, 10, r.DARKGRAY);

    r.EndDrawing();
    //----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
r.CloseWindow();        // Close window and OpenGL context
//--------------------------------------------------------------------------------------
github RobLoach / node-raylib / examples / core / core_2d_camera.js View on Github external
for (var i = 0; i < MAX_BUILDINGS; i++) {
        r.DrawRectangleRec(buildings[i], buildColors[i]);
      }

      r.DrawRectangleRec(player, r.RED);

      r.DrawLine(camera.target.x, -screenHeight*10, camera.target.x, screenHeight*10, r.GREEN);
      r.DrawLine(-screenWidth*10, camera.target.y, screenWidth*10, camera.target.y, r.GREEN);

    r.EndMode2D();

    r.DrawText("SCREEN AREA", 640, 10, 20, r.RED);

    r.DrawRectangle(0, 0, screenWidth, 5, r.RED);
    r.DrawRectangle(0, 5, 5, screenHeight - 10, r.RED);
    r.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, r.RED);
    r.DrawRectangle(0, screenHeight - 5, screenWidth, 5, r.RED);

    r.DrawRectangle( 10, 10, 250, 113, r.Fade(r.SKYBLUE, 0.5));
    r.DrawRectangleLines( 10, 10, 250, 113, r.BLUE);

    r.DrawText("Free 2d camera controls:", 20, 20, 10, r.BLACK);
    r.DrawText("- Right/Left to move Offset", 40, 40, 10, r.DARKGRAY);
    r.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, r.DARKGRAY);
    r.DrawText("- A / S to Rotate", 40, 80, 10, r.DARKGRAY);
    r.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, r.DARKGRAY);

  r.EndDrawing();
  //----------------------------------------------------------------------------------
}

// De-Initialization
github RobLoach / node-raylib / templates / simple_game / simple_game.js View on Github external
r.DrawText("LOGO SCREEN", 20, 20, 40, r.LIGHTGRAY)
                r.DrawText("WAIT for 2 SECONDS...", 290, 220, 20, r.GRAY)

            } break
            case 'TITLE':
            {
                // TODO: Draw TITLE screen here!
                r.DrawRectangle(0, 0, screenWidth, screenHeight, r.GREEN)
                r.DrawText("TITLE SCREEN", 20, 20, 40, r.DARKGREEN)
                r.DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, r.DARKGREEN)

            } break
            case 'GAMEPLAY':
            {
                // TODO: Draw GAMEPLAY screen here!
                r.DrawRectangle(0, 0, screenWidth, screenHeight, r.PURPLE)
                r.DrawText("GAMEPLAY SCREEN", 20, 20, 40, r.MAROON)
                r.DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, r.MAROON)

            } break
            case 'ENDING':
            {
                // TODO: Draw ENDING screen here!
                r.DrawRectangle(0, 0, screenWidth, screenHeight, r.BLUE);
                r.DrawText("ENDING SCREEN", 20, 20, 40, r.DARKBLUE);
                r.DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, r.DARKBLUE);

            } break
        }

    r.EndDrawing()
    //----------------------------------------------------------------------------------
github RobLoach / node-raylib / examples / core / core_2d_camera.js View on Github external
r.DrawRectangleRec(player, r.RED);

      r.DrawLine(camera.target.x, -screenHeight*10, camera.target.x, screenHeight*10, r.GREEN);
      r.DrawLine(-screenWidth*10, camera.target.y, screenWidth*10, camera.target.y, r.GREEN);

    r.EndMode2D();

    r.DrawText("SCREEN AREA", 640, 10, 20, r.RED);

    r.DrawRectangle(0, 0, screenWidth, 5, r.RED);
    r.DrawRectangle(0, 5, 5, screenHeight - 10, r.RED);
    r.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, r.RED);
    r.DrawRectangle(0, screenHeight - 5, screenWidth, 5, r.RED);

    r.DrawRectangle( 10, 10, 250, 113, r.Fade(r.SKYBLUE, 0.5));
    r.DrawRectangleLines( 10, 10, 250, 113, r.BLUE);

    r.DrawText("Free 2d camera controls:", 20, 20, 10, r.BLACK);
    r.DrawText("- Right/Left to move Offset", 40, 40, 10, r.DARKGRAY);
    r.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, r.DARKGRAY);
    r.DrawText("- A / S to Rotate", 40, 80, 10, r.DARKGRAY);
    r.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, r.DARKGRAY);

  r.EndDrawing();
  //----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
r.CloseWindow();        // Close window and OpenGL context
//--------------------------------------------------------------------------------------
github RobLoach / node-raylib / examples / core / core_2d_camera.js View on Github external
r.DrawRectangle(-6000, 320, 13000, 8000, r.DARKGRAY);

      for (var i = 0; i < MAX_BUILDINGS; i++) {
        r.DrawRectangleRec(buildings[i], buildColors[i]);
      }

      r.DrawRectangleRec(player, r.RED);

      r.DrawLine(camera.target.x, -screenHeight*10, camera.target.x, screenHeight*10, r.GREEN);
      r.DrawLine(-screenWidth*10, camera.target.y, screenWidth*10, camera.target.y, r.GREEN);

    r.EndMode2D();

    r.DrawText("SCREEN AREA", 640, 10, 20, r.RED);

    r.DrawRectangle(0, 0, screenWidth, 5, r.RED);
    r.DrawRectangle(0, 5, 5, screenHeight - 10, r.RED);
    r.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, r.RED);
    r.DrawRectangle(0, screenHeight - 5, screenWidth, 5, r.RED);

    r.DrawRectangle( 10, 10, 250, 113, r.Fade(r.SKYBLUE, 0.5));
    r.DrawRectangleLines( 10, 10, 250, 113, r.BLUE);

    r.DrawText("Free 2d camera controls:", 20, 20, 10, r.BLACK);
    r.DrawText("- Right/Left to move Offset", 40, 40, 10, r.DARKGRAY);
    r.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, r.DARKGRAY);
    r.DrawText("- A / S to Rotate", 40, 80, 10, r.DARKGRAY);
    r.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, r.DARKGRAY);

  r.EndDrawing();
  //----------------------------------------------------------------------------------
}
github RobLoach / node-raylib / examples / core / core_2d_camera.js View on Github external
for (var i = 0; i < MAX_BUILDINGS; i++) {
        r.DrawRectangleRec(buildings[i], buildColors[i]);
      }

      r.DrawRectangleRec(player, r.RED);

      r.DrawLine(camera.target.x, -screenHeight*10, camera.target.x, screenHeight*10, r.GREEN);
      r.DrawLine(-screenWidth*10, camera.target.y, screenWidth*10, camera.target.y, r.GREEN);

    r.EndMode2D();

    r.DrawText("SCREEN AREA", 640, 10, 20, r.RED);

    r.DrawRectangle(0, 0, screenWidth, 5, r.RED);
    r.DrawRectangle(0, 5, 5, screenHeight - 10, r.RED);
    r.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, r.RED);
    r.DrawRectangle(0, screenHeight - 5, screenWidth, 5, r.RED);

    r.DrawRectangle( 10, 10, 250, 113, r.Fade(r.SKYBLUE, 0.5));
    r.DrawRectangleLines( 10, 10, 250, 113, r.BLUE);

    r.DrawText("Free 2d camera controls:", 20, 20, 10, r.BLACK);
    r.DrawText("- Right/Left to move Offset", 40, 40, 10, r.DARKGRAY);
    r.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, r.DARKGRAY);
    r.DrawText("- A / S to Rotate", 40, 80, 10, r.DARKGRAY);
    r.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, r.DARKGRAY);

  r.EndDrawing();
  //----------------------------------------------------------------------------------
}