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);
}
}

View file

@ -23,7 +23,7 @@ pub fn main() anyerror!void {
var outlineSize: f32 = 2.0;
const outlineColor = [4]f32{ 1.0, 0.0, 0.0, 1.0 }; // Normalized RED color
const textureSize = rl.Vector2.init(@intToFloat(f32, texture.width), @intToFloat(f32, texture.height));
const textureSize = rl.Vector2.init(@as(f32, @floatFromInt(texture.width)), @as(f32, @floatFromInt(texture.height)));
// Get shader locations
const outlineSizeLoc = rl.getShaderLocation(shdrOutline, "outlineSize");
@ -31,9 +31,9 @@ pub fn main() anyerror!void {
const textureSizeLoc = rl.getShaderLocation(shdrOutline, "textureSize");
// Set shader values (they can be changed later)
rl.setShaderValue(shdrOutline, outlineSizeLoc, &outlineSize, @enumToInt(rl.ShaderUniformDataType.shader_uniform_float));
rl.setShaderValue(shdrOutline, outlineColorLoc, &outlineColor, @enumToInt(rl.ShaderUniformDataType.shader_uniform_vec4));
rl.setShaderValue(shdrOutline, textureSizeLoc, &textureSize, @enumToInt(rl.ShaderUniformDataType.shader_uniform_vec2));
rl.setShaderValue(shdrOutline, outlineSizeLoc, &outlineSize, @intFromEnum(rl.ShaderUniformDataType.shader_uniform_float));
rl.setShaderValue(shdrOutline, outlineColorLoc, &outlineColor, @intFromEnum(rl.ShaderUniformDataType.shader_uniform_vec4));
rl.setShaderValue(shdrOutline, textureSizeLoc, &textureSize, @intFromEnum(rl.ShaderUniformDataType.shader_uniform_vec2));
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -45,7 +45,7 @@ pub fn main() anyerror!void {
outlineSize += rl.getMouseWheelMove();
if (outlineSize < 1.0) outlineSize = 1.0;
rl.setShaderValue(shdrOutline, outlineSizeLoc, &outlineSize, @enumToInt(rl.ShaderUniformDataType.shader_uniform_float));
rl.setShaderValue(shdrOutline, outlineSizeLoc, &outlineSize, @intFromEnum(rl.ShaderUniformDataType.shader_uniform_float));
//----------------------------------------------------------------------------------
// Draw
@ -64,7 +64,7 @@ pub fn main() anyerror!void {
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.Color.maroon);
rl.drawText(rl.textFormat("Outline size: %i px", .{@as(i32, @intFromFloat(outlineSize))}), 10, 120, 20, rl.Color.maroon);
rl.drawFPS(710, 10);
//----------------------------------------------------------------------------------

View file

@ -21,7 +21,7 @@ pub fn main() anyerror!void {
defer rl.unloadTexture(scarfy); // Texture unloading
const position = rl.Vector2.init(350.0, 280.0);
var frameRec = rl.Rectangle.init(0, 0, @intToFloat(f32, @divFloor(scarfy.width, 6)), @intToFloat(f32, scarfy.height));
var frameRec = rl.Rectangle.init(0, 0, @as(f32, @floatFromInt(@divFloor(scarfy.width, 6))), @as(f32, @floatFromInt(scarfy.height)));
var currentFrame: u8 = 0;
var framesCounter: u8 = 0;
@ -42,7 +42,7 @@ pub fn main() anyerror!void {
if (currentFrame > 5) currentFrame = 0;
frameRec.x = @intToFloat(f32, currentFrame) * @intToFloat(f32, @divFloor(scarfy.width, 6));
frameRec.x = @as(f32, @floatFromInt(currentFrame)) * @as(f32, @floatFromInt(@divFloor(scarfy.width, 6)));
}
// Control frames speed
@ -69,17 +69,17 @@ pub fn main() anyerror!void {
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.drawRectangleLines(15 + @as(i32, @intFromFloat(frameRec.x)), 40 + @as(i32, @intFromFloat(frameRec.y)), @as(i32, @intFromFloat(frameRec.width)), @as(i32, @intFromFloat(frameRec.height)), rl.Color.red);
rl.drawText("FRAME SPEED: ", 165, 210, 10, rl.Color.dark_gray);
rl.drawText(rl.textFormat("%02i FPS", .{framesSpeed}), 575, 210, 10, rl.Color.dark_gray);
rl.drawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, rl.Color.dark_gray);
for ([_]u32{0} ** MAX_FRAME_SPEED) |_, i| {
for ([_]u32{0} ** MAX_FRAME_SPEED, 0..) |_, i| {
if (i < framesSpeed) {
rl.drawRectangle(250 + 21 * @intCast(i32, i), 205, 20, 20, rl.Color.red);
rl.drawRectangle(250 + 21 * @as(i32, @intCast(i)), 205, 20, 20, rl.Color.red);
}
rl.drawRectangleLines(250 + 21 * @intCast(i32, i), 205, 20, 20, rl.Color.maroon);
rl.drawRectangleLines(250 + 21 * @as(i32, @intCast(i)), 205, 20, 20, rl.Color.maroon);
}
scarfy.drawRec(frameRec, position, rl.Color.white); // Draw part of the texture