zig-learn/movement.zig

45 lines
1.0 KiB
Zig
Raw Permalink Normal View History

2024-10-30 09:38:15 +00:00
const term = @import("term.zig");
const Winsize = term.Winsize;
const primitive = @import("primitives.zig");
const Point = primitive.Point;
pub fn mv_axis_border_bounce(w: Winsize, point: *Point, axis: u8) void {
var cor = &point.x;
var dir = &point.direction.x;
var upper = w.ws_col;
switch (axis) {
'x' => {
cor = &point.x;
upper = w.ws_col;
dir = &point.direction.x;
},
'y' => {
cor = &point.y;
upper = w.ws_row;
dir = &point.direction.y;
},
'X' => {
cor = &point.x;
upper = w.ws_col;
dir = &point.direction.x;
2024-11-01 14:24:59 +00:00
dir.* *= -1;
2024-10-30 09:38:15 +00:00
},
'Y' => {
cor = &point.y;
upper = w.ws_row;
dir = &point.direction.y;
2024-11-01 14:24:59 +00:00
dir.* *= -1;
2024-10-30 09:38:15 +00:00
},
else => {},
}
2024-11-01 14:24:59 +00:00
//if (cor.* < upper and cor.* > 0) {
cor.* += dir.*;
// }
2024-10-30 09:38:15 +00:00
if (cor.* >= upper or cor.* <= 0) {
dir.* *= -1;
cor.* += dir.*;
}
}