end screen after end

This commit is contained in:
artem 2024-04-01 22:23:40 +03:00
parent a3b18313a7
commit f6b7e465d1
4 changed files with 729 additions and 699 deletions

View File

@ -41,7 +41,7 @@ use msg::ScreenSizeMessage;
use player::Player;
use sound::Sound;
const START_LEVEL: u32 = 3;
const START_LEVEL: u32 = 1;
pub struct GameConstructor;
// impl PluginConstructor for GameConstructor {
@ -70,6 +70,7 @@ pub struct Game {
need_show_menu: bool,
show_menu_time: f32,
change_level_time: f32,
need_show_end: bool,
}
impl Game {
@ -107,6 +108,7 @@ impl Game {
level: START_LEVEL,
need_change_level: false,
need_show_menu: false,
need_show_end: false,
show_menu_time: 0.0,
change_level_time: 0.0,
}
@ -121,6 +123,10 @@ impl Game {
self.show_menu_time = show_menu_time;
self.need_show_menu = true;
}
pub fn end_game(&mut self) {
self.need_show_end = true;
}
}
impl Plugin for Game {
@ -151,7 +157,6 @@ impl Plugin for Game {
if self.need_show_menu && self.show_menu_time < context.elapsed_time {
self.need_show_menu = false;
self.show_menu_time = 0.0;
println!("self.level {}", self.level);
context
.user_interface
.send_message(WidgetMessage::visibility(
@ -162,6 +167,18 @@ impl Plugin for Game {
true,
));
}
if self.need_show_end {
context
.user_interface
.send_message(WidgetMessage::visibility(
context
.user_interface
.find_handle_by_name_from_root("EndScreen"),
MessageDirection::ToWidget,
true,
));
}
}
fn on_os_event(&mut self, event: &Event<()>, context: PluginContext) {

View File

@ -249,7 +249,7 @@ pub fn build_map(graph: &mut Graph, resource_manager: &ResourceManager, level: u
}
build_stone_block(resource_manager, graph, 30.0, bottom_y);
if level == 3 {
build_home_block(resource_manager, graph, 0.0, bottom_y);
build_home_block(resource_manager, graph, -40.0, bottom_y);
} else {
build_stone_block(resource_manager, graph, -30.0, bottom_y);
}

View File

@ -37,6 +37,7 @@ use fyrox::{
const JUMP_HEIGHT: f32 = 6.0;
const SPEED: f32 = 2.9;
const ONE_SEC: f32 = 1.0;
const END_MAP: f32 = -36.5;
#[derive(Visit, Reflect, Debug, Default, Clone)]
pub struct Player {
@ -494,6 +495,16 @@ impl Player {
None => {}
}
}
fn check_is_home(&self, context: &mut ScriptContext) {
let rigid_body = context.scene.graph[context.handle].cast::<RigidBody>();
if let Some(rigid_data) = rigid_body {
if rigid_data.local_transform().position().x <= END_MAP {
let game = context.plugins.get_mut::<Game>();
game.end_game();
}
}
}
}
impl_component_provider!(Player,);
@ -526,6 +537,7 @@ impl ScriptTrait for Player {
}
}
// Called whenever there is an event from OS (mouse click, keypress, etc.)
fn on_os_event(&mut self, event: &Event<()>, _context: &mut ScriptContext) {
if let Event::WindowEvent { event, .. } = event {
@ -583,5 +595,6 @@ impl ScriptTrait for Player {
self.update_health(context);
self.attack_enemy(context);
self.loop_over(context);
self.check_is_home(context);
}
}

File diff suppressed because it is too large Load Diff