Skip to content

Commit

Permalink
More levels
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Dec 11, 2023
1 parent e8a3bb1 commit 2f75e42
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 41 deletions.
62 changes: 50 additions & 12 deletions src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub struct Level {
pub bases: &'static [LevelBase],
pub enabled_effects: &'static [(EffectType, f32)],
pub effect_likelihood: f32,
pub intro_text: &'static str,
pub intro_text: Option<&'static str>,
pub rain: Option<usize>,
pub friction: f32,
pub launch_platform: LaunchPlatform,
Expand All @@ -108,6 +108,8 @@ pub struct Level {
pub const DEFAULT_EFFECTS: [(EffectType, f32); 2] =
[(EffectType::Glue, 1.0), (EffectType::Magnetic, 1.0)];

pub const NO_EFFECTS: [(EffectType, f32); 0] = [];

pub const DEFAULT_LEVEL: Level = Level {
level: 0,
goal: LevelGoal::ReachHeight(20.0),
Expand All @@ -119,7 +121,7 @@ pub const DEFAULT_LEVEL: Level = Level {
}],
enabled_effects: &DEFAULT_EFFECTS,
effect_likelihood: 0.05,
intro_text: "Welcome to the game!",
intro_text: None,
rain: None,
friction: 0.5,
launch_platform: static_launch_platform(),
Expand All @@ -137,10 +139,10 @@ pub struct NextLevel(pub Option<usize>);
#[derive(Component, Debug, Clone)]
pub struct LevelLifecycle;

pub static LEVELS: [Level; 8] = [
pub static LEVELS: [Level; 9] = [
Level {
level: 0,
intro_text: "Test Level",
intro_text: Some("Test Level"),
goal: LevelGoal::ReachHeight(15.0),
time_limit: Some(Duration::from_secs(60)),
max_blocks: None,
Expand All @@ -154,55 +156,75 @@ pub static LEVELS: [Level; 8] = [
},
Level {
level: 1,
intro_text: "Welcome to your first day at Big Bad Buildings, Inc. Your job is to operate the Tower Thrower 3000, a state-of-the-art machine that constructs buildings by throwing blocks.\
For your first building, reach a target height of 200m.\
",
intro_text: Some("Welcome to your first day at Big Bad Buildings, Inc. Your job is to operate the Tower Thrower 3000, a state-of-the-art machine that constructs buildings by throwing blocks.
For your first building, reach a target height of 20m.
Controls:
Mouse: aim,
Mouse wheel / Touch scroll: Adjust force
Right click: Rotate 90 degrees
Q / E: Finely adjust rotation
"),
goal: LevelGoal::ReachHeight(20.0),
time_limit: Some(Duration::from_secs(60)),
max_blocks: None,
bases: &[LevelBase {
base_type: BaseType::T9,
..default_level_base()
}],
launch_platform: free_launch_platform(),
enabled_effects: &NO_EFFECTS,
..DEFAULT_LEVEL
},
Level {
level: 2,
intro_text: Some("For this building we only have a limited block supply. Be careful to not drop any! Stack 10 blocks to continue."),
goal: LevelGoal::ReachBlockCount(10),
time_limit: Some(Duration::from_secs(60)),
max_blocks: Some(13),
bases: &[LevelBase {
base_type: BaseType::T4,
..default_level_base()
}],
enabled_effects: &NO_EFFECTS,
..DEFAULT_LEVEL
},
// TODO: Make this easier
Level {
level: 3,
intro_text: Some("Oh no, it's raining! Everything will be slippery"),
goal: LevelGoal::ReachHeight(20.0),
time_limit: Some(Duration::from_secs(60)),
max_blocks: Some(30),
bases: &[LevelBase {
base_type: BaseType::T4,
..default_level_base()
}],
rain: Some(10),
friction: 0.2,
enabled_effects: &NO_EFFECTS,
launch_platform: LaunchPlatform {
translation: Vec2::new(13.0, 10.5),
kind: LaunchPlatformKind::Static,
},
..DEFAULT_LEVEL
},
Level {
level: 4,
intro_text: Some("We found some glue in the basement, some blocks will be sticky."),
goal: LevelGoal::ReachBlockCount(20),
time_limit: Some(Duration::from_secs(60)),
max_blocks: Some(25),
bases: &[LevelBase {
base_type: BaseType::T4,
..default_level_base()
}],
enabled_effects: &[(EffectType::Glue, 1.0)],
effect_likelihood: 0.1,
..DEFAULT_LEVEL
},
Level {
level: 5,
intro_text: "We're going to build the next one on two existing buildings, try combining them so you have a wider fundament.",
intro_text: Some("We're going to build the next one on two existing buildings, try combining them so you have a wider fundament."),
goal: LevelGoal::ReachHeight(35.0),
time_limit: Some(Duration::from_secs(60)),
max_blocks: Some(25),
Expand All @@ -223,7 +245,7 @@ pub static LEVELS: [Level; 8] = [
},
Level {
level: 6,
intro_text: "Oops, this one has a tilted fundament. Be careful!",
intro_text: Some("Oops, this one has a tilted fundament. Be careful!"),
goal: LevelGoal::ReachHeight(35.0),
time_limit: Some(Duration::from_secs(60)),
max_blocks: Some(25),
Expand All @@ -239,7 +261,23 @@ pub static LEVELS: [Level; 8] = [
},
Level {
level: 7,
intro_text: "Looks like it's starting to rain. The rain will make the blocks slippery, so be careful!",
intro_text: Some("We've ordered some magnets, these should hopefully help with building stability."),
goal: LevelGoal::ReachHeight(35.0),
time_limit: Some(Duration::from_secs(60)),
max_blocks: Some(25),
bases: &[
LevelBase {
base_type: BaseType::T4,
rotation: -0.1,
..default_level_base()
},
],
enabled_effects: &[(EffectType::Glue, 1.0)],
..DEFAULT_LEVEL
},
Level {
level: 8,
intro_text: Some("Looks like it's starting to rain. The rain will make the blocks slippery, so be careful!"),
goal: LevelGoal::ReachHeight(20.0),
bases: &[LevelBase {
base_type: BaseType::T4,
Expand All @@ -248,7 +286,7 @@ pub static LEVELS: [Level; 8] = [
rain: Some(10),
friction: 0.2,
..DEFAULT_LEVEL
}
},
];

pub fn load_level_event(
Expand Down
59 changes: 31 additions & 28 deletions src/level_intro_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,36 @@ pub fn update_level_intro_dialog(
level: Res<Level>,
) {
if dialog.visible {
egui::Window::new("Level Introo")
.collapsible(false)
.resizable(false)
.title_bar(false)
.anchor(egui::Align2::CENTER_CENTER, egui::Vec2::ZERO)
.frame(
Frame::none()
.fill(Color32::from_rgba_unmultiplied(0, 0, 0, 250))
.inner_margin(8.0),
)
.show(egui.ctx_mut(), |ui| {
ui.set_min_width(200.0);

ui.heading(format!("Level {}", level.level + 1));

ui.label(level.intro_text);

ui.add_space(50.0);

ui.with_layout(
egui::Layout::top_down_justified(egui::Align::Center),
|ui| {
if ui.button("START").clicked() {
dialog.visible = false;
}
},
);
});
if let Some(intro_text) = level.intro_text {
egui::Window::new("Level Intro")
.collapsible(false)
.resizable(false)
.title_bar(false)
.anchor(egui::Align2::CENTER_CENTER, egui::Vec2::ZERO)
.constrain(true)
.frame(
Frame::none()
.fill(Color32::from_rgba_unmultiplied(0, 0, 0, 250))
.inner_margin(8.0),
)
.show(egui.ctx_mut(), |ui| {
ui.set_min_width(120.0);

ui.heading(format!("Level {}", level.level + 1));

ui.label(intro_text);

ui.add_space(50.0);

ui.with_layout(
egui::Layout::top_down_justified(egui::Align::Center),
|ui| {
if ui.button("START").clicked() {
dialog.visible = false;
}
},
);
});
}
}
}
1 change: 1 addition & 0 deletions src/level_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub fn target_ui(
.resizable(false)
.frame(Frame::none())
.anchor(egui::Align2::RIGHT_TOP, egui::Vec2::new(-16.0, 8.0))
.interactable(false)
.show(egui.ctx_mut(), |ui| {
ui.with_layout(Layout::top_down(egui::Align::Max), |ui| {
match level.goal {
Expand Down
4 changes: 3 additions & 1 deletion src/throw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Default for Aim {
direction: Vec2::from_angle(PI / 1.5),
force_factor: 0.0,
force: 500.0,
rotation: 0.1,
rotation: 0.0,
}
}
}
Expand Down Expand Up @@ -544,5 +544,7 @@ pub fn throw_system(

commands.entity(entity).insert(Animator::new(tween));
}

aim.rotation = 0.0;
}
}

0 comments on commit 2f75e42

Please sign in to comment.