ludic/packages/ludic.core/components.ludic
Orkuncakilkaya ad3be0c53c
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 23s
ci / build-and-test (push) Successful in 2m23s
commit-lint / conventional-commits (push) Successful in 5s
docs / build-and-deploy (push) Successful in 28s
feat(input,ecs): #79 Input.axis_i directional int + #84 world bounds
#79 — Input.axis_i(neg,pos) -> int returns a -1/0/1 movement intent from the
multi-key device set, so WASD-to-movement needs no bool->int glue and feeds an
int mover directly (dx = Input.axis_i('a','d')).

#84 — a Bounds config entity (rect + policy, from ludic.core) drives the
engine-owned world-bounds system (LateUpdate): clamp / wrap / bounce (clamp +
flip Body velocity) / kill (despawn a body fully outside). Reads the Collider
size so the box stays inside; off by default, spliced only when Bounds is
declared (byte-identical otherwise). Adds World.despawn(e) — the by-id
reflective despawn (runs @OnDespawn + frees) via a new world_despawn intrinsic
whose @fn_world_despawn helper is emitted in emit_program's tail once a use is
seen (the g_uses_* prelude pattern), used by the kill policy and callable from
any system.

Examples input_movement + world_bounds. Full suite 112/0, goldens
byte-identical, fixpoint holds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 07:44:41 +03:00

62 lines
3.6 KiB
Text

# components.ludic — the canonical engine-ABI components (#77).
#
# These are the exact bundles runtime/native/systems_move.ludic (#65) reads by
# name. Import this file instead of re-declaring them, and the engine-owned
# `esys_move` system moves and collides your entities for free — declare a Body
# (and optionally a Collider) and it is ticked in the Update phase.
#
# Every field is defaulted so a game overrides only what it needs, and any field
# the move system does not find on an entity no-ops cleanly. Extend by
# *composition*: attach your own components (Health, Sprite, an AI brain) on the
# same model next to these; nothing here needs subclassing.
# The world anchor: integer pixels. This is the *rendered* location — a
# framebuffer pixel is the smallest drawable unit — so it stays integer. Sub-pixel
# motion accumulates in Body.rx/ry (Q16.16) and only the whole-pixel carry reaches
# Position (see docs/RFC-POSITION-TYPES.md, #78).
property Position { x: int = 0, y: int = 0 }
# A moving body: Q16.16 velocity, optional gravity, engine-owned sub-pixel
# accumulators, and the polled contact outputs the move system writes each frame.
# policy 0 = platformer (gravity applies) policy 1 = top-down (no gravity)
# on_ground / hit_wall / hit_ceiling and the optional contact normal hit_nx/hit_ny
# are OUTPUTS: read them in a handler to raise your own landing / bonk events
# (the SpriteAnim.event_fired pattern — polled flags, no engine coupling).
property Body {
vx: fixed = 0.0, vy: fixed = 0.0,
gravity: fixed = 0.0, max_fall: fixed = 0.0,
rx: fixed = 0.0, ry: fixed = 0.0,
policy: int = 0,
on_ground: int = 0, hit_wall: int = 0, hit_ceiling: int = 0,
hit_nx: int = 0, hit_ny: int = 0
}
# An axis-aligned box off the Position anchor. A solid Collider resolves swept-AABB
# collisions; a trigger (is_trigger = 1) reports overlap without resolving. layer /
# mask are collision bitmasks (0 = all); one_way = 1 is a platform that blocks only
# a downward landing. hit / entered / exited are trigger OUTPUTS.
property Collider {
w: int = 0, h: int = 0, offx: int = 0, offy: int = 0,
is_trigger: int = 0, one_way: int = 0, layer: int = 0, mask: int = 0,
hit: int = 0, entered: int = 0, exited: int = 0
}
# A drawable sprite (#85): declare it and the engine-owned sprite-render system
# draws the entity each Render frame from its Position — no hand-written Render
# handler. `id` is a sprite id (png_load / atlas cell); when the entity also carries
# SpriteAnim, the current animation frame is added to it. offx/offy offset from the
# Position anchor, scale is an integer zoom (0/1 = 1:1), flip mirrors horizontally,
# tint (non-zero) draws every opaque pixel in one colour (hit flash), hidden = 1
# skips it. Draw order is spawn order; a game wanting custom draw omits Sprite.
property Sprite { id: int = 0, offx: int = 0, offy: int = 0, scale: int = 1, flip: int = 0, tint: int = 0, hidden: int = 0 }
# Optional single config entity that turns the tile-grid broadphase on: solids are
# read from the Map.* tilemap. tile > 0 sets the tile size in px; wall is the solid
# glyph; oneway is an optional one-way-platform glyph (0 = none).
property Solids { tile: int = 0, wall: int = 0, oneway: int = 0 }
# Optional single config entity defining a world boundary / play area (#84): a rect
# (x, y, w, h) and a policy the engine applies to every moving Body each frame —
# 0 clamp (walls), 1 wrap (toroidal), 2 bounce (flip velocity), 3 kill (despawn when
# fully outside). Off by default (no Bounds entity = open world).
property Bounds { x: int = 0, y: int = 0, w: int = 0, h: int = 0, policy: int = 0 }