zig-learn/movement.zig
jonathan santis 4c31674539 sdf
2024-11-01 15:24:59 +01:00

45 lines
1.0 KiB
Zig

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;
dir.* *= -1;
},
'Y' => {
cor = &point.y;
upper = w.ws_row;
dir = &point.direction.y;
dir.* *= -1;
},
else => {},
}
//if (cor.* < upper and cor.* > 0) {
cor.* += dir.*;
// }
if (cor.* >= upper or cor.* <= 0) {
dir.* *= -1;
cor.* += dir.*;
}
}