Skip to main content

Module sim

Module sim 

Source
Expand description

The deterministic simulation: a level of solid tiles and the hero moving through it.

No toolkit types. World::step advances one fixed step of DT; the same Intents give the same results, so a cloned world plays out identically (the tests rely on that, and so will rewinds and replays).

Movement follows the Celeste school: integer positions (units) with a fractional remainder, moved one unit at a time against the tile grid, so collisions are exact and nothing tunnels. All feel numbers live in Tuning.

On its own: an Intent in each fixed step, Events out.

use game_toolkit_platformer::sim::{Event, Intent, JumpKind, Level, Preset, World};

let mut level = Level::demo();
let mut world = World::on(&level, Preset::Precise.tuning());
world.step(&mut level, &Intent::default());
world.step(&mut level, &Intent { jump_pressed: true, jump_held: true, ..Intent::default() });
assert!(world.events.iter().any(|e| matches!(e, Event::Jumped { kind: JumpKind::Ground, .. })));

Re-exports§

pub use ability::Ability;
pub use ability::Step;
pub use contacts::Contacts;
pub use crystal::Crystal;
pub use custom_id::CustomId;
pub use custom_tile::CustomTile;
pub use event::Event;
pub use event::JumpKind;
pub use grid::Grid;
pub use grid::GridTerrain;
pub use hold::Hold;
pub use intent::Intent;
pub use level::Level;
pub use level::TILE;
pub use level::Tile;
pub use moves::Moves;
pub use player::Mode;
pub use player::Player;
pub use rect::Rect;
pub use spot::Spot;
pub use surface::Surface;
pub use terrain::Terrain;
pub use tuning::Preset;
pub use tuning::Tuning;

Modules§

ability
Ability: a move of your game’s own (an attack lunge, a ledge grab, a grapple, a pogo), hooked into World::step without forking the movement.
contacts
Contacts: what the body ran into in its last step, for an Ability::after that reacts to collisions (a wall-hit stun, a ceiling bonk that breaks a block, a ground pound).
crystal
Crystal: a dash refill floating in the air; used up on touch, back after a while.
custom_id
CustomId: the name of a move or event of your own, for Mode::Custom and Event::Custom.
custom_tile
CustomTile: what a Tile::Custom is to the movement, set per id with Level::define.
event
Event: what happened in a step, for animation, sound and effects.
grid
Grid: a tilemap of your own, one answer per tile, turned into the Terrain rules the movement relies on (solid ground, one-way platforms held only from exactly above, the surface under the feet or beside the body) by GridTerrain. Level answers by the same rules.
hold
Hold: how a CustomTile holds the character.
intent
Intent: what the player wants this step, independent of keys or pads.
level
Level: a ready-made Terrain: a grid of tiles (solid, one-way platforms), dash refills and a spawn point. Parse it from ASCII rows, build it from your own tilemap with Level::from_fn, or implement Terrain for your own world instead.
moves
Moves: which built-in moves may run in one step. An Ability clears what its own move rules out in Ability::before: no dash while attacking, no wall grab while carrying, slow walking while pushing.
player
Player: the hero’s body: position, speed, timers, and the movement rules.
rect
Rect: an integer axis-aligned box, in units or in a terrain’s pixels.
spot
Spot: where to put the character, by its hitbox’s top-left or by its feet.
surface
Surface: what kind of ground or wall the character touches: ice, a conveyor belt, a wall too smooth to climb, a bouncy pad. A Terrain answers it in Terrain::surface; by default everything is Surface::DEFAULT and the Tuning alone sets the feel.
terrain
Terrain: what the movement asks about the world around the character. Your game implements it for its own level (a tilemap, a collision grid, anything): write Terrain::solid and say what it builds on with terrain_layer! (terrain_layer!() for nothing, terrain_layer!(level) for a field it wraps).
tuning
Tuning: every number that shapes how the hero moves. Units and seconds (the movement’s space: pixels at a scale of 1; see docs/scale.md).

Structs§

World
The character’s movement: its body, its feel, and the bookkeeping between steps. The world around it is a Terrain passed to every World::step, so it stays yours.

Constants§

DT
The fixed simulation step in seconds (120 Hz).