Miguel's state of mind
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -7,7 +7,9 @@ use goal::{check_goal, GoalBundle};
|
|||||||
use ground_detection::GroundDetectionPlugin;
|
use ground_detection::GroundDetectionPlugin;
|
||||||
use level_structure::{WallBundle, WallPlugin};
|
use level_structure::{WallBundle, WallPlugin};
|
||||||
use logging::log_positions;
|
use logging::log_positions;
|
||||||
|
use menu::spawn_box;
|
||||||
use player::PlayerPlugin;
|
use player::PlayerPlugin;
|
||||||
|
use state::GameState;
|
||||||
|
|
||||||
mod animations;
|
mod animations;
|
||||||
mod camera;
|
mod camera;
|
||||||
@@ -16,13 +18,15 @@ mod goal;
|
|||||||
mod ground_detection;
|
mod ground_detection;
|
||||||
mod level_structure;
|
mod level_structure;
|
||||||
mod logging;
|
mod logging;
|
||||||
|
mod menu;
|
||||||
mod player;
|
mod player;
|
||||||
|
mod state;
|
||||||
pub const GRID_SIZE: i32 = 16;
|
pub const GRID_SIZE: i32 = 16;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
|
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
|
||||||
|
.insert_state(GameState::MainMenu)
|
||||||
.add_plugins((
|
.add_plugins((
|
||||||
LdtkPlugin,
|
LdtkPlugin,
|
||||||
RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0),
|
RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0),
|
||||||
@@ -46,6 +50,7 @@ fn main() {
|
|||||||
.register_ldtk_entity::<GoalBundle>("Goal")
|
.register_ldtk_entity::<GoalBundle>("Goal")
|
||||||
.register_ldtk_int_cell::<WallBundle>(1)
|
.register_ldtk_int_cell::<WallBundle>(1)
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
|
.add_systems(Update, spawn_box.run_if(in_state(GameState::MainMenu)))
|
||||||
.add_plugins(CameraPlugin)
|
.add_plugins(CameraPlugin)
|
||||||
.add_plugins(ShockingAnimationPlugin)
|
.add_plugins(ShockingAnimationPlugin)
|
||||||
.add_systems(Update, (translate_grid_coords_entities, check_goal))
|
.add_systems(Update, (translate_grid_coords_entities, check_goal))
|
||||||
@@ -53,7 +58,10 @@ fn main() {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn setup(
|
||||||
|
mut commands: Commands,
|
||||||
|
asset_server: Res<AssetServer>,
|
||||||
|
) {
|
||||||
commands.spawn(LdtkWorldBundle {
|
commands.spawn(LdtkWorldBundle {
|
||||||
ldtk_handle: asset_server.load("shocked-miguel.ldtk"),
|
ldtk_handle: asset_server.load("shocked-miguel.ldtk"),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|||||||
54
src/menu.rs
Normal file
54
src/menu.rs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
use bevy::{
|
||||||
|
color::Color,
|
||||||
|
ecs::system::Commands,
|
||||||
|
ui::{node_bundles::NodeBundle, JustifyContent, Style, UiRect, Val},
|
||||||
|
};
|
||||||
|
pub(crate) fn spawn_box(mut commands: Commands) {
|
||||||
|
let container = NodeBundle {
|
||||||
|
style: Style {
|
||||||
|
width: Val::Percent(100.0),
|
||||||
|
height: Val::Percent(100.0),
|
||||||
|
justify_content: JustifyContent::Center,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
..default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let square = NodeBundle {
|
||||||
|
style: Style {
|
||||||
|
width: Val::Px(200.),
|
||||||
|
border: UiRect::all(Val::Px(2.)),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
background_color: Color::srgb(0., 0.65, 0.65).into(),
|
||||||
|
..default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let parent = commands.spawn(container).id();
|
||||||
|
let child = commands.spawn(square).id();
|
||||||
|
|
||||||
|
commands.entity(parent).push_children(&[child]);
|
||||||
|
}
|
||||||
|
pub(crate) fn spawn_text(mut commands: Commands) {
|
||||||
|
let text = "Hello world!";
|
||||||
|
|
||||||
|
commands.spawn(
|
||||||
|
TextBundle::from_section(
|
||||||
|
text,
|
||||||
|
TextStyle {
|
||||||
|
font_size: 100.0,
|
||||||
|
color: Color::WHITE,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
) // Set the alignment of the Text
|
||||||
|
.with_text_justify(JustifyText::Center)
|
||||||
|
// Set the style of the TextBundle itself.
|
||||||
|
.with_style(Style {
|
||||||
|
position_type: PositionType::Absolute,
|
||||||
|
bottom: Val::Px(5.0),
|
||||||
|
right: Val::Px(5.0),
|
||||||
|
..default()
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -6,13 +6,14 @@ use crate::{
|
|||||||
animations::{AnimationIndices, AnimationTimer},
|
animations::{AnimationIndices, AnimationTimer},
|
||||||
colliders::ColliderBundle,
|
colliders::ColliderBundle,
|
||||||
ground_detection::GroundDetection,
|
ground_detection::GroundDetection,
|
||||||
|
state::GameState,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct PlayerPlugin;
|
pub struct PlayerPlugin;
|
||||||
|
|
||||||
impl Plugin for PlayerPlugin {
|
impl Plugin for PlayerPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Update, player_movement)
|
app.add_systems(Update, player_movement.run_if(in_state(GameState::InGame)))
|
||||||
.register_ldtk_entity::<PlayerBundle>("Player");
|
.register_ldtk_entity::<PlayerBundle>("Player");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/state.rs
Normal file
20
src/state.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
use bevy::{
|
||||||
|
ecs::system::ResMut,
|
||||||
|
state::state::{NextState, States},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default, States)]
|
||||||
|
pub(crate) enum GameState {
|
||||||
|
#[default]
|
||||||
|
MainMenu,
|
||||||
|
InGame,
|
||||||
|
GamePaused,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_game(mut next_state: ResMut<NextState<GameState>>) {
|
||||||
|
next_state.set(GameState::InGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pause_game(mut next_state: ResMut<NextState<GameState>>) {
|
||||||
|
next_state.set(GameState::GamePaused);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user