Skip to main content

Module script_game

Module script_game 

Source
Expand description

Game-wide services on Ctx: the screen interface, saves and settings, files, cameras and asking the host to quit.

use kvas_engine::prelude::*;

#[derive(Default)]
pub struct Menu { volume: f32 }
impl Script for Menu {
    fn update(&mut self, ctx: &mut Ctx) {
        let ui = ctx.ui();
        ui.panel([0.0, 0.0, ui.width(), 720.0], [0.0, 0.0, 0.0, 0.7], 0.0);
        ui.text("PAUSED", [ui.width() / 2.0, 200.0], 48.0, [1.0; 4], "", Align::Center);
        self.volume = ui.slider("volume", [540.0, 300.0, 200.0, 24.0], self.volume);
        if ui.button("save", [540.0, 360.0, 200.0, 40.0], "SAVE") {
            let _ = ctx.save_game("slot1", "Chapter 1", &serde_json::json!({ "volume": self.volume }));
        }
        if ui.button("quit", [540.0, 420.0, 200.0, 40.0], "QUIT") {
            ctx.quit_game();
        }
    }
}