tamamo/src/sh0rk.zig

47 lines
1.2 KiB
Zig

pub const Point = packed struct {
x: i32,
y: i32,
pub fn init(x: i32, y: i32) @This() {
return @This() {
.x = x,
.y = y,
};
}
pub fn equals(this: @This(), other: @This()) bool {
return this.x == other.x and this.y == other.y;
}
};
pub const Rect = packed struct {
base: Point,
width: i32,
height: i32,
pub fn init(base: Point, width: i32, height: i32) @This() {
return @This() {
.base = base,
.width = width,
.height = height,
};
}
pub fn inside(this: @This(), point: Point) bool {
return point.x >= this.base.x and point.x < this.base.x + this.width and point.y >= this.base.y and point.y < this.base.y + this.height;
}
pub fn collides(this: @This(), other: @This()) bool {
return this.base.x < other.base.x + other.width and this.base.x + this.width > other.base.x and this.base.y < other.base.y + other.height and this.base.y + this.height > other.base.y;
}
};
pub const Direction = enum(u2) {
Up,
Down,
Left,
Right,
};
pub const Tile = packed struct {
x: u4,
y: u4,
};