|
@@ -1,5 +1,9 @@ |
|
|
use crate::resources::spritesheet::*; |
|
|
|
|
|
use amethyst::{assets::ProgressCounter, prelude::*}; |
|
|
|
|
|
|
|
|
use crate::resources::{font::FontResource, spritesheet::*}; |
|
|
|
|
|
use amethyst::{ |
|
|
|
|
|
assets::ProgressCounter, |
|
|
|
|
|
prelude::*, |
|
|
|
|
|
ui::{Anchor, UiText, UiTransform}, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
/// struct for preloading the game |
|
|
/// struct for preloading the game |
|
|
pub struct PreloadState { |
|
|
pub struct PreloadState { |
|
@@ -14,6 +18,30 @@ impl PreloadState { |
|
|
|
|
|
|
|
|
impl SimpleState for PreloadState { |
|
|
impl SimpleState for PreloadState { |
|
|
fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) { |
|
|
fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) { |
|
|
|
|
|
let world = data.world; |
|
|
|
|
|
|
|
|
|
|
|
// load the font |
|
|
|
|
|
let font = FontResource::load(world, "fnt/8x8_wide_mono_bold.ttf".into()); |
|
|
|
|
|
let tmp_font_handle = font.get_handle().clone(); |
|
|
|
|
|
world.insert(font); |
|
|
|
|
|
|
|
|
|
|
|
// create the loading thingo |
|
|
|
|
|
let title_transform = UiTransform::new( |
|
|
|
|
|
"loading".into(), |
|
|
|
|
|
Anchor::Middle, |
|
|
|
|
|
Anchor::Middle, |
|
|
|
|
|
0.0, |
|
|
|
|
|
0.0, |
|
|
|
|
|
0.0, |
|
|
|
|
|
350.0, |
|
|
|
|
|
45.0, |
|
|
|
|
|
); |
|
|
|
|
|
world |
|
|
|
|
|
.create_entity() |
|
|
|
|
|
.with(UiText::new(tmp_font_handle, "Loading...".into(), [0.0, 0.0, 0.0, 1.0], 45.0)) |
|
|
|
|
|
.with(title_transform) |
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
// load the spritesheet |
|
|
// load the spritesheet |
|
|
let (spritesheet_map, counter) = SpriteSheetMapLoader::new() |
|
|
let (spritesheet_map, counter) = SpriteSheetMapLoader::new() |
|
|
.with_paths( |
|
|
.with_paths( |
|
@@ -21,13 +49,15 @@ impl SimpleState for PreloadState { |
|
|
"img/title_screen_sprite_sheet.ron".into(), |
|
|
"img/title_screen_sprite_sheet.ron".into(), |
|
|
"img/title_screen_texture.png".into(), |
|
|
"img/title_screen_texture.png".into(), |
|
|
) |
|
|
) |
|
|
.load(data.world); |
|
|
|
|
|
|
|
|
.load(world); |
|
|
|
|
|
|
|
|
self.counter = Some(counter); |
|
|
self.counter = Some(counter); |
|
|
data.world.insert(spritesheet_map); |
|
|
|
|
|
|
|
|
world.insert(spritesheet_map); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fn update(&mut self, _data: &mut StateData<'_, GameData<'_, '_>>) -> SimpleTrans { |
|
|
|
|
|
|
|
|
fn update(&mut self, data: &mut StateData<'_, GameData<'_, '_>>) -> SimpleTrans { |
|
|
|
|
|
let world = &mut data.world; |
|
|
|
|
|
|
|
|
if let Some(counter) = &self.counter { |
|
|
if let Some(counter) = &self.counter { |
|
|
let (assets, finished) = (counter.num_assets(), counter.num_finished()); |
|
|
let (assets, finished) = (counter.num_assets(), counter.num_finished()); |
|
|
|
|
|
|
|
@@ -36,6 +66,7 @@ impl SimpleState for PreloadState { |
|
|
Trans::None |
|
|
Trans::None |
|
|
} else if counter.is_complete() { |
|
|
} else if counter.is_complete() { |
|
|
println!("completed load!"); |
|
|
println!("completed load!"); |
|
|
|
|
|
world.delete_all(); |
|
|
Trans::Switch(Box::new(crate::states::titlescreen::TitleScreenState)) |
|
|
Trans::Switch(Box::new(crate::states::titlescreen::TitleScreenState)) |
|
|
} else { |
|
|
} else { |
|
|
Trans::None |
|
|
Trans::None |
|
|