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
202 downloads per month
Used in pixels-graphics-lib
29KB
606 lines
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
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();
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