Expand description
wasm4-sx - Opinionated wrapper around WASM-4
Tired of accessing raw pointers and adding “unsafe” everywhere? Use abstractions, now!
use wasm4_sx::*;
#[no_mangle]
fn start() {
// Let's change the palette!
Engine::palette().set(
Palette::new([
Color::new(0, 0, 0),
Color::new(0, 0, 127),
Color::new(0, 127, 127),
Color::new(127, 127, 127),
])
)
}
#[no_mangle]
fn update() {
Engine::run_frame(|ctx| {
// Let's change draw colors, safely!
Engine::draw_colors().set_index(DrawColorsIndex::I1, PaletteColor::P1);
Engine::draw_colors().set_index(DrawColorsIndex::I2, PaletteColor::Transparent);
// Let's check if the X button is pressed on gamepad #1
if ctx.gamepad(GamepadIndex::I1).is_button_pressed(GamepadButton::X) {
Engine::draw_colors().set_index(DrawColorsIndex::I1, PaletteColor::P2);
}
// Let's check if the mouse left-click was just pressed
if ctx.mouse().is_button_just_pressed(MouseButton::Left) {
Engine::draw_colors().set_index(DrawColorsIndex::I1, PaletteColor::P3);
}
});
}
Re-exports
Macros
- Format text.
- Print a line.
- Setup panic handler for WASM-4.
Structs
- ADSR envelope.
- RGB color with u8 components.
- Draw colors.
- Draw colors builder.
- Engine: wrapper around direct layers.
- Frame context: engine state for a frame.
- Frequency slide.
- Gamepad state.
- Mouse state.
- Color palette.
- A text drawing helper.
- Tone.
- Tone builder.
- Tone flags.
- Tone flags builder.
- Track reader.
- A 2D vector.
- Tone volume.
- A “safe” global RefCell to use in the WASM-4 context.
Enums
- Tone channel (waveform type).
- Draw colors index.
- Duty cycle.
- Gamepad button.
- Gamepad index.
- Mouse button.
- Palette color.
- Palette index.
- Panning.
- Horizontal alignment.
- Vertical alignment.
Functions
- Generate a random f64.
- Generate a random i32.
- Reseed the RNG.
- Generate a random u8.