Skip to content

Commit

Permalink
feat(tutorial): added planning tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
pedryx committed Apr 15, 2024
1 parent 90025c9 commit a41b903
Showing 1 changed file with 124 additions and 1 deletion.
125 changes: 124 additions & 1 deletion src/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,35 @@ const INGREDIENTS_TEXT_POS: Vec2 = Vec2::new(615., 60.);
const SUMMONING_TEXT_POS: Vec2 = Vec2::new(0., 210.);
const MINIONS_TEXT_POS: Vec2 = Vec2::new(0., -440.);

const ENEMY_CARDS_TEXT_POS: Vec2 = Vec2::ZERO;

pub struct TutorialPlugin;

impl Plugin for TutorialPlugin {
fn build(&self, app: &mut App) {
app.init_state::<TutorialState>()
.init_resource::<FirstTutorial>()
.add_systems(
Update,
handle_tutorial_control.run_if(in_state(GameState::Playing)),
)
.add_systems(OnEnter(TutorialState::None), clean_up_tutorial)
.add_systems(OnEnter(TutorialState::Summoning), show_summoning_tutorial);
.add_systems(
OnEnter(TutorialState::Summoning),
show_summoning_tutorial.run_if(resource_equals(FirstTutorial(false))),
)
.add_systems(
OnEnter(GameScreen::Summoning),
show_summoning_tutorial.run_if(resource_equals(FirstTutorial(true))),
)
.add_systems(
OnEnter(TutorialState::Planning),
show_planning_tutorial.run_if(resource_equals(FirstTutorial(false))),
)
.add_systems(
OnEnter(GameScreen::Planning),
show_planning_tutorial.run_if(resource_equals(FirstTutorial(true))),
);
}
}

Expand All @@ -40,11 +58,21 @@ pub enum TutorialState {
#[derive(Component)]
struct TutorialEntity;

#[derive(Resource, PartialEq, Eq)]
struct FirstTutorial(bool);

impl Default for FirstTutorial {
fn default() -> Self {
Self(true)
}
}

fn handle_tutorial_control(
keyboard_input: Res<ButtonInput<KeyCode>>,
mouse_input: Res<ButtonInput<MouseButton>>,
game_screen: Res<State<GameScreen>>,
mut next_tutorial_state: ResMut<NextState<TutorialState>>,
mut first_tutorial: ResMut<FirstTutorial>,
) {
if keyboard_input.just_pressed(KeyCode::F1) {
match game_screen.get() {
Expand All @@ -55,6 +83,10 @@ fn handle_tutorial_control(
}

if mouse_input.just_pressed(MouseButton::Left) {
if *game_screen.get() == GameScreen::Planning {
first_tutorial.0 = false;
}

next_tutorial_state.set(TutorialState::None);
}
}
Expand All @@ -69,7 +101,10 @@ fn show_summoning_tutorial(
mut commands: Commands,
textures: Res<TextureAssets>,
fonts: Res<FontAssets>,
mut next_tutorial_state: ResMut<NextState<TutorialState>>,
) {
next_tutorial_state.set(TutorialState::Summoning);

// highlight
commands.spawn((
SpriteBundle {
Expand Down Expand Up @@ -212,3 +247,91 @@ fn show_summoning_tutorial(
TutorialEntity,
));
}

fn show_planning_tutorial(
mut commands: Commands,
textures: Res<TextureAssets>,
fonts: Res<FontAssets>,
mut next_tutorial_state: ResMut<NextState<TutorialState>>,
) {
next_tutorial_state.set(TutorialState::Planning);

// highlight
commands.spawn((
SpriteBundle {
texture: textures.tutorial_highlight_planning.clone(),
sprite: Sprite {
color: Color::WHITE.with_a(HIGHLIGHT_TRANSPARENCY),
..Default::default()
},
transform: Transform::from_xyz(0., 0., HIGHLIGHT_Z),
..Default::default()
},
TutorialEntity,
));

// minions text
commands.spawn((
Text2dBundle {
text: Text {
sections: vec![TextSection::new(
"ENEMY CARDS\nEACH SHOW ENEMY STATS AND REWARDS\nLMB - SELECT ENEMY",
TextStyle {
font: fonts.texts.clone(),
color: Color::BLACK,
font_size: TEXT_SIZE,
},
)],
justify: JustifyText::Center,
..Default::default()
},
transform: Transform::from_translation(ENEMY_CARDS_TEXT_POS.extend(TEXT_Z)),
..Default::default()
},
TutorialEntity,
));

// show help text
commands.spawn((
Text2dBundle {
text: Text {
sections: vec![TextSection::new(
"F1 - SHOW THIS HELP",
TextStyle {
font: fonts.texts.clone(),
color: Color::WHITE,
font_size: TEXT_SIZE,
},
)],
justify: JustifyText::Center,
..Default::default()
},
text_anchor: bevy::sprite::Anchor::TopLeft,
transform: Transform::from_xyz(-950., 530., TEXT_Z),
..Default::default()
},
TutorialEntity,
));

// continue text
commands.spawn((
Text2dBundle {
text: Text {
sections: vec![TextSection::new(
"(CLICK ANYWHERE TO CONTINUE)",
TextStyle {
font: fonts.texts.clone(),
color: Color::WHITE,
font_size: TEXT_SIZE * 0.7,
},
)],
justify: JustifyText::Center,
..Default::default()
},
text_anchor: bevy::sprite::Anchor::TopCenter,
transform: Transform::from_translation(Vec2::new(0., 530.).extend(TEXT_Z)),
..Default::default()
},
TutorialEntity,
));
}

0 comments on commit a41b903

Please sign in to comment.