53 lines
1.2 KiB
Zig
53 lines
1.2 KiB
Zig
pub const Point = packed struct {
|
|
x: u16,
|
|
y: u16,
|
|
pub fn init(x: u16, y: u16) @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: u8,
|
|
height: u8,
|
|
pub fn init(base: Point, width: u8, height: u8) @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 Trigger = struct {
|
|
aura: Rect,
|
|
direction: Direction,
|
|
dialogue: []const u8,
|
|
};
|
|
|
|
pub const Tile = packed struct {
|
|
x: u4,
|
|
y: u4,
|
|
}; |