Clean up build.zig and examples

This commit affects the build.zig and examples files. It reformats the
code to meet a 120 column limit. It also adjusts comments so that
there is a space after the comment symbol '//' and the grammar in the
comments has been fixed.
This commit is contained in:
vent 2023-09-11 16:04:32 +01:00
parent 4dbbea186e
commit a378960088
9 changed files with 219 additions and 71 deletions

View file

@ -28,7 +28,12 @@ pub fn main() anyerror!void {
spacing += @as(i32, @intFromFloat(buildings[i].width));
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);
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{
@ -97,8 +102,20 @@ pub fn main() anyerror!void {
rl.drawRectangleRec(player, rl.Color.red);
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.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

@ -27,8 +27,17 @@ pub fn main() anyerror!void {
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);
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,
);
}
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second

View file

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

@ -28,7 +28,7 @@ pub fn main() anyerror!void {
var model = LoadModel(resourceDir ++ "models/castle.obj"); // Load model
var texture = LoadTexture(resourceDir ++ "models/castle_diffuse.png"); // Load model texture
model.materials[0].maps[@enumToInt(MAP_DIFFUSE)].texture = texture; // Set map diffuse texture
model.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture; // Set map diffuse texture
var position = Vector3{ .x = 0.0, .y = 0.0, .z = 0.0 }; // Set model position
@ -64,7 +64,8 @@ pub fn main() anyerror!void {
{
UnloadModel(model); // Unload previous model
model = LoadModel(droppedFiles[0]); // Load new model
model.materials[0].maps[@enumToInt(MAP_DIFFUSE)].texture = texture; // Set current map diffuse texture
// Set current map diffuse texture
model.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture;
bounds = MeshBoundingBox(model.meshes[0]);
@ -74,7 +75,7 @@ pub fn main() anyerror!void {
// Unload current model texture and load new one
UnloadTexture(texture);
texture = LoadTexture(droppedFiles[0]);
model.materials[0].maps[@enumToInt(MAP_DIFFUSE)].texture = texture;
model.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture;
}
}

View file

@ -44,9 +44,9 @@ pub fn main() !void {
const texture = LoadTexture(resourceDir ++ "texel_checker.png");
// Assign texture to default model material
modelA.materials[0].maps[@enumToInt(MAP_DIFFUSE)].texture = texture;
modelB.materials[0].maps[@enumToInt(MAP_DIFFUSE)].texture = texture;
modelC.materials[0].maps[@enumToInt(MAP_DIFFUSE)].texture = texture;
modelA.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture;
modelB.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture;
modelC.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture;
var shader = LoadShader(
resourceDir ++ "/shaders/glsl330/base_lighting.vs",
@ -54,13 +54,13 @@ pub fn main() !void {
);
// Get some shader loactions
shader.locs[@enumToInt(ShaderLocationIndex.SHADER_LOC_MATRIX_MODEL)] = GetShaderLocation(shader, "matModel");
shader.locs[@enumToInt(ShaderLocationIndex.SHADER_LOC_VECTOR_VIEW)] = GetShaderLocation(shader, "viewPos");
shader.locs[@intFromEnum(ShaderLocationIndex.SHADER_LOC_MATRIX_MODEL)] = GetShaderLocation(shader, "matModel");
shader.locs[@intFromEnum(ShaderLocationIndex.SHADER_LOC_VECTOR_VIEW)] = GetShaderLocation(shader, "viewPos");
// ambient light level
const ambientLoc = GetShaderLocation(shader, "ambient");
const ambientVals = [4]f32{ 0.2, 0.2, 0.2, 1.0 };
SetShaderValue(shader, ambientLoc, &ambientVals, @enumToInt(ShaderUniformDataType.SHADER_UNIFORM_VEC4));
SetShaderValue(shader, ambientLoc, &ambientVals, @intFromEnum(ShaderUniformDataType.SHADER_UNIFORM_VEC4));
var angle: f32 = 6.282;
@ -126,7 +126,12 @@ pub fn main() !void {
// Update the light shader with the camera view position
const cameraPos = [3]f32{ camera.position.x, camera.position.y, camera.position.z };
SetShaderValue(shader, shader.locs[@enumToInt(ShaderLocationIndex.SHADER_LOC_VECTOR_VIEW)], &cameraPos, @enumToInt(ShaderUniformDataType.SHADER_UNIFORM_VEC3));
SetShaderValue(
shader,
shader.locs[@intFromEnum(ShaderLocationIndex.SHADER_LOC_VECTOR_VIEW)],
&cameraPos,
@intFromEnum(ShaderUniformDataType.SHADER_UNIFORM_VEC3),
);
//----------------------------------------------------------------------------------
// Draw

View file

@ -23,7 +23,10 @@ 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(@as(f32, @floatFromInt(texture.width)), @as(f32, @floatFromInt(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 +34,24 @@ pub fn main() anyerror!void {
const textureSizeLoc = rl.getShaderLocation(shdrOutline, "textureSize");
// Set shader values (they can be changed later)
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.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 +63,12 @@ pub fn main() anyerror!void {
outlineSize += rl.getMouseWheelMove();
if (outlineSize < 1.0) outlineSize = 1.0;
rl.setShaderValue(shdrOutline, outlineSizeLoc, &outlineSize, @intFromEnum(rl.ShaderUniformDataType.shader_uniform_float));
rl.setShaderValue(
shdrOutline,
outlineSizeLoc,
&outlineSize,
@intFromEnum(rl.ShaderUniformDataType.shader_uniform_float),
);
//----------------------------------------------------------------------------------
// Draw
@ -59,12 +82,22 @@ pub fn main() anyerror!void {
rl.beginShaderMode(shdrOutline);
defer rl.endShaderMode();
texture.draw(@divFloor(rl.getScreenWidth(), 2) - @divFloor(texture.width, 2), -30, rl.Color.white);
texture.draw(
@divFloor(rl.getScreenWidth(), 2) - @divFloor(texture.width, 2),
-30,
rl.Color.white,
);
}
rl.drawText("Shader-based\ntexture\noutline", 10, 10, 20, rl.Color.gray);
rl.drawText(rl.textFormat("Outline size: %i px", .{@as(i32, @intFromFloat(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,12 @@ 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, @as(f32, @floatFromInt(@divFloor(scarfy.width, 6))), @as(f32, @floatFromInt(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;
@ -69,7 +74,13 @@ 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 + @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.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);
@ -84,7 +95,13 @@ pub fn main() anyerror!void {
scarfy.drawRec(frameRec, position, rl.Color.white); // Draw part of the texture
rl.drawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, rl.Color.gray);
rl.drawText(
"(c) Scarfy sprite by Eiden Marsal",
screenWidth - 200,
screenHeight - 20,
10,
rl.Color.gray,
);
//----------------------------------------------------------------------------------
}
}