commit while it finally compiles again

This commit is contained in:
2026-05-09 17:02:51 +02:00
parent b5122a8da8
commit 66b7fed9e6

View File

@ -7,18 +7,114 @@ const Vec2 = rl.Vector2;
const Frug = struct { const Frug = struct {
pos: Vec3, pos: Vec3,
radius: f32 = 24, radius: f32 = 24,
pub fn draw(self: @This()) void {
charging: bool = false,
charge: f32 = 0,
frugBurp: rl.Sound,
pub fn init(frugBurp: rl.Sound) Frug {
return .{
.pos = .{ .x = 200, .y = 400, .z = 10 },
.frugBurp = frugBurp,
};
}
pub fn handleInput(self: *Frug, dt: f32) void {
if (rl.isKeyDown(.space)) {
self.charging = true;
self.charge += dt * 20.0;
}
if (rl.isKeyReleased(.space)) {
self.jump();
}
}
pub fn jump(self: *Frug) void {
rl.playSound(self.frugBurp);
self.charging = false;
self.charge = 0;
}
pub fn draw(self: Frug) void {
rl.drawCircleV( rl.drawCircleV(
Vec2.init(self.pos.x, self.pos.y), Vec2.init(self.pos.x, self.pos.y),
self.radius, self.radius,
.green, .green,
); );
} }
pub fn init() Frug {
return Frug{
.pos = .{ .x = 200, .y = 400, .z = 10 },
.radius = 24,
}; };
const Pad = struct {
pos: Vec2,
radius: f32 = 12,
pub fn draw(self: Pad) void {
rl.drawCircleV(
Vec2.init(self.pos.x, self.pos.y),
self.radius,
.red,
);
}
pub fn init() Pad {
return Pad{
.pos = Vec2.init(1, 1),
};
}
};
const Game = struct {
frug: Frug,
pads: [10]Pad,
charging: bool,
charge: f32,
pub fn init(frugBurp: rl.Sound) Game {
// just temporary non random pads
var pads: [10]Pad = undefined;
for (&pads, 0..) |*pad, i| {
pad.* = Pad.init();
pad.pos.x = 30 + 30 * @as(f32, @floatFromInt(i));
pad.pos.y = 20 + 20 * @as(f32, @floatFromInt(i));
}
return Game{
.frug = Frug.init(frugBurp),
.pads = pads,
.charging = false,
.charge = 0,
};
}
pub fn update(self: *Game, dt: f32) void {
self.frug.handleInput(dt);
}
pub fn draw(self: *Game) void {
rl.clearBackground(.sky_blue);
for (self.pads) |pad| {
pad.draw();
}
self.frug.draw();
rl.drawText("FRUGG!", 10, 10, 40, .green);
}
pub fn handleInput(self: *Game, dt: f32) void {
if (rl.isKeyDown(.space)) {
self.charging = true;
self.charge += dt * 20.0;
}
if (rl.isKeyReleased(.space)) {
self.frug.jump();
}
} }
}; };
@ -39,18 +135,17 @@ pub fn main(init: std.process.Init) anyerror!void {
rl.setTargetFPS(60); rl.setTargetFPS(60);
const frug = Frug.init(); var game = Game.init(frugBurp);
while (!rl.windowShouldClose()) { while (!rl.windowShouldClose()) {
const dt = rl.getFrameTime();
game.handleInput(dt);
game.update(dt);
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing(); defer rl.endDrawing();
if (rl.isKeyPressed(.space)) rl.playSound(frugBurp); game.draw();
rl.clearBackground(.sky_blue);
frug.draw();
rl.drawText("FRUGG!", 10, 10, 40, .green);
} }
} }