Bump to Zig 0.11/raylib 4.6-dev

This commit is contained in:
Not-Nik 2023-07-21 17:04:56 +02:00
parent 9c5197bad4
commit edbd73e6be
Failed to generate hash of commit
19 changed files with 478 additions and 402 deletions

View file

@ -20,15 +20,15 @@ pub fn main() anyerror!void {
var spacing: i32 = 0;
for (buildings) |_, i| {
buildings[i].width = @intToFloat(f32, rl.getRandomValue(50, 200));
buildings[i].height = @intToFloat(f32, rl.getRandomValue(100, 800));
for (0..buildings.len) |i| {
buildings[i].width = @as(f32, @floatFromInt(rl.getRandomValue(50, 200)));
buildings[i].height = @as(f32, @floatFromInt(rl.getRandomValue(100, 800)));
buildings[i].y = screenHeight - 130 - buildings[i].height;
buildings[i].x = @intToFloat(f32, -6000 + spacing);
buildings[i].x = @as(f32, @floatFromInt(-6000 + spacing));
spacing += @floatToInt(i32, buildings[i].width);
spacing += @as(i32, @intFromFloat(buildings[i].width));
buildColors[i] = rl.Color.init(@intCast(u8, rl.getRandomValue(200, 240)), @intCast(u8, rl.getRandomValue(200, 240)), @intCast(u8, rl.getRandomValue(200, 250)), 255);
buildColors[i] = rl.Color.init(@as(u8, @intCast(rl.getRandomValue(200, 240))), @as(u8, @intCast(rl.getRandomValue(200, 240))), @as(u8, @intCast(rl.getRandomValue(200, 250))), 255);
}
var camera = rl.Camera2D{
@ -91,14 +91,14 @@ pub fn main() anyerror!void {
rl.drawRectangle(-6000, 320, 13000, 8000, rl.Color.dark_gray);
for (buildings) |building, i| {
for (buildings, 0..) |building, i| {
rl.drawRectangleRec(building, buildColors[i]);
}
rl.drawRectangleRec(player, rl.Color.red);
rl.drawLine(@floatToInt(i32, camera.target.x), -screenHeight * 10, @floatToInt(i32, camera.target.x), screenHeight * 10, rl.Color.green);
rl.drawLine(-screenWidth * 10, @floatToInt(i32, camera.target.y), screenWidth * 10, @floatToInt(i32, camera.target.y), rl.Color.green);
rl.drawLine(@as(i32, @intFromFloat(camera.target.x)), -screenHeight * 10, @as(i32, @intFromFloat(camera.target.x)), screenHeight * 10, rl.Color.green);
rl.drawLine(-screenWidth * 10, @as(i32, @intFromFloat(camera.target.y)), screenWidth * 10, @as(i32, @intFromFloat(camera.target.y)), rl.Color.green);
}
rl.drawText("SCREEN AREA", 640, 10, 20, rl.Color.red);

View file

@ -25,14 +25,12 @@ pub fn main() anyerror!void {
var positions: [MAX_COLUMNS]rl.Vector3 = undefined;
var colors: [MAX_COLUMNS]rl.Color = undefined;
for (heights) |_, i| {
heights[i] = @intToFloat(f32, rl.getRandomValue(1, 12));
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);
for (0..heights.len) |i| {
heights[i] = @as(f32, @floatFromInt(rl.getRandomValue(1, 12)));
positions[i] = rl.Vector3.init(@as(f32, @floatFromInt(rl.getRandomValue(-15, 15))), heights[i] / 2.0, @as(f32, @floatFromInt(rl.getRandomValue(-15, 15))));
colors[i] = rl.Color.init(@as(u8, @intCast(rl.getRandomValue(20, 255))), @as(u8, @intCast(rl.getRandomValue(10, 55))), 30, 255);
}
camera.setMode(rl.CameraMode.camera_first_person);
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -40,7 +38,7 @@ pub fn main() anyerror!void {
while (!rl.windowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
camera.update();
camera.update(rl.CameraMode.camera_first_person);
//----------------------------------------------------------------------------------
// Draw
@ -61,7 +59,7 @@ pub fn main() anyerror!void {
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| {
for (heights, 0..) |height, i| {
rl.drawCube(positions[i], 2.0, height, 2.0, colors[i]);
rl.drawCubeWires(positions[i], 2.0, height, 2.0, rl.Color.maroon);
}

View file

@ -22,8 +22,8 @@ pub fn main() anyerror!void {
// Update
//----------------------------------------------------------------------------------
ballPosition = rl.getMousePosition();
ballPosition.x = @intToFloat(f32, rl.getMouseX());
ballPosition.y = @intToFloat(f32, rl.getMouseY());
ballPosition.x = @as(f32, @floatFromInt(rl.getMouseX()));
ballPosition.y = @as(f32, @floatFromInt(rl.getMouseY()));
if (rl.isMouseButtonPressed(rl.MouseButton.mouse_button_left)) {
ballColor = rl.Color.maroon;

View file

@ -32,11 +32,11 @@ pub fn main() anyerror!void {
rl.clearBackground(rl.Color.white);
rl.drawRectangle(screenWidth / 2 - 40, @floatToInt(i32, boxPositionY), 80, 80, rl.Color.maroon);
rl.drawRectangle(screenWidth / 2 - 40, @as(i32, @intFromFloat(boxPositionY)), 80, 80, rl.Color.maroon);
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.light_gray);
rl.drawText(rl.textFormat("Box position Y: %03i", .{@as(i32, @intFromFloat(boxPositionY))}), 10, 40, 20, rl.Color.light_gray);
//----------------------------------------------------------------------------------
}
}

View file

@ -69,7 +69,7 @@ pub fn main() anyerror!void {
// Draw circle and touch index number
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);
rl.drawText(rl.textFormat("%d", .{i}), @as(i32, @intFromFloat(touchPosition.x)) - 10, @as(i32, @intFromFloat(touchPosition.y)) - 70, 40, rl.Color.black);
}
}