10 unstable releases (3 breaking)

0.4.2 Jan 7, 2024
0.4.1 Dec 27, 2023
0.3.4 Dec 23, 2023
0.2.0 Dec 19, 2023
0.1.0 Dec 19, 2023

#831 in Game dev

Download history 89/week @ 2023-12-18 31/week @ 2023-12-25 44/week @ 2024-01-01 13/week @ 2024-01-08 8/week @ 2024-02-26 169/week @ 2024-03-11 33/week @ 2024-04-01

202 downloads per month
Used in pixels-graphics-lib

Custom license

29KB
606 lines

Crates.io Documentation

Game Utils

Simple game utilities

Usage

Cargo

In your Cargo.toml file add

simple-game-utils = { version = "0.4.2", features = ["controller"] }

Code

Timing

This program runs for 1 second then exits.

//track passage of time
let mut timing = Timing::new(240); //UPS
//triggers after specified time has passed
let mut timer = Timer::new(1.0);
loop {
    //automatically updates based on how much time has passed since the last call
    timing.update();
    //returns true if time has run out
    if timer.update(timing) {
        break;
    }   
}

Sound

Requires sound feature

let mut engine = AudioEngine::new().unwrap();
let mut sound = engine.load_from_bytes(&some_sound_bytes, duration).unwrap();
sound.play();
loop {
    timing.update();
    sound.update(&timing);
} 

Controller

Requires controller or controller_xinput feature

// This will work whether or not there's a controller plugged in
let mut controller = GameController::new().expect("Unable to init controller lib");

loop {
    controller.update();
    if controller.direction.up {
        println!("DPad UP pressed");
    }
}

Preferences

Requires prefs feature

struct Settings {
    user: String,
    theme: usize
}

let prefs: AppPrefs<Settings> = AppPrefs::new("com","example","readme", || Settings::default()).unwrap();
println!("{}", prefs.data.user);
prefs.data.user = String::new("New");
prefs.save();

Features

Default features: prefs, sound, serde

prefs

Simple struct storage

controller

Very basic controller support

  • no support for choosing controllers

Can not be used with controllerxinput

controller_xinput

Use XInput for controllers (windows only)

Can not be used with controller

sound

Basic sound effects or music playback

serde

Adds serialization for some structs and enums

Dependencies

~0.5–34MB
~492K SLoC