1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-13 01:22:45 +00:00
doukutsu-rs/src/scene/loading_scene.rs

42 lines
1.1 KiB
Rust
Raw Normal View History

2020-08-19 19:11:32 +00:00
use crate::ggez::{Context, GameResult};
2020-08-18 16:46:07 +00:00
2020-08-19 13:11:34 +00:00
use crate::scene::game_scene::GameScene;
2020-08-18 16:46:07 +00:00
use crate::scene::Scene;
2020-08-19 13:11:34 +00:00
use crate::SharedGameState;
2020-08-19 00:55:21 +00:00
use crate::stage::StageData;
2020-08-18 16:46:07 +00:00
pub struct LoadingScene {
tick: usize,
}
impl LoadingScene {
2020-08-19 00:55:21 +00:00
pub fn new() -> Self {
Self {
2020-08-18 16:46:07 +00:00
tick: 0,
}
}
}
impl Scene for LoadingScene {
2020-08-19 13:11:34 +00:00
fn tick(&mut self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult {
2020-08-18 16:46:07 +00:00
// deferred to let the loading image draw
if self.tick == 1 {
2020-08-19 13:11:34 +00:00
let stages = StageData::load_stage_table(ctx, &state.base_path)?;
state.stages = stages;
2020-08-19 19:11:32 +00:00
state.next_scene = Some(Box::new(GameScene::new(state, ctx, 0)?));
2020-08-18 16:46:07 +00:00
}
self.tick += 1;
Ok(())
}
2020-08-19 13:11:34 +00:00
fn draw(&self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult {
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "Loading")?;
2020-08-18 16:46:07 +00:00
2020-08-19 13:11:34 +00:00
batch.add(((state.canvas_size.0 - batch.width() as f32) / 2.0).floor(),
((state.canvas_size.1 - batch.height() as f32) / 2.0).floor());
batch.draw(ctx)?;
2020-08-18 16:46:07 +00:00
Ok(())
}
}