Crates.io | simple-game-utils |
lib.rs | simple-game-utils |
version | 0.5.2 |
source | src |
created_at | 2023-12-19 19:48:17.916475 |
updated_at | 2024-10-01 07:39:06.661645 |
description | Utilities for simple games |
homepage | |
repository | https://github.com/emmabritton/simple-game-utils |
max_upload_size | |
id | 1074584 |
size | 112,282 |
Simple game utilities
In your Cargo.toml file add
simple-game-utils = { version = "0.5.2", features = ["controller"] }
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;
}
}
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);
}
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");
}
}
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();
Default features:
prefs
,sound
,serde
,ici
Simple struct storage
Very basic controller support
Can not be used with
controllerxinput
Use XInput for controllers (windows only)
Can not be used with
controller
Basic sound effects or music playback
Adds serialization for some structs and enums
Adds ICI file support for tilemap