Move colors into color struct

This commit is contained in:
Not-Nik 2023-07-10 00:57:02 +02:00
parent 642ca0513f
commit c564af4f61
No known key found for this signature in database
GPG Key ID: 08BB71E672DB3BFD
11 changed files with 124 additions and 124 deletions

View File

@ -81,38 +81,38 @@ pub fn main() anyerror!void {
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.Color.RAYWHITE);
camera.begin();
rl.DrawRectangle(-6000, 320, 13000, 8000, rl.DARKGRAY);
rl.DrawRectangle(-6000, 320, 13000, 8000, rl.Color.DARKGRAY);
for (buildings) |building, i| {
rl.DrawRectangleRec(building, buildColors[i]);
}
rl.DrawRectangleRec(player, rl.RED);
rl.DrawRectangleRec(player, rl.Color.RED);
rl.DrawLine(@floatToInt(c_int, camera.target.x), -screenHeight * 10, @floatToInt(c_int, camera.target.x), screenHeight * 10, rl.GREEN);
rl.DrawLine(-screenWidth * 10, @floatToInt(c_int, camera.target.y), screenWidth * 10, @floatToInt(c_int, camera.target.y), rl.GREEN);
rl.DrawLine(@floatToInt(c_int, camera.target.x), -screenHeight * 10, @floatToInt(c_int, camera.target.x), screenHeight * 10, rl.Color.GREEN);
rl.DrawLine(-screenWidth * 10, @floatToInt(c_int, camera.target.y), screenWidth * 10, @floatToInt(c_int, camera.target.y), rl.Color.GREEN);
camera.end();
rl.DrawText("SCREEN AREA", 640, 10, 20, rl.RED);
rl.DrawText("SCREEN AREA", 640, 10, 20, rl.Color.RED);
rl.DrawRectangle(0, 0, screenWidth, 5, rl.RED);
rl.DrawRectangle(0, 5, 5, screenHeight - 10, rl.RED);
rl.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, rl.RED);
rl.DrawRectangle(0, screenHeight - 5, screenWidth, 5, rl.RED);
rl.DrawRectangle(0, 0, screenWidth, 5, rl.Color.RED);
rl.DrawRectangle(0, 5, 5, screenHeight - 10, rl.Color.RED);
rl.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, rl.Color.RED);
rl.DrawRectangle(0, screenHeight - 5, screenWidth, 5, rl.Color.RED);
rl.DrawRectangle(10, 10, 250, 113, rl.Fade(rl.SKYBLUE, 0.5));
rl.DrawRectangleLines(10, 10, 250, 113, rl.BLUE);
rl.DrawRectangle(10, 10, 250, 113, rl.Fade(rl.Color.SKYBLUE, 0.5));
rl.DrawRectangleLines(10, 10, 250, 113, rl.Color.BLUE);
rl.DrawText("Free 2d camera controls:", 20, 20, 10, rl.BLACK);
rl.DrawText("- Right/Left to move Offset", 40, 40, 10, rl.DARKGRAY);
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.DARKGRAY);
rl.DrawText("- A / S to Rotate", 40, 80, 10, rl.DARKGRAY);
rl.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, rl.DARKGRAY);
rl.DrawText("Free 2d camera controls:", 20, 20, 10, rl.Color.BLACK);
rl.DrawText("- Right/Left to move Offset", 40, 40, 10, rl.Color.DARKGRAY);
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.Color.DARKGRAY);
rl.DrawText("- A / S to Rotate", 40, 80, 10, rl.Color.DARKGRAY);
rl.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, rl.Color.DARKGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------

View File

