zig-raylib/src/main.zig

75 lines
2.5 KiB
Zig
Raw Normal View History

2024-11-08 09:34:08 +00:00
const std = @import("std");
const rl = @import("raylib");
const rg = @import("raygui");
2024-11-08 15:00:57 +00:00
const pr = @import("primitives.zig");
const Particle = struct{
const Self = @This();
position : pr.Vec = .{.a = .{.x=0,.y=0,.z=0}},
velocity : pr.Vec = .{.a = .{.x=0,.y=0,.z=0}},
acceleration : pr.Vec = .{.a = .{.x=0,.y=0,.z=0}},
pub fn new(self:Self)void{
_ = self;
}
pub fn update(self:Self)void{
self.velocity = self.velocity + self.acceleration;
self.position = self.position + self.velocity;
}
};
2024-11-08 09:34:08 +00:00
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
const screenHeight = 450;
const rect2 = rl.Rectangle{ .x = @as(f32, @floatFromInt(10)), .y = @as(f32, @floatFromInt(10)), .width = @as(f32, @floatFromInt(300)), .height = @as(f32, @floatFromInt(100)) };
var msg_res : i32=-1;
var state : i32=-1;
2024-11-08 15:00:57 +00:00
const p1 = Particle{.velocity = .{.a = .{.x = 1,.y = 1}}};
2024-11-08 09:34:08 +00:00
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
defer rl.closeWindow(); // Close window and OpenGL context
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
while (!rl.windowShouldClose()) { // Detect window close button or ESC key
2024-11-08 15:00:57 +00:00
rl.beginDrawing();
defer rl.endDrawing();
2024-11-08 09:34:08 +00:00
2024-11-08 15:00:57 +00:00
rl.clearBackground(rl.Color{.r=181,
.g =177,
.b =154,
.a = 255,
});
2024-11-08 09:34:08 +00:00
if(state != 0){
2024-11-08 15:00:57 +00:00
msg_res = rg.guiMessageBox(rect2, "Title", "question?", "Nice;Cool");
2024-11-08 09:34:08 +00:00
if(msg_res > -1){
state = msg_res;
}
rl.clearBackground(rl.Color.white);
switch(state){
1 => {
rl.drawText("1", 190, 200, 20, rl.Color.red);
},
2 => {
rl.drawText("2", 190, 200, 20, rl.Color.red);
},
else =>{},
}
}
2024-11-08 15:00:57 +00:00
p1.update();
rl.drawCircle(p1.position.a.x,p1.position.a.y,40,rl.Color{.r=124,.g=195,.b=217,.a=100});
2024-11-08 09:34:08 +00:00
}
}
test "simple test" {
var list = std.ArrayList(i32).init(std.testing.allocator);
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
try list.append(42);
try std.testing.expectEqual(@as(i32, 42), list.pop());
}