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: {
|
map: {
|
||||||
KeyCode(ShiftLeft): [
|
MouseButton(Middle): [
|
||||||
MultiPlaceTower,
|
CameraOrbitEnable,
|
||||||
],
|
],
|
||||||
MouseButton(Right): [
|
MouseButton(Right): [
|
||||||
PlaceTower,
|
PlaceTower,
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
MouseButton(Left): [
|
MouseButton(Left): [
|
||||||
CameraPanEnable,
|
CameraPanEnable,
|
||||||
],
|
],
|
||||||
MouseButton(Middle): [
|
KeyCode(ShiftLeft): [
|
||||||
CameraOrbitEnable,
|
MultiPlaceTower,
|
||||||
],
|
],
|
||||||
MouseScroll: [
|
MouseScroll: [
|
||||||
CameraZoom,
|
CameraZoom,
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use building::{BuildingInfo, BuildingPreview, Core, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
use building::{BuildingInfo, BuildingPreview, Core, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
||||||
use combat::{Defense, Health, Range};
|
use combat::{Defense, Died, Health, Range};
|
||||||
use state::CoreState;
|
use state::{CoreState, GameState};
|
||||||
use ui_range_indicator::CustomRangeIndicator;
|
use ui_range_indicator::CustomRangeIndicator;
|
||||||
|
|
||||||
pub struct BuildingCorePlugin;
|
pub struct BuildingCorePlugin;
|
||||||
|
|
@ -85,17 +85,29 @@ fn populate(
|
||||||
if trigger.event().info != res.info_entity {
|
if trigger.event().info != res.info_entity {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
commands.entity(trigger.target()).insert((
|
commands
|
||||||
Core,
|
.entity(trigger.target())
|
||||||
Mesh3d(res.mesh.clone()),
|
.insert((
|
||||||
MeshMaterial3d(res.material.clone()),
|
Core,
|
||||||
CustomRangeIndicator::new(materials.add(StandardMaterial {
|
Mesh3d(res.mesh.clone()),
|
||||||
alpha_mode: AlphaMode::Blend,
|
MeshMaterial3d(res.material.clone()),
|
||||||
base_color: Color::srgba(0.6, 0.2, 0.2, 0.4),
|
CustomRangeIndicator::new(materials.add(StandardMaterial {
|
||||||
unlit: true,
|
alpha_mode: AlphaMode::Blend,
|
||||||
double_sided: true,
|
base_color: Color::srgba(0.6, 0.2, 0.2, 0.4),
|
||||||
..default()
|
unlit: true,
|
||||||
})),
|
double_sided: true,
|
||||||
));
|
..default()
|
||||||
|
})),
|
||||||
|
))
|
||||||
|
.observe(core_dead);
|
||||||
next_core_state.set(CoreState::Placed);
|
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,
|
Game,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Hash, SubStates, Default)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, SubStates, Default)]
|
||||||
#[source(AppState = AppState::Game)]
|
#[source(AppState = AppState::Game)]
|
||||||
pub enum GameState {
|
pub enum GameState {
|
||||||
Loading,
|
Loading,
|
||||||
#[default]
|
#[default]
|
||||||
Running,
|
Running,
|
||||||
Paused,
|
Paused,
|
||||||
|
GameOver,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// this is what you should set to change the state. do not read this for scheduling
|
/// 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> {
|
fn compute(sources: Self::SourceStates) -> Option<Self> {
|
||||||
match sources {
|
match sources {
|
||||||
(_, GameState::Loading, _) | (_, GameState::Paused, _) => None,
|
(_, GameState::Loading, _)
|
||||||
|
| (_, GameState::Paused, _)
|
||||||
|
| (_, GameState::GameOver, _) => None,
|
||||||
(_, _, CoreState::Dead) | (_, _, CoreState::Unplaced) => None,
|
(_, _, CoreState::Dead) | (_, _, CoreState::Unplaced) => None,
|
||||||
(BasePhaseState::Execute { .. }, GameState::Running, CoreState::Placed) => {
|
(BasePhaseState::Execute { .. }, GameState::Running, CoreState::Placed) => {
|
||||||
Some(Self::Execute)
|
Some(Self::Execute)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ use building_placement::SelectBuildingPreview;
|
||||||
use combat::Range;
|
use combat::Range;
|
||||||
use input::{SelectEntity, Selected};
|
use input::{SelectEntity, Selected};
|
||||||
use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit};
|
use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit};
|
||||||
use state::{BasePhaseState, CoreState, Phase};
|
use state::{BasePhaseState, CoreState, GameState, Phase};
|
||||||
use ui_state::GameUIState;
|
use ui_state::GameUIState;
|
||||||
use upgrade::{UnlockUpgrade, Upgradable, Upgrade};
|
use upgrade::{UnlockUpgrade, Upgradable, Upgrade};
|
||||||
|
|
||||||
|
|
@ -32,6 +32,7 @@ impl Plugin for UiIngamePlugin {
|
||||||
.run_if(in_state(GameUIState::Default).and(in_state(CoreState::Unplaced))),
|
.run_if(in_state(GameUIState::Default).and(in_state(CoreState::Unplaced))),
|
||||||
side_panel
|
side_panel
|
||||||
.run_if(in_state(GameUIState::Default).and(in_state(CoreState::Placed))),
|
.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))),
|
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))),
|
execute_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Execute))),
|
||||||
transition_ui.run_if(
|
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 VERY_LARGE_FONT_SIZE: f32 = 48.;
|
||||||
const LARGE_FONT_SIZE: f32 = 24.;
|
const LARGE_FONT_SIZE: f32 = 24.;
|
||||||
const FONT_SIZE: f32 = 16.;
|
const FONT_SIZE: f32 = 16.;
|
||||||
|
|
@ -176,7 +178,7 @@ fn transition_ui(
|
||||||
},
|
},
|
||||||
curr_state.get().phase_count()
|
curr_state.get().phase_count()
|
||||||
))
|
))
|
||||||
.size(64.),
|
.size(MEGA_FONT_SIZE),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -352,8 +354,24 @@ fn place_core(
|
||||||
.title_bar(false)
|
.title_bar(false)
|
||||||
.anchor(Align2::CENTER_BOTTOM, [0., 0.])
|
.anchor(Align2::CENTER_BOTTOM, [0., 0.])
|
||||||
.show(ctx, |ui| {
|
.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)));
|
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::Loading => GameState::Loading,
|
||||||
GameState::Running => GameState::Paused,
|
GameState::Running => GameState::Paused,
|
||||||
GameState::Paused => GameState::Running,
|
GameState::Paused => GameState::Running,
|
||||||
|
s @ _ => *s,
|
||||||
};
|
};
|
||||||
info!("toggle pause, changing to {:?}", next);
|
info!("toggle pause, changing to {:?}", next);
|
||||||
next_state.set(next);
|
next_state.set(next);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue