12 releases
0.5.2 | Oct 1, 2024 |
---|---|
0.5.1 | Sep 30, 2024 |
0.4.2 | Jan 7, 2024 |
0.4.1 | Dec 27, 2023 |
0.1.0 | Dec 19, 2023 |
#376 in Game dev
591 downloads per month
Used in pixels-graphics-lib
56KB
1.5K
SLoC
Game Utils
Simple game utilities
Usage
Cargo
In your Cargo.toml file add
simple-game-utils = { version = "0.5.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
orcontroller_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();
Tilemap
Features
Default features:
prefs
,sound
,serde
,ici
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
ici
Adds ICI file support for tilemap
Dependencies
~0.4–30MB
~459K SLoC