doukutsu-rs/src/scene/loading_scene.rs

55 lines
1.9 KiB
Rust
Raw Normal View History

2020-08-27 02:43:21 +00:00
use crate::ggez::{Context, filesystem, GameResult};
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-27 22:29:10 +00:00
use crate::text_script::{TextScript, TextScriptExecutionState};
2020-08-28 01:41:14 +00:00
use crate::common::FadeState;
2020-09-04 23:08:33 +00:00
use crate::npc::NPCTable;
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-09-04 23:08:33 +00:00
let npc_table = NPCTable::load_from(filesystem::open(ctx, [&state.base_path, "/npc.tbl"].join(""))?)?;
state.npc_table = npc_table;
2020-09-10 10:25:40 +00:00
let head_script = TextScript::load_from(filesystem::open(ctx, [&state.base_path, "/Head.tsc"].join(""))?)?;
state.textscript_vm.set_global_script(head_script);
2020-09-10 12:34:42 +00:00
2020-08-27 22:29:10 +00:00
let mut next_scene = GameScene::new(state, ctx, 13)?;
next_scene.player.x = 10 * 16 * 0x200;
next_scene.player.y = 8 * 16 * 0x200;
2020-08-28 01:41:14 +00:00
state.fade_state = FadeState::Hidden;
2020-08-27 22:29:10 +00:00
state.textscript_vm.state = TextScriptExecutionState::Running(200, 0);
2020-08-27 23:34:28 +00:00
state.next_scene = Some(Box::new(next_scene));
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(())
}
}