More convenience functions in structs

This commit is contained in:
Not-Nik 2023-07-09 19:31:27 +02:00
parent 42671d0195
commit 7a9cdd3af0
Failed to generate hash of commit
9 changed files with 167 additions and 71 deletions

View file

@ -27,12 +27,12 @@ pub fn main() anyerror!void {
spacing += @floatToInt(i32, buildings[i].width);
buildColors[i] = rl.Color{ .r = @intCast(u8, rl.GetRandomValue(200, 240)), .g = @intCast(u8, rl.GetRandomValue(200, 240)), .b = @intCast(u8, rl.GetRandomValue(200, 250)), .a = 255 };
buildColors[i] = rl.Color.init(@intCast(u8, rl.GetRandomValue(200, 240)), @intCast(u8, rl.GetRandomValue(200, 240)), @intCast(u8, rl.GetRandomValue(200, 250)), 255);
}
var camera = rl.Camera2D{
.target = rl.Vector2{ .x = player.x + 20, .y = player.y + 20 },
.offset = rl.Vector2{ .x = screenWidth / 2, .y = screenHeight / 2 },
.target = rl.Vector2.init(player.x + 20, player.y + 20),
.offset = rl.Vector2.init(screenWidth / 2, screenHeight / 2),
.rotation = 0,
.zoom = 1,
};
@ -53,7 +53,7 @@ pub fn main() anyerror!void {
}
// Camera target follows player
camera.target = rl.Vector2{ .x = player.x + 20, .y = player.y + 20 };
camera.target = rl.Vector2.init(player.x + 20, player.y + 20);
// Camera rotation controls
if (rl.IsKeyDown(rl.KeyboardKey.KEY_A)) {

View file

@ -14,9 +14,9 @@ pub fn main() anyerror!void {
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - 3d camera first person");
var camera = rl.Camera3D{
.position = rl.Vector3{ .x = 4, .y = 2, .z = 4 },
.target = rl.Vector3{ .x = 0, .y = 1.8, .z = 0 },
.up = rl.Vector3{ .x = 0, .y = 1, .z = 0 },
.position = rl.Vector3.init(4, 2, 4),
.target = rl.Vector3.init(0, 1.8, 0),
.up = rl.Vector3.init(0, 1, 0),
.fovy = 60,
.projection = rl.CameraProjection.CAMERA_PERSPECTIVE,
};
@ -27,8 +27,8 @@ pub fn main() anyerror!void {
for (heights) |_, i| {
heights[i] = @intToFloat(f32, rl.GetRandomValue(1, 12));
positions[i] = rl.Vector3{ .x = @intToFloat(f32, rl.GetRandomValue(-15, 15)), .y = heights[i] / 2.0, .z = @intToFloat(f32, rl.GetRandomValue(-15, 15)) };
colors[i] = rl.Color{ .r = @intCast(u8, rl.GetRandomValue(20, 255)), .g = @intCast(u8, rl.GetRandomValue(10, 55)), .b = 30, .a = 255 };
positions[i] = rl.Vector3.init(@intToFloat(f32, rl.GetRandomValue(-15, 15)), heights[i] / 2.0, @intToFloat(f32, rl.GetRandomValue(-15, 15)));
colors[i] = rl.Color.init(@intCast(u8, rl.GetRandomValue(20, 255)), @intCast(u8, rl.GetRandomValue(10, 55)), 30, 255);
}
camera.setMode(rl.CameraMode.CAMERA_FIRST_PERSON);
@ -52,10 +52,10 @@ pub fn main() anyerror!void {
camera.begin();
// Draw ground
rl.DrawPlane(rl.Vector3{ .x = 0.0, .y = 0.0, .z = 0.0 }, rl.Vector2{ .x = 32.0, .y = 32.0 }, rl.LIGHTGRAY);
rl.DrawCube(rl.Vector3{ .x = -16.0, .y = 2.5, .z = 0.0 }, 1.0, 5.0, 32.0, rl.BLUE); // Draw a blue wall
rl.DrawCube(rl.Vector3{ .x = 16.0, .y = 2.5, .z = 0.0 }, 1.0, 5.0, 32.0, rl.LIME); // Draw a green wall
rl.DrawCube(rl.Vector3{ .x = 0.0, .y = 2.5, .z = 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.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
// Draw some cubes around
for (heights) |height, i| {

View file

@ -10,7 +10,7 @@ pub fn main() anyerror!void {
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - keyboard input");
var ballPosition = rl.Vector2{ .x = screenWidth / 2, .y = screenHeight / 2 };
var ballPosition = rl.Vector2.init(screenWidth / 2, screenHeight / 2);
rl.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

View file

@ -10,7 +10,7 @@ pub fn main() anyerror!void {
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - mouse input");
var ballPosition = rl.Vector2{ .x = -100.0, .y = -100.0 };
var ballPosition = rl.Vector2.init(-100, -100);
var ballColor = rl.DARKBLUE;
rl.SetTargetFPS(60); // Set our game to run at 60 frames-per-second

View file

@ -10,11 +10,11 @@ pub fn main() anyerror!void {
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
var ballPosition = rl.Vector2{ .x = -100.0, .y = -100.0 };
var ballPosition = rl.Vector2.init(-100, -100);
var ballColor = rl.BEIGE;
var touchCounter: f32 = 0;
var touchPosition = rl.Vector2{ .x = 0.0, .y = 0.0 };
var touchPosition = rl.Vector2.init(0, 0);
rl.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------