add game_over
This commit is contained in:
parent
1ecd054a31
commit
e9379a6a94
5 changed files with 57 additions and 23 deletions
|
|
@ -1,7 +1,7 @@
|
|||
(
|
||||
map: {
|
||||
KeyCode(ShiftLeft): [
|
||||
MultiPlaceTower,
|
||||
MouseButton(Middle): [
|
||||
CameraOrbitEnable,
|
||||
],
|
||||
MouseButton(Right): [
|
||||
PlaceTower,
|
||||
|
|
@ -9,8 +9,8 @@
|
|||
MouseButton(Left): [
|
||||
CameraPanEnable,
|
||||
],
|
||||
MouseButton(Middle): [
|
||||
CameraOrbitEnable,
|
||||
KeyCode(ShiftLeft): [
|
||||
MultiPlaceTower,
|
||||
],
|
||||
MouseScroll: [
|
||||
CameraZoom,
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
use bevy::prelude::*;
|
||||
use building::{BuildingInfo, BuildingPreview, Core, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
||||
use combat::{Defense, Health, Range};
|
||||
use state::CoreState;
|
||||
use combat::{Defense, Died, Health, Range};
|
||||
use state::{CoreState, GameState};
|
||||
use ui_range_indicator::CustomRangeIndicator;
|
||||
|
||||
pub struct BuildingCorePlugin;
|
||||
|
|
@ -85,17 +85,29 @@ fn populate(
|
|||
if trigger.event().info != res.info_entity {
|
||||
return;
|
||||
}
|
||||
commands.entity(trigger.target()).insert((
|
||||
Core,
|
||||
Mesh3d(res.mesh.clone()),
|
||||
MeshMaterial3d(res.material.clone()),
|
||||
CustomRangeIndicator::new(materials.add(StandardMaterial {
|
||||
alpha_mode: AlphaMode::Blend,
|
||||
base_color: Color::srgba(0.6, 0.2, 0.2, 0.4),
|
||||
unlit: true,
|
||||
double_sided: true,
|
||||
..default()
|
||||
})),
|
||||
));
|
||||
commands
|
||||
.entity(trigger.target())
|
||||
.insert((
|
||||
Core,
|
||||
Mesh3d(res.mesh.clone()),
|
||||
MeshMaterial3d(res.material.clone()),
|
||||
CustomRangeIndicator::new(materials.add(StandardMaterial {
|
||||
alpha_mode: AlphaMode::Blend,
|
||||
base_color: Color::srgba(0.6, 0.2, 0.2, 0.4),
|
||||
unlit: true,
|
||||
double_sided: true,
|
||||
..default()
|
||||
})),
|
||||
))
|
||||
.observe(core_dead);
|
||||
next_core_state.set(CoreState::Placed);
|
||||
}
|
||||
|
||||
fn core_dead(
|
||||
_trigger: Trigger<Died>,
|
||||
mut next_core_state: ResMut<NextState<CoreState>>,
|
||||
mut next_game_state: ResMut<NextState<GameState>>,
|
||||
) {
|
||||
next_core_state.set(CoreState::Dead);
|
||||
next_game_state.set(GameState::GameOver);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,13 +73,14 @@ pub enum AppState {
|
|||
Game,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash, SubStates, Default)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, SubStates, Default)]
|
||||
#[source(AppState = AppState::Game)]
|
||||
pub enum GameState {
|
||||
Loading,
|
||||
#[default]
|
||||
Running,
|
||||
Paused,
|
||||
GameOver,
|
||||
}
|
||||
|
||||
/// this is what you should set to change the state. do not read this for scheduling
|
||||
|
|
@ -117,7 +118,9 @@ impl ComputedStates for Phase {
|
|||
|
||||
fn compute(sources: Self::SourceStates) -> Option<Self> {
|
||||
match sources {
|
||||
(_, GameState::Loading, _) | (_, GameState::Paused, _) => None,
|
||||
(_, GameState::Loading, _)
|
||||
| (_, GameState::Paused, _)
|
||||
| (_, GameState::GameOver, _) => None,
|
||||
(_, _, CoreState::Dead) | (_, _, CoreState::Unplaced) => None,
|
||||
(BasePhaseState::Execute { .. }, GameState::Running, CoreState::Placed) => {
|
||||
Some(Self::Execute)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use building_placement::SelectBuildingPreview;
|
|||
use combat::Range;
|
||||
use input::{SelectEntity, Selected};
|
||||
use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit};
|
||||
use state::{BasePhaseState, CoreState, Phase};
|
||||
use state::{BasePhaseState, CoreState, GameState, Phase};
|
||||
use ui_state::GameUIState;
|
||||
use upgrade::{UnlockUpgrade, Upgradable, Upgrade};
|
||||
|
||||
|
|
@ -32,6 +32,7 @@ impl Plugin for UiIngamePlugin {
|
|||
.run_if(in_state(GameUIState::Default).and(in_state(CoreState::Unplaced))),
|
||||
side_panel
|
||||
.run_if(in_state(GameUIState::Default).and(in_state(CoreState::Placed))),
|
||||
game_over.run_if(in_state(GameState::GameOver)),
|
||||
plan_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Plan))),
|
||||
execute_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Execute))),
|
||||
transition_ui.run_if(
|
||||
|
|
@ -60,6 +61,7 @@ impl Plugin for UiIngamePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
const MEGA_FONT_SIZE: f32 = 64.;
|
||||
const VERY_LARGE_FONT_SIZE: f32 = 48.;
|
||||
const LARGE_FONT_SIZE: f32 = 24.;
|
||||
const FONT_SIZE: f32 = 16.;
|
||||
|
|
@ -176,7 +178,7 @@ fn transition_ui(
|
|||
},
|
||||
curr_state.get().phase_count()
|
||||
))
|
||||
.size(64.),
|
||||
.size(MEGA_FONT_SIZE),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
@ -352,8 +354,24 @@ fn place_core(
|
|||
.title_bar(false)
|
||||
.anchor(Align2::CENTER_BOTTOM, [0., 0.])
|
||||
.show(ctx, |ui| {
|
||||
if ui.button(RichText::new("COLONIZE").size(64.)).clicked() {
|
||||
if ui
|
||||
.button(RichText::new("COLONIZE").size(MEGA_FONT_SIZE))
|
||||
.clicked()
|
||||
{
|
||||
selected_preview_writer.write(SelectBuildingPreview(Some(*core_preview)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn game_over(mut contexts: EguiContexts) {
|
||||
let ctx = contexts.ctx_mut().unwrap();
|
||||
|
||||
egui::Window::new("TRANSITION")
|
||||
.collapsible(false)
|
||||
.title_bar(false)
|
||||
.anchor(Align2::CENTER_CENTER, [0., 0.])
|
||||
.fixed_size([600., 200.])
|
||||
.show(ctx, |ui| {
|
||||
ui.label(RichText::new("TRANSMISSION END").size(MEGA_FONT_SIZE));
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ fn toggle_pause(
|
|||
GameState::Loading => GameState::Loading,
|
||||
GameState::Running => GameState::Paused,
|
||||
GameState::Paused => GameState::Running,
|
||||
s @ _ => *s,
|
||||
};
|
||||
info!("toggle pause, changing to {:?}", next);
|
||||
next_state.set(next);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue