commit while it finally compiles again
This commit is contained in:
121
src/main.zig
121
src/main.zig
@ -7,18 +7,114 @@ const Vec2 = rl.Vector2;
|
||||
const Frug = struct {
|
||||
pos: Vec3,
|
||||
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(
|
||||
Vec2.init(self.pos.x, self.pos.y),
|
||||
self.radius,
|
||||
.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);
|
||||
|
||||
const frug = Frug.init();
|
||||
var game = Game.init(frugBurp);
|
||||
|
||||
while (!rl.windowShouldClose()) {
|
||||
const dt = rl.getFrameTime();
|
||||
|
||||
game.handleInput(dt);
|
||||
game.update(dt);
|
||||
|
||||
rl.beginDrawing();
|
||||
defer rl.endDrawing();
|
||||
|
||||
if (rl.isKeyPressed(.space)) rl.playSound(frugBurp);
|
||||
|
||||
rl.clearBackground(.sky_blue);
|
||||
|
||||
frug.draw();
|
||||
|
||||
rl.drawText("FRUGG!", 10, 10, 40, .green);
|
||||
game.draw();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user