@ -47,30 +47,30 @@ pub fn main() anyerror!void {
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.Color.RAYWHITE);
camera.begin();
// Draw ground
rl.DrawPlane(rl.Vector3.init(0, 0, 0), rl.Vector2.init(32, 32), rl.LIGHTGRAY);
rl.DrawCube(rl.Vector3.init(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.BLUE); // Draw a blue wall
rl.DrawCube(rl.Vector3.init(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.LIME); // Draw a green wall
rl.DrawCube(rl.Vector3.init(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.GOLD); // Draw a yellow wall
rl.DrawPlane(rl.Vector3.init(0, 0, 0), rl.Vector2.init(32, 32), rl.Color.LIGHTGRAY);
rl.DrawCube(rl.Vector3.init(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Color.BLUE); // Draw a blue wall
rl.DrawCube(rl.Vector3.init(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Color.LIME); // Draw a green wall
rl.DrawCube(rl.Vector3.init(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.Color.GOLD); // Draw a yellow wall
// Draw some cubes around
for (heights) |height, i| {
rl.DrawCube(positions[i], 2.0, height, 2.0, colors[i]);
rl.DrawCubeWires(positions[i], 2.0, height, 2.0, rl.MAROON);
rl.DrawCubeWires(positions[i], 2.0, height, 2.0, rl.Color.MAROON);
}
camera.end();
rl.DrawRectangle(10, 10, 220, 70, rl.Fade(rl.SKYBLUE, 0.5));
rl.DrawRectangleLines(10, 10, 220, 70, rl.BLUE);
rl.DrawRectangle(10, 10, 220, 70, rl.Fade(rl.Color.SKYBLUE, 0.5));
rl.DrawRectangleLines(10, 10, 220, 70, rl.Color.BLUE);
rl.DrawText("First person camera default controls:", 20, 20, 10, rl.BLACK);
rl.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, rl.DARKGRAY);
rl.DrawText("- Mouse move to look around", 40, 60, 10, rl.DARKGRAY);
rl.DrawText("First person camera default controls:", 20, 20, 10, rl.Color.BLACK);
rl.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, rl.Color.DARKGRAY);
rl.DrawText("- Mouse move to look around", 40, 60, 10, rl.Color.DARKGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------

View File

@ -24,9 +24,9 @@ pub fn main() anyerror!void {
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.WHITE);
rl.ClearBackground(rl.Color.WHITE);
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LIGHTGRAY);
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.LIGHTGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------

View File

@ -38,11 +38,11 @@ pub fn main() anyerror!void {
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.Color.RAYWHITE);
rl.DrawText("move the ball with arrow keys", 10, 10, 20, rl.DARKGRAY);
rl.DrawText("move the ball with arrow keys", 10, 10, 20, rl.Color.DARKGRAY);
rl.DrawCircleV(ballPosition, 50, rl.MAROON);
rl.DrawCircleV(ballPosition, 50, rl.Color.MAROON);
rl.EndDrawing();
//----------------------------------------------------------------------------------

View File

@ -11,7 +11,7 @@ pub fn main() anyerror!void {
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - mouse input");
var ballPosition = rl.Vector2.init(-100, -100);
var ballColor = rl.DARKBLUE;
var ballColor = rl.Color.DARKBLUE;
rl.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -25,11 +25,11 @@ pub fn main() anyerror!void {
ballPosition.y = @intToFloat(f32, rl.GetMouseY());
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
ballColor = rl.MAROON;
ballColor = rl.Color.MAROON;
} else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
ballColor = rl.LIME;
ballColor = rl.Color.LIME;
} else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
ballColor = rl.DARKBLUE;
ballColor = rl.Color.DARKBLUE;
}
//----------------------------------------------------------------------------------
@ -37,12 +37,12 @@ pub fn main() anyerror!void {
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.Color.RAYWHITE);
rl.DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 50, ballColor);
//DrawCircleV(ballPosition, 40, ballColor);
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.DARKGRAY);
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.Color.DARKGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------

View File

@ -27,12 +27,12 @@ pub fn main() anyerror!void {
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.WHITE);
rl.ClearBackground(rl.Color.WHITE);
rl.DrawRectangle(screenWidth / 2 - 40, @floatToInt(c_int, boxPositionY), 80, 80, rl.MAROON);
rl.DrawRectangle(screenWidth / 2 - 40, @floatToInt(c_int, boxPositionY), 80, 80, rl.Color.MAROON);
rl.DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rl.GRAY);
rl.DrawText(rl.TextFormat("Box position Y: %03i", @floatToInt(c_int, boxPositionY)), 10, 40, 20, rl.LIGHTGRAY);
rl.DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rl.Color.GRAY);
rl.DrawText(rl.TextFormat("Box position Y: %03i", @floatToInt(c_int, boxPositionY)), 10, 40, 20, rl.Color.LIGHTGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------

View File

@ -11,7 +11,7 @@ pub fn main() anyerror!void {
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
var ballPosition = rl.Vector2.init(-100, -100);
var ballColor = rl.BEIGE;
var ballColor = rl.Color.BEIGE;
var touchCounter: f32 = 0;
var touchPosition = rl.Vector2.init(0, 0);
@ -25,16 +25,16 @@ pub fn main() anyerror!void {
//----------------------------------------------------------------------------------
ballPosition = rl.GetMousePosition();
ballColor = rl.BEIGE;
ballColor = rl.Color.BEIGE;
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
ballColor = rl.MAROON;
ballColor = rl.Color.MAROON;
}
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
ballColor = rl.LIME;
ballColor = rl.Color.LIME;
}
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
ballColor = rl.DARKBLUE;
ballColor = rl.Color.DARKBLUE;
}
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
@ -56,7 +56,7 @@ pub fn main() anyerror!void {
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.Color.RAYWHITE);
const nums = [_]i32{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (nums) |i| {
@ -66,16 +66,16 @@ pub fn main() anyerror!void {
if ((touchPosition.x >= 0) and (touchPosition.y >= 0)) {
// Draw circle and touch index number
rl.DrawCircleV(touchPosition, 34, rl.ORANGE);
rl.DrawText(rl.TextFormat("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, rl.BLACK);
rl.DrawCircleV(touchPosition, 34, rl.Color.ORANGE);
rl.DrawText(rl.TextFormat("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, rl.Color.BLACK);
}
}
// Draw the normal mouse location
rl.DrawCircleV(ballPosition, 30 + (touchCounter * 3), ballColor);
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.DARKGRAY);
rl.DrawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, rl.DARKGRAY);
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.Color.DARKGRAY);
rl.DrawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, rl.Color.DARKGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------

View File

@ -49,17 +49,17 @@ pub fn main() anyerror!void {
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.Color.RAYWHITE);
rl.BeginShaderMode(shdrOutline);
rl.DrawTexture(texture, @divFloor(rl.GetScreenWidth(), 2) - @divFloor(texture.width, 2), -30, rl.WHITE);
rl.DrawTexture(texture, @divFloor(rl.GetScreenWidth(), 2) - @divFloor(texture.width, 2), -30, rl.Color.WHITE);
rl.EndShaderMode();
rl.DrawText("Shader-based\ntexture\noutline", 10, 10, 20, rl.GRAY);
rl.DrawText("Shader-based\ntexture\noutline", 10, 10, 20, rl.Color.GRAY);
rl.DrawText(rl.TextFormat("Outline size: %i px", @floatToInt(i32, outlineSize)), 10, 120, 20, rl.MAROON);
rl.DrawText(rl.TextFormat("Outline size: %i px", @floatToInt(i32, outlineSize)), 10, 120, 20, rl.Color.MAROON);
rl.DrawFPS(710, 10);

View File

@ -62,26 +62,26 @@ pub fn main() anyerror!void {
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.Color.RAYWHITE);
rl.DrawTexture(scarfy, 15, 40, rl.WHITE);
rl.DrawRectangleLines(15, 40, scarfy.width, scarfy.height, rl.LIME);
rl.DrawRectangleLines(15 + @floatToInt(i32, frameRec.x), 40 + @floatToInt(i32, frameRec.y), @floatToInt(i32, frameRec.width), @floatToInt(i32, frameRec.height), rl.RED);
rl.DrawTexture(scarfy, 15, 40, rl.Color.WHITE);
rl.DrawRectangleLines(15, 40, scarfy.width, scarfy.height, rl.Color.LIME);
rl.DrawRectangleLines(15 + @floatToInt(i32, frameRec.x), 40 + @floatToInt(i32, frameRec.y), @floatToInt(i32, frameRec.width), @floatToInt(i32, frameRec.height), rl.Color.RED);
rl.DrawText("FRAME SPEED: ", 165, 210, 10, rl.DARKGRAY);
rl.DrawText(rl.TextFormat("%02i FPS", framesSpeed), 575, 210, 10, rl.DARKGRAY);
rl.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, rl.DARKGRAY);
rl.DrawText("FRAME SPEED: ", 165, 210, 10, rl.Color.DARKGRAY);
rl.DrawText(rl.TextFormat("%02i FPS", framesSpeed), 575, 210, 10, rl.Color.DARKGRAY);
rl.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, rl.Color.DARKGRAY);
for ([_]u32{0} ** MAX_FRAME_SPEED) |_, i| {
if (i < framesSpeed) {
rl.DrawRectangle(250 + 21 * @intCast(c_int, i), 205, 20, 20, rl.RED);
rl.DrawRectangle(250 + 21 * @intCast(c_int, i), 205, 20, 20, rl.Color.RED);
}
rl.DrawRectangleLines(250 + 21 * @intCast(c_int, i), 205, 20, 20, rl.MAROON);
rl.DrawRectangleLines(250 + 21 * @intCast(c_int, i), 205, 20, 20, rl.Color.MAROON);
}
rl.DrawTextureRec(scarfy, frameRec, position, rl.WHITE); // Draw part of the texture
rl.DrawTextureRec(scarfy, frameRec, position, rl.Color.WHITE); // Draw part of the texture
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, rl.GRAY);
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, rl.Color.GRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------

