generated from bbarker/bevy_game_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add score * fix: repair the opening of the menu menu is buged and starting and unopening crashes the game * feat: add score * fix: repair the opening of the menu menu is buged and starting and unopening crashes the game * alocate camera spawning * broken scene switch * fix: only spawn player if he does not exsist yet * fix scene switch problem and code cleanup --------- Co-authored-by: Space Nerd <71553327+SpaceNerde@users.noreply.github.com> Co-authored-by: Space Nerd <spacenerddev@gmail.com>
- Loading branch information
1 parent
8345bf3
commit 8f6fdf1
Showing
6 changed files
with
108 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::GameState; | ||
use bevy::prelude::*; | ||
use bevy_voxel_world::prelude::*; | ||
|
||
pub struct SceneSwitchPlugin; | ||
|
||
/// This Plugin configurats the cameras so that only one is active at a time | ||
impl Plugin for SceneSwitchPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_systems(Startup, setup_cameras) | ||
.add_systems(OnEnter(GameState::Playing), enter_playing) | ||
.add_systems(OnEnter(GameState::Menu), enter_menu); | ||
} | ||
} | ||
|
||
#[derive(Component)] | ||
pub struct MenuCamera; | ||
|
||
fn setup_cameras( | ||
mut commands: Commands, | ||
){ | ||
// Spawn Cameras | ||
|
||
// Menu Camera | ||
commands.spawn((Camera2dBundle::default(), MenuCamera)); | ||
|
||
// Game Camera | ||
commands.spawn(( | ||
Camera3dBundle { | ||
transform: Transform::from_xyz(-200.0, 180.0, -200.0), | ||
..default() | ||
}, | ||
// This tells bevy_voxel_world tos use this cameras transform to calculate spawning area | ||
VoxelWorldCamera, | ||
)); | ||
} | ||
|
||
fn enter_playing( | ||
mut menu_camera_query: Query<&mut Camera, With<MenuCamera>>, | ||
mut game_camera_query: Query<&mut Camera, (With<VoxelWorldCamera>, Without<MenuCamera>)>, | ||
){ | ||
let mut menu_camera = menu_camera_query.single_mut(); | ||
menu_camera.is_active = false; | ||
|
||
let mut game_camera = game_camera_query.single_mut(); | ||
game_camera.is_active = true; | ||
} | ||
|
||
fn enter_menu( | ||
mut menu_camera_query: Query<&mut Camera, With<MenuCamera>>, | ||
mut game_camera_query: Query<&mut Camera, (With<VoxelWorldCamera>, Without<MenuCamera>)>, | ||
){ | ||
let mut menu_camera = menu_camera_query.single_mut(); | ||
menu_camera.is_active = true; | ||
|
||
let mut game_camera = game_camera_query.single_mut(); | ||
game_camera.is_active = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters