summaryrefslogtreecommitdiff
path: root/src/Animation.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Animation.zig')
-rw-r--r--src/Animation.zig21
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;