NYXWorld/README.md

78 lines
1.7 KiB
Markdown
Raw Normal View History

2026-08-01 21:34:45 +01:00
# NYXWorld
Low cortisol simple
**Archetype**
**ECS**
# Examples
**Basic**
```zig
const Exclude = struct {};
const Zombie = struct {};
const Player = struct { name: []const u8 };
const Vehicle = struct {};
const Transform = struct { pos: @Vector(2, f32) = .{ 0, 0 }, scale: @Vector(2, f32) = .{ 32, 32 } };
const Velocity = struct { value: @Vector(2, f32) = .{ 0, 0 } };
test "basic" {
// --- WORLD ---
2026-08-01 21:55:04 +01:00
var world: World = .init(std.testing.allocator);
2026-08-01 21:34:45 +01:00
defer world.deinit();
// --- PLAYER ---
try world.spawn(.{
Player{ .name = "abux" },
Transform{},
Velocity{},
});
// --- QUERY ---
var it = world.query(struct {
player: ?*const Player,
zombie: ?*const Zombie,
vehicle: ?*const Velocity,
transform: *Transform,
velocity: *Velocity,
}, .{
.without = &.{
Exclude,
},
});
while (it.next()) |e| {
// --- MOVE ---
e.velocity.value[0] += 2;
e.velocity.value[1] += 4;
// --- APPLY VELOCITY ---
e.transform.pos[0] += e.velocity.value[0];
e.transform.pos[1] += e.velocity.value[1];
// --- DEBUG PLAYER ---
if (e.player) |player| {
std.debug.print(
\\({f})PLAYER
\\| Name: {s}
\\| Position: {}
\\| Scale: {}
\\
, .{
it.entity(),
player.name,
e.transform.pos,
e.transform.scale,
});
}
}
}
```
2026-08-01 20:57:35 +00:00
**Output**
```text
(1) PLAYER
| Name: abux
| Position: { 2, 4 }
| Scale: { 32, 32 }
```