diff options
| author | Alec Goncharow <alec@goncharow.dev> | 2025-01-13 14:22:54 -0500 |
|---|---|---|
| committer | Alec Goncharow <alec@goncharow.dev> | 2025-01-13 14:22:54 -0500 |
| commit | 4115e75af690ad56d758fe43a609e05de6f93199 (patch) | |
| tree | f9286ed01239d434522488ce2d8dd7d3a51493db /src/Animation.zig | |
| parent | 0048221026e22efad5b8539618dd54ce650956ba (diff) | |
some junkmain
Diffstat (limited to 'src/Animation.zig')
| -rw-r--r-- | src/Animation.zig | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/Animation.zig b/src/Animation.zig index 93255ec..fe5a51e 100644 --- a/src/Animation.zig +++ b/src/Animation.zig @@ -5,17 +5,22 @@ const Animation = @This(); world_from: rl.Vector2, world_to: rl.Vector2, -duration: u32, // TODO frame independent durations +//distance: f32, // TODO frame independent durations +//speed: f32, // TODO frame independent durations +duration: u32, tick: u32, active: bool, -pub fn init() Animation { +// this is wrong, just do per tile/node animations between path finding nodes +pub fn init(world_from: rl.Vector2, world_to: rl.Vector2, speed: u32) Animation { return Animation{ - .world_from = .{ .x = 0.0, .y = 0.0 }, - .world_to = .{ .x = 0.0, .y = 0.0 }, - .duration = 60, // TODO speed based duration + .world_from = world_from, + .world_to = world_to, + //.distance = calc_distance(world_from, world_to), + //.speed = speed, + .duration = root.HexCoord.fakeDistance(root.HexCoord.worldToQr(world_from), root.HexCoord.worldToQr(world_to)) * 10 / speed, // TODO speed based duration .tick = 0, - .active = false, + .active = true, }; } @@ -29,6 +34,10 @@ pub fn next(self: *Animation) rl.Vector2 { return self.lerp(); } +inline fn calc_distance(from: rl.Vector2, to: rl.Vector2) f32 { + return @abs(from.x - to.x) + @abs(from.x - to.y); +} + inline fn lerp(self: *Animation) rl.Vector2 { const t: f32 = @as(f32, @floatFromInt(self.tick)) / @as(f32, @floatFromInt(self.duration)); const v1 = self.world_from; |
