summaryrefslogtreecommitdiff
path: root/src/root.zig
diff options
context:
space:
mode:
authorAlec Goncharow <alec@goncharow.dev>2025-01-13 14:22:54 -0500
committerAlec Goncharow <alec@goncharow.dev>2025-01-13 14:22:54 -0500
commit4115e75af690ad56d758fe43a609e05de6f93199 (patch)
treef9286ed01239d434522488ce2d8dd7d3a51493db /src/root.zig
parent0048221026e22efad5b8539618dd54ce650956ba (diff)
some junkmain
Diffstat (limited to 'src/root.zig')
-rw-r--r--src/root.zig23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/root.zig b/src/root.zig
index 00a56ad..29e5d72 100644
--- a/src/root.zig
+++ b/src/root.zig
@@ -49,6 +49,10 @@ pub const HexCoord = struct {
return cubeRound(rl.Vector3{ .x = frac.x, .y = frac.y, .z = fracS(frac.x, frac.y) });
}
+ pub inline fn fakeDistance(from: HexCoord, to: HexCoord) u32 {
+ return @abs(from.q - to.q) + @abs(from.r - to.r);
+ }
+
pub inline fn cubeRound(frac: rl.Vector3) HexCoord {
var q = @round(frac.x);
var r = @round(frac.y);
@@ -86,8 +90,9 @@ pub fn setup() !void {
.world_coords = .{ .x = 0.0, .y = 0.0 },
.hex_coords = .{ .q = (grid_size / 2) + 1, .r = (grid_size / 2) + 1 },
.target_coords = .{ .q = (grid_size / 2) + 1, .r = (grid_size / 2) + 1 },
- .animation = Animation.init(),
+ .animation = Animation.init(.{ .x = 0.0, .y = 0.0 }, .{ .x = 0.0, .y = 0.0 }, 1.0),
};
+ context.main_dude.animation.active = false;
context.main_dude.world_coords = HexCoord.qrToWorld(@intCast(context.main_dude.hex_coords.q), @intCast(context.main_dude.hex_coords.r));
// TODO think what it means to populate a hex grid
@@ -124,7 +129,7 @@ pub fn update() !void {
// TODO FIXME laptop dev doesnt allow middle mouse and mouse move to happen
// at same time and im not yak shavin this
- if (rl.IsMouseButtonDown(rl.MOUSE_BUTTON_RIGHT)) {
+ if (rl.IsMouseButtonDown(rl.MOUSE_BUTTON_RIGHT) or rl.IsMouseButtonDown(rl.MOUSE_BUTTON_MIDDLE)) {
const delta = rl.GetMouseDelta();
var scale = @log2(@abs(delta.x) + @abs(delta.y));
if (delta.x == 0.0 and delta.y == 0.0) {
@@ -137,15 +142,15 @@ pub fn update() !void {
if (main_dude.animation.active) {
main_dude.world_coords = main_dude.animation.next();
- main_dude.hex_coords = main_dude.target_coords;
+ main_dude.hex_coords = HexCoord.worldToQr(main_dude.world_coords);
}
- if (!main_dude.animation.active and rl.IsMouseButtonDown(rl.MOUSE_BUTTON_LEFT)) {
- main_dude.animation.world_to = context.hovered_coords.toWorld();
- main_dude.animation.world_from = main_dude.hex_coords.toWorld();
- main_dude.animation.active = true;
- main_dude.animation.tick = 0;
- main_dude.target_coords = context.hovered_coords;
+ if (rl.IsMouseButtonDown(rl.MOUSE_BUTTON_LEFT)) {
+ if (!(main_dude.animation.world_to.x == context.hovered_coords.toWorld().x and main_dude.animation.world_to.y == context.hovered_coords.toWorld().y)) {
+ main_dude.animation = Animation.init(main_dude.world_coords, context.hovered_coords.toWorld(), 1);
+ std.debug.print("{}\n", .{main_dude.animation});
+ main_dude.target_coords = context.hovered_coords;
+ }
}
const wm = rl.GetMouseWheelMove();