-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.rs
51 lines (40 loc) · 1.98 KB
/
utils.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use amethyst::assets::SimpleFormat;
use amethyst::ecs::{WriteStorage, world::EntitiesRes};
use amethyst::ui::{UiImage, UiTransform};
use amethyst::utils::time_destroy::DestroyInTime;
use super::gameplay;
const NEPU: &'static [u8] = include_bytes!("../../../resources/images/Nepu.png");
pub struct Images {
pub nepu: amethyst::renderer::TextureHandle,
}
impl Images {
pub fn spawn_nepu<'s>(&self, entities: &EntitiesRes, side: gameplay::Side, ui_transform: &mut WriteStorage<'s, UiTransform>, ui_image: &mut WriteStorage<'s, UiImage>, time_destroy: &mut WriteStorage<'s, DestroyInTime>) {
let timer = DestroyInTime { timer: 0.5 };
let image = amethyst::ui::UiImage { texture: self.nepu.clone() };
let (anchor, transform_x) = match side {
gameplay::Side::Right => (amethyst::ui::Anchor::TopRight, -60.0),
gameplay::Side::Left => (amethyst::ui::Anchor::TopLeft, 60.0),
};
let transform = amethyst::ui::UiTransform::new("NEPU".to_owned(),
anchor,
transform_x, -50.0, 1.0,
200.0, 134.0,
0);
entities.build_entity()
.with(transform, ui_transform)
.with(image, ui_image)
.with(timer, time_destroy)
.build();
}
}
fn load_texture(data: &'static [u8], world: &mut amethyst::prelude::World) -> amethyst::renderer::TextureHandle {
let img = amethyst::renderer::PngFormat.import(data.to_owned(), amethyst::renderer::TextureMetadata::srgb()).expect("To import builtin image");
world.read_resource::<amethyst::assets::Loader>().load_from_data(img, (), &world.read_resource())
}
pub fn init_pop_up(world: &mut amethyst::prelude::World) {
let nepu = load_texture(NEPU, world);
let images = Images {
nepu,
};
world.add_resource(images);
}