View File

@ -58,11 +58,6 @@ pub const Color = extern struct {
b: u8,
a: u8,
pub fn init(r: u8, g: u8, b: u8, a: u8) Color {
return Color{ .r = r, .g = g, .b = b, .a = a };
}
};
pub const LIGHTGRAY = Color.init(200, 200, 200, 255);
pub const GRAY = Color.init(130, 130, 130, 255);
pub const DARKGRAY = Color.init(80, 80, 80, 255);
@ -91,6 +86,11 @@ pub const BLANK = Color.init(0, 0, 0, 0);
pub const MAGENTA = Color.init(255, 0, 255, 255);
pub const RAYWHITE = Color.init(245, 245, 245, 255);
pub fn init(r: u8, g: u8, b: u8, a: u8) Color {
return Color{ .r = r, .g = g, .b = b, .a = a };
}
};
pub const Rectangle = extern struct {
x: f32,
y: f32,

View File

@ -58,11 +58,6 @@ pub const Color = extern struct {
b: u8,
a: u8,
pub fn init(r: u8, g: u8, b: u8, a: u8) Color {
return Color{ .r = r, .g = g, .b = b, .a = a };
}
};
pub const LIGHTGRAY = Color.init(200, 200, 200, 255);
pub const GRAY = Color.init(130, 130, 130, 255);
pub const DARKGRAY = Color.init(80, 80, 80, 255);
@ -91,6 +86,11 @@ pub const BLANK = Color.init(0, 0, 0, 0);
pub const MAGENTA = Color.init(255, 0, 255, 255);
pub const RAYWHITE = Color.init(245, 245, 245, 255);
pub fn init(r: u8, g: u8, b: u8, a: u8) Color {
return Color{ .r = r, .g = g, .b = b, .a = a };
}
};
pub const Rectangle = extern struct {
x: f32,
y: f32,