O36DJNAVPXS5ZYAD2T35DEOFC2GSTKQIQ7DM5EAPC22F3JF2LFIAC
const Drawable = union(enum) { rect: rl.Rectangle, color_rect: ColorRectangle };
const Velocity = struct { x: f32, y: f32 };
const Orientation = struct { direction: Direction };
const Drawable = union(enum) {
rect: rl.Rectangle,
color_rect: ColorRectangle,
color_circle: ColorCircle,
};
pos[i].y += 2;
vel.y += 2;
}
const x: i32 = @intFromFloat(math.sign(vel.x));
const y: i32 = @intFromFloat(math.sign(vel.y));
if (x == 1 and y == 0) {
orientation[i].direction = Direction.right;
} else if (x == 1 and y == 1) {
orientation[i].direction = Direction.down_right;
} else if (x == 0 and y == 1) {
orientation[i].direction = Direction.down;
} else if (x == -1 and y == 1) {
orientation[i].direction = Direction.down_left;
} else if (x == -1 and y == 0) {
orientation[i].direction = Direction.left;
} else if (x == -1 and y == -1) {
orientation[i].direction = Direction.top_left;
} else if (x == 0 and y == -1) {
orientation[i].direction = Direction.top;
} else if (x == 1 and y == -1) {
orientation[i].direction = Direction.top_right;
},
Drawable.color_circle => |d| {
const p = rl.Vector2{
.x = pos.x + d.circle.radius,
.y = pos.y + d.circle.radius,
};
rl.DrawCircleV(p, d.circle.radius, d.color);
if (orientation != null) {
const dir = orientation.?;
const cart = polarToCartesian(
d.circle.radius,
theta * @as(f32, @floatFromInt(@intFromEnum(dir[i].direction))),
);
const end = rl.Vector2{
.x = p.x + cart.x,
.y = p.y + cart.y,
};
rl.DrawLineV(
p,
end,
rl.BLACK,
);
}
};
const move_system = sys: {
var system_desc = ecs.system_desc_t{};
system_desc.callback = move;
system_desc.query.filter.terms[0] = .{ .id = ecs.id(Position) };
system_desc.query.filter.terms[1] = .{ .id = ecs.id(Velocity) };
system_desc.query.filter.terms[2] = .{ .id = ecs.id(CameraTarget), .oper = ecs.oper_kind_t.Optional };
break :sys SYSTEM(world, "move", handle_input_system, &system_desc);
system_desc.query.filter.terms[2] = .{ .id = ecs.id(Foreground), .oper = ecs.oper_kind_t.Not };
system_desc.query.filter.terms[3] = .{ .id = ecs.id(Background), .oper = ecs.oper_kind_t.Not };
system_desc.query.filter.terms[2] = .{ .id = ecs.id(Orientation), .oper = ecs.oper_kind_t.Optional };
system_desc.query.filter.terms[3] = .{ .id = ecs.id(Foreground), .oper = ecs.oper_kind_t.Not };
system_desc.query.filter.terms[4] = .{ .id = ecs.id(Background), .oper = ecs.oper_kind_t.Not };
_ = ecs.set(world, player, Drawable, .{
.rect = rl.Rectangle{
.x = 0,
.y = 0,
.width = 40,
.height = 40,
},
});
_ = ecs.set(world, player, Orientation, .{ .direction = Direction.right });
_ = ecs.set(world, player, Drawable, .{ .color_circle = ColorCircle{
.circle = Circle{ .radius = 20 },
.color = rl.BLUE,
} });