-
Notifications
You must be signed in to change notification settings - Fork 0
API Reference
Mike Wright edited this page Feb 12, 2026
·
3 revisions
This page provides a summary of the public API. For detailed documentation, see the rustdoc or Modules page.
Color type with RGBA components in 0.0 to 1.0 range.
pub struct Rgba(pub f32, pub f32, pub f32, pub f32);Constants:
-
BLACK,WHITE,GREEN,RED,BLUE -
YELLOW,CYAN,MAGENTA,ORANGE -
PHOSPHOR- Classic green vector monitor color
Methods:
-
rgb(r, g, b)- Create from RGB, alpha = 1.0 -
with_a(a)- Return copy with modified alpha -
lerp(other, t)- Interpolate between colors
Trait for deterministic random number generation.
pub trait GameRng {
fn next_u32(&mut self) -> u32;
fn next_u64(&mut self) -> u64;
fn next_f32(&mut self) -> f32;
fn range_f32(&mut self, lo: f32, hi: f32) -> f32;
fn range_i32(&mut self, lo: i32, hi: i32) -> i32;
fn chance(&mut self, p: f32) -> bool;
fn pick_index(&mut self, len: usize) -> Option<usize>;
}Fast xorshift64 RNG implementation.
impl Xorshift64 {
pub const fn new(seed: u64) -> Self;
pub const fn default_seed() -> Self;
}Display-list commands for rendering.
pub enum DrawCmd {
Clear { color: Rgba },
Line(Line2),
Polyline { pts: Vec<Vec2>, closed: bool, stroke: Stroke },
Text { pos: Vec2, text: String, size_px: f32, color: Rgba, style: FontStyleId },
PushTransform(Mat3),
PopTransform,
BeginLayer { name: &'static str },
EndLayer,
}Stroke style for vector lines.
pub struct Stroke {
pub color: Rgba,
pub width_px: f32,
pub glow: f32,
}Methods:
-
new(color, width_px)- Create stroke without glow -
with_glow(color, width_px, glow)- Create stroke with glow
-
rect_wire(min, max, stroke)- Create wireframe rectangle
pub trait Game {
fn metadata(&self) -> GameMeta;
fn reset(&mut self, ctx: &mut GameCtx);
fn update(&mut self, ctx: &mut GameCtx, dt: f32);
fn render(&mut self, ctx: &mut GameCtx, out: &mut Vec<DrawCmd>);
}Context passed to game methods.
pub struct GameCtx<'a> {
pub input: &'a dyn InputState,
pub audio: &'a dyn AudioOut,
pub rng: &'a mut dyn GameRng,
pub screen: ScreenInfo,
pub now_s: f64,
}Display surface information.
pub struct ScreenInfo {
pub width_px: u32,
pub height_px: u32,
pub dpi_scale: f32,
}pub trait InputState {
fn key(&self, k: Key) -> Button;
fn axis(&self, a: Axis) -> f32;
fn pointer(&self) -> Option<Pointer>;
}pub enum Key {
Left, Right, Up, Down,
Space, Enter, Escape,
W, S, Z, X, C,
}pub struct Button {
pub is_down: bool,
pub went_down: bool,
pub went_up: bool,
}Axis-aligned bounding box.
pub struct Aabb {
pub min: Vec2,
pub max: Vec2,
}Methods:
-
from_center(center, half)- Create from center and half-extents -
from_min_max(min, max)- Create from corners -
center()- Get center point -
half_extents()- Get half-extents -
contains_point(p)- Point containment test -
overlaps(other)- AABB overlap test
pub struct Circle {
pub center: Vec2,
pub radius: f32,
}Methods:
-
new(center, radius)- Create circle -
contains_point(p)- Point containment test -
overlaps_circle(other)- Circle overlap test -
overlaps_aabb(aabb)- Circle-AABB overlap test
-
line_aabb_intersect(a, b, aabb)- Line segment vs AABB -
line_circle_intersect(a, b, circle)- Line segment vs circle
-
lerp(a, b, t)- Linear interpolation -
inv_lerp(a, b, v)- Inverse linear interpolation -
remap(v, from_lo, from_hi, to_lo, to_hi)- Remap value between ranges
-
clamp(x, lo, hi)- Clamp to range -
wrap_signed_unit(x)- Wrap to [-1, 1) -
wrap_range(x, lo, hi)- Wrap to custom range -
wrap_position(p)- Wrap Vec2 to [-1, 1) on both axes
-
normalize_angle(angle)- Normalize to [-PI, PI) -
angle_diff(from, to)- Shortest angular distance
-
project_persp(p, fov_y_rad, aspect)- Perspective projection for single point -
project_line_3d(a, b, fov_y_rad, aspect)- Project 3D line with near-plane clipping -
rotate_point_y(p, angle)- Rotate point around Y axis (for camera/tank turning) -
depth_intensity(distance, near, far)- Depth-based intensity falloff
-
rot2(theta_rad)- 2D rotation matrix -
translate2(t)- 2D translation matrix -
scale2(s)- 2D non-uniform scale matrix -
scale2_uniform(s)- 2D uniform scale matrix
For first-person 3D shooter games (Battlezone, etc.):
pub struct Projectile3D {
pub pos: Vec3,
pub dir: Vec3,
pub speed: f32,
pub max_dist: f32,
pub traveled: f32,
pub alive: bool,
}Methods:
-
new(origin, direction, speed, max_dist)- Create projectile -
update(dt)- Move projectile, mark dead if max distance exceeded -
hits_sphere(center, radius)- Collision check against spherical hitbox
For top-down 2D shooter games (Asteroids, etc.):
pub struct Projectile2D {
pub pos: Vec2,
pub vel: Vec2,
pub alive: bool,
pub lifetime: f32,
}Methods:
-
new(pos, vel, lifetime)- Create projectile (lifetime=0 for no auto-despawn) -
update(dt)- Move projectile, mark dead if lifetime expired -
hits_circle(center, radius)- Collision check against circular hitbox
-
update_projectiles_3d(projectiles, dt)- Update all and remove dead
pub trait VectorFont {
fn style_id(&self) -> FontStyleId;
fn has_glyph(&self, ch: char) -> bool;
fn glyph_paths(&self, ch: char) -> Vec<GlyphPath>;
fn advance(&self, ch: char) -> f32;
}pub struct FontStyleId(pub u32);
impl FontStyleId {
pub const DEFAULT: FontStyleId;
pub const ATARI: FontStyleId;
pub const CINEMATRONICS: FontStyleId;
pub const MIDWAY: FontStyleId;
pub const VECTOR_SCANLINE: FontStyleId;
}- Modules - Detailed module documentation
- Getting-Started - Usage examples
- Architecture - Design overview