-
Notifications
You must be signed in to change notification settings - Fork 2
/
title.rs
108 lines (98 loc) · 3.19 KB
/
title.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use bevy::prelude::*;
use bevy_kira_audio::{Audio, AudioChannel};
use rand::Rng;
use rand::distributions::Standard;
use crate::{AppState, GlobalData, HEIGHT, MySelf, PlayerData, WIDTH};
use crate::fight::fight_screen::MyFoe;
use crate::data::font::TextStyles;
use crate::data::loading::{AudioAssets, TextureAssets};
use crate::ui::StateBackground;
use crate::util::{Z_BACKGROUND, cleanup_system};
pub struct TitlePlugin;
impl Plugin for TitlePlugin {
fn build(&self, app: &mut AppBuilder) {
app
.add_system_set(
SystemSet::on_enter(AppState::Title)
.with_system(display_title.system())
.with_system(setup_data.system())
)
.add_system_set(
SystemSet::on_update(AppState::Title)
.with_system(click_to_shop.system())
)
.add_system_set(
SystemSet::on_exit(AppState::Title)
.with_system(cleanup_system::<StateBackground>.system())
.with_system(cleanup_system::<Title>.system())
)
;
}
}
struct Title;
fn display_title(
mut commands: Commands,
text_styles: Res<TextStyles>,
handles: Res<TextureAssets>,
audio: Res<Audio>,
songs: Res<AudioAssets>,
) {
audio.stop();
audio.set_volume_in_channel(0.8, &AudioChannel::new("SFX".to_owned()));
audio.set_volume(0.8);
audio.play_looped(songs.title.clone());
commands.spawn_bundle(SpriteBundle {
material: handles.title_bg.clone(),
transform: Transform {
translation: Vec3::new(WIDTH / 2., HEIGHT / 2., Z_BACKGROUND),
..Default::default()
},
..Default::default()
}).insert(StateBackground);
commands.spawn_bundle(Text2dBundle {
text: Text::with_section("Click to start",
text_styles.subtitle.clone(),
TextAlignment {
horizontal: HorizontalAlign::Center,
..Default::default()
}),
transform: Transform {
translation: Vec3::new(WIDTH / 2., HEIGHT / 2. + 120., 1.),
..Default::default()
},
..Default::default()
}).insert(Title);
}
fn click_to_shop(
mut app_state: ResMut<State<AppState>>,
btn: Res<Input<MouseButton>>,
) {
if btn.just_pressed(MouseButton::Left) {
app_state.set(AppState::Shop).unwrap();
}
}
fn setup_data(
mut commands: Commands,
) {
let mut global_data = GlobalData {
next_card_id: 0, // WARNING: the number of cards created before in this function
..Default::default()
};
commands.spawn().insert(
PlayerData {
id: 0,
name: "YOU".to_string(),
hand: vec![],
board: vec![],
..Default::default()
}).insert(MySelf);
commands.spawn().insert(
PlayerData {
id: 1,
name: "AI".to_string(),
board: vec![],
ia: global_data.rng.sample(Standard),
..Default::default()
}).insert(MyFoe);
commands.insert_resource(global_data);
}