WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 003f332

Browse files
committed
Fix wasm and add menu
1 parent 4562397 commit 003f332

File tree

3 files changed

+63
-19
lines changed

3 files changed

+63
-19
lines changed

src/camera_movement.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@ impl Default for CameraMovement {
1919
pub fn camera_movement_system(
2020
mut camera_movement: ResMut<CameraMovement>,
2121
mut camera_query: Query<(&mut Transform, &GlobalTransform, &Camera), With<MainCamera>>,
22-
mut query: Query<
23-
&Transform,
24-
(
25-
Without<MainCamera>,
26-
Without<Falling>,
27-
Or<(With<Block>, With<LaunchPlatform>)>,
28-
),
29-
>,
22+
mut query: Query<&Transform, (With<LaunchPlatform>, Without<MainCamera>)>,
3023
) {
3124
let start_move_at = 20.0;
3225

@@ -39,7 +32,7 @@ pub fn camera_movement_system(
3932

4033
let target_height = highest - start_move_at;
4134

42-
let increase = 0.03;
35+
let increase = 0.06;
4336

4437
if target_height > camera_movement.height {
4538
camera_movement.height += increase;

src/level_ui.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bevy_egui::{egui, EguiContexts};
55

66
use crate::block::Aiming;
77
use crate::environment::fees::LevelFees;
8-
use crate::level::{Level, LevelGoal, LevelStats, NextLevel};
8+
use crate::level::{Level, LevelGoal, LevelStats, NextLevel, LEVELS};
99
use crate::state::LevelState;
1010
use crate::throw::ThrowQueue;
1111

@@ -14,7 +14,7 @@ pub struct LevelUiPlugin;
1414
impl Plugin for LevelUiPlugin {
1515
fn build(&self, app: &mut App) {
1616
app.add_systems(Startup, setup_level_ui)
17-
.add_systems(Update, (egui_level_ui, target_ui));
17+
.add_systems(Update, (target_ui));
1818
}
1919
}
2020

@@ -128,12 +128,57 @@ pub fn target_ui(
128128
mut rendered_texture_id: Local<egui::TextureId>,
129129
mut has_aiming_block: Query<(), With<Aiming>>,
130130
queue: Res<ThrowQueue>,
131+
mut next_level: EventWriter<NextLevel>,
132+
mut menu_open: Local<bool>,
131133
) {
132134
if !*is_initialized {
133135
*is_initialized = true;
134136
*rendered_texture_id = egui.add_image(assets.load("blocks/T/2.png"));
135137
}
136138

139+
egui::Window::new("Menu Button UI")
140+
.title_bar(false)
141+
.movable(false)
142+
.resizable(false)
143+
.frame(Frame::none())
144+
.anchor(egui::Align2::LEFT_TOP, egui::Vec2::new(16.0, 8.0))
145+
.show(egui.ctx_mut(), |ui| {
146+
ui.horizontal(|ui| {
147+
if ui.button("MENU").clicked() {
148+
*menu_open = !*menu_open;
149+
}
150+
151+
ui.label(
152+
RichText::new(format!("Level {}: {}", level.level + 1, level.name))
153+
.size(20.0)
154+
.color(Color32::BLACK),
155+
);
156+
});
157+
});
158+
159+
if *menu_open {
160+
egui::Window::new("Menu")
161+
.title_bar(false)
162+
.movable(false)
163+
.resizable(false)
164+
.anchor(egui::Align2::LEFT_TOP, egui::Vec2::new(16.0, 48.0))
165+
.show(egui.ctx_mut(), |ui| {
166+
if level.level < LEVELS.len() - 1 {
167+
if ui.button("Next Level").clicked() {
168+
next_level.send(NextLevel(None));
169+
}
170+
}
171+
if level.level > 0 {
172+
if ui.button("Previous Level").clicked() {
173+
next_level.send(NextLevel(Some(level.level - 1)));
174+
}
175+
}
176+
if ui.button("Retry").clicked() {
177+
next_level.send(NextLevel(Some(level.level)));
178+
}
179+
});
180+
}
181+
137182
egui::Window::new("Target UI")
138183
.title_bar(false)
139184
.movable(false)

src/main.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,24 @@ pub const BARREL_LENGTH: f32 = 3.5;
7171
fn main() {
7272
App::new()
7373
.insert_resource(ClearColor(Color::rgb_u8(44, 79, 255)))
74+
.insert_resource(AssetMetaCheck::Never)
7475
.add_plugins((
7576
// Bevy plugins
76-
DefaultPlugins.set(WindowPlugin {
77-
primary_window: Some(Window {
78-
title: "Tower Thrower".into(),
79-
fit_canvas_to_parent: true,
80-
// resolution: WindowResolution::new(1280.0, 720.0)
81-
// .with_scale_factor_override(1.0),
77+
DefaultPlugins
78+
.set(WindowPlugin {
79+
primary_window: Some(Window {
80+
title: "Tower Thrower".into(),
81+
fit_canvas_to_parent: true,
82+
// resolution: WindowResolution::new(1280.0, 720.0)
83+
// .with_scale_factor_override(1.0),
84+
..default()
85+
}),
8286
..default()
87+
})
88+
.set(AssetPlugin {
89+
mode: AssetMode::Unprocessed,
90+
..Default::default()
8391
}),
84-
..default()
85-
}),
8692
RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(PIXELS_PER_METER)
8793
.in_fixed_schedule(),
8894
{

0 commit comments

Comments
 (0)