Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c39993fc01 | ||
|
|
1a850787c7 | ||
|
|
33cbdb5443 | ||
|
|
c0ed583d5a | ||
|
|
90ef45ab47 | ||
|
|
832d4ba847 | ||
|
|
452d39dd45 | ||
|
|
3910eb4261 | ||
|
|
05616061ed | ||
|
|
f2f3e5c76c | ||
|
|
7234a3d664 | ||
|
|
9127d9bb1c | ||
|
|
d42f5af75f |
@@ -9,25 +9,28 @@
|
|||||||
|
|
||||||
## Player
|
## Player
|
||||||
- Reset seed on reset
|
- Reset seed on reset
|
||||||
|
- Don't reset on replayer
|
||||||
|
|
||||||
## Game over
|
## Game over
|
||||||
- Create Events to replace global bool resources
|
- Create Events to replace global bool resources
|
||||||
|
|
||||||
## Game states
|
## Game states
|
||||||
- Add game states (Menu, Playing, GameOver, EscMenu, ...)
|
- Add EscMenu
|
||||||
|
- Add SettingsMenu
|
||||||
|
|
||||||
## UI
|
## UI
|
||||||
- Menu ui
|
- Better menu ui
|
||||||
- Playing score etc ui
|
- Better playing score etc ui
|
||||||
- GameOver screen
|
- Better GameOver screen with final score
|
||||||
- Settings ui
|
- Settings ui
|
||||||
- ...
|
- ...
|
||||||
|
|
||||||
## Ideas
|
## Ideas
|
||||||
- Camera shake / non-following patterns
|
- Camera shake / non-following patterns
|
||||||
|
- Player trail (particuls) with normal / speed trails
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
- Camera adapts to screen...
|
- Camera adapts to screen...
|
||||||
|
|
||||||
## Assets
|
## Assets
|
||||||
- Make assets for actual better looking
|
- Make assets for better looking
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{camera::MainCamera, collision::Collider, player::Player};
|
use crate::{camera::MainCamera, collision::Collider, game_state::GameState, player::Player};
|
||||||
|
|
||||||
fn constrain_player(
|
fn constrain_player(
|
||||||
mut player: Single<(&Collider, &mut Transform), With<Player>>,
|
mut player: Single<(&Collider, &mut Transform), With<Player>>,
|
||||||
@@ -20,6 +20,6 @@ pub struct BoundsPlugin;
|
|||||||
|
|
||||||
impl Plugin for BoundsPlugin {
|
impl Plugin for BoundsPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Update, constrain_player);
|
app.add_systems(Update, constrain_player.run_if(in_state(GameState::InGame)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-3
@@ -3,12 +3,11 @@ use bevy::prelude::*;
|
|||||||
use crate::game_state::GameState;
|
use crate::game_state::GameState;
|
||||||
use crate::player::Player;
|
use crate::player::Player;
|
||||||
use crate::player::move_player;
|
use crate::player::move_player;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct MainCamera;
|
pub struct MainCamera;
|
||||||
|
|
||||||
fn spawn_main_camera(mut commands: Commands) {
|
fn spawn_main_camera(mut commands: Commands) {
|
||||||
commands.spawn((Camera2d, MainCamera));
|
commands.spawn((Camera2d, MainCamera, IsDefaultUiCamera));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Follow the player with the camera
|
// Follow the player with the camera
|
||||||
@@ -22,11 +21,17 @@ fn follow_player(
|
|||||||
// + (player.translation.y - camera.translation.y) * 3.0 * time.delta_secs(); // with delay
|
// + (player.translation.y - camera.translation.y) * 3.0 * time.delta_secs(); // with delay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn reset_camera(mut main_camera: Single<&mut Camera, With<MainCamera>>) {
|
||||||
|
main_camera.is_active = true;
|
||||||
|
}
|
||||||
|
|
||||||
pub struct CameraPlugin;
|
pub struct CameraPlugin;
|
||||||
|
|
||||||
impl Plugin for CameraPlugin {
|
impl Plugin for CameraPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, spawn_main_camera).add_systems(
|
app.add_systems(Startup, spawn_main_camera)
|
||||||
|
.add_systems(OnEnter(GameState::InGame), reset_camera)
|
||||||
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
follow_player
|
follow_player
|
||||||
.run_if(in_state(GameState::InGame))
|
.run_if(in_state(GameState::InGame))
|
||||||
|
|||||||
+3
-10
@@ -12,19 +12,12 @@ pub struct Collider {
|
|||||||
pub size: Vec2,
|
pub size: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource, Default)]
|
|
||||||
pub struct HasCollided(pub bool);
|
|
||||||
|
|
||||||
// Check collision with Player
|
// Check collision with Player
|
||||||
pub fn check_collision_with_player(
|
pub fn check_collision_with_player(
|
||||||
player: Single<(&Transform, &Collider, &mut Sprite), With<Player>>,
|
player: Single<(&Transform, &Collider, &mut Sprite), With<Player>>,
|
||||||
obstacle: Query<(&Transform, &Collider), With<Obstacle>>,
|
obstacle: Query<(&Transform, &Collider), With<Obstacle>>,
|
||||||
mut has_collided: ResMut<HasCollided>,
|
mut next_state: ResMut<NextState<GameState>>,
|
||||||
) {
|
) {
|
||||||
if has_collided.0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let (player_transform, player_collider, mut _player_sprite) = player.into_inner();
|
let (player_transform, player_collider, mut _player_sprite) = player.into_inner();
|
||||||
|
|
||||||
// Check whether or not each obstacles overlap the player
|
// Check whether or not each obstacles overlap the player
|
||||||
@@ -36,7 +29,7 @@ pub fn check_collision_with_player(
|
|||||||
collider_collider.size / 2.0,
|
collider_collider.size / 2.0,
|
||||||
) {
|
) {
|
||||||
// player_sprite.color = Color::srgb(1.0, 0.0, 0.0); // Change sprite color
|
// player_sprite.color = Color::srgb(1.0, 0.0, 0.0); // Change sprite color
|
||||||
has_collided.0 = true;
|
next_state.set(GameState::GameOver);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,7 +46,7 @@ pub struct CollisionPlugin;
|
|||||||
|
|
||||||
impl Plugin for CollisionPlugin {
|
impl Plugin for CollisionPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.init_resource::<HasCollided>().add_systems(
|
app.add_systems(
|
||||||
Update,
|
Update,
|
||||||
check_collision_with_player
|
check_collision_with_player
|
||||||
.run_if(in_state(GameState::InGame))
|
.run_if(in_state(GameState::InGame))
|
||||||
|
|||||||
+96
-7
@@ -1,12 +1,19 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::{
|
||||||
|
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{camera::MainCamera, game_state::GameState, player::Player};
|
use crate::{camera::MainCamera, game_state::GameState, player::Player, world::RunSeed};
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Debug;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct DebugCamera;
|
pub struct DebugCamera;
|
||||||
|
|
||||||
fn spawn_debug_camera(mut commands: Commands) {
|
fn spawn_debug_camera(mut commands: Commands) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
Debug,
|
||||||
DebugCamera,
|
DebugCamera,
|
||||||
Camera2d,
|
Camera2d,
|
||||||
Camera {
|
Camera {
|
||||||
@@ -63,6 +70,7 @@ fn spawn_debug_frame(mut commands: Commands) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
Debug,
|
||||||
FramePart(side),
|
FramePart(side),
|
||||||
Sprite::from_color(Color::srgb(1.0, 0.0, 0.0), size),
|
Sprite::from_color(Color::srgb(1.0, 0.0, 0.0), size),
|
||||||
Visibility::Hidden,
|
Visibility::Hidden,
|
||||||
@@ -99,23 +107,104 @@ fn draw_view_frame(
|
|||||||
*visibility = visible;
|
*visibility = visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct SeedDebugText;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct FpsDebugText;
|
||||||
|
|
||||||
|
// Debug information on screen
|
||||||
|
fn spawn_debug_texts(mut commands: Commands) {
|
||||||
|
commands.spawn((
|
||||||
|
Debug,
|
||||||
|
Node {
|
||||||
|
position_type: PositionType::Absolute,
|
||||||
|
right: Val::Px(0.0),
|
||||||
|
top: Val::Px(0.0),
|
||||||
|
width: Val::Percent(17.0),
|
||||||
|
height: Val::Percent(10.0),
|
||||||
|
flex_direction: FlexDirection::Column,
|
||||||
|
row_gap: Val::Px(5.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
// Black background
|
||||||
|
BackgroundColor(Color::srgba(0.0, 1.0, 0.0, 0.1)),
|
||||||
|
// Texts
|
||||||
|
children![
|
||||||
|
// Seed display
|
||||||
|
(
|
||||||
|
Text::new(""),
|
||||||
|
TextFont {
|
||||||
|
font_size: FontSize::Px(20.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
TextColor(Color::srgb(1.0, 1.0, 0.0)),
|
||||||
|
SeedDebugText,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Text::new(""),
|
||||||
|
TextFont {
|
||||||
|
font_size: FontSize::Px(20.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
TextColor(Color::srgb(1.0, 1.0, 0.0)),
|
||||||
|
FpsDebugText,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update depth score texts
|
||||||
|
fn update_seed_debug_text(
|
||||||
|
run_seed: Res<RunSeed>,
|
||||||
|
mut run_seed_debug_text: Single<&mut Text, With<SeedDebugText>>,
|
||||||
|
) {
|
||||||
|
run_seed_debug_text.0 = format!("Seed: {}", run_seed.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_fps_debug_text(
|
||||||
|
store: Res<DiagnosticsStore>,
|
||||||
|
mut fps_debug_text: Single<&mut Text, With<FpsDebugText>>,
|
||||||
|
) {
|
||||||
|
if let Some(fps) = store.get(&FrameTimeDiagnosticsPlugin::FPS) {
|
||||||
|
if let Some(value) = fps.smoothed() {
|
||||||
|
fps_debug_text.0 = format!("FPS: {:.0}", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cleanup_debug(mut commands: Commands, entities: Query<Entity, With<Debug>>) {
|
||||||
|
for entity in entities {
|
||||||
|
commands.entity(entity).despawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct DebugPlugin;
|
pub struct DebugPlugin;
|
||||||
|
|
||||||
impl Plugin for DebugPlugin {
|
impl Plugin for DebugPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
Startup,
|
OnEnter(GameState::InGame),
|
||||||
(
|
(
|
||||||
spawn_debug_camera,
|
spawn_debug_camera,
|
||||||
setup_debug_camera.after(spawn_debug_camera),
|
setup_debug_camera.after(spawn_debug_camera),
|
||||||
spawn_debug_frame,
|
spawn_debug_frame,
|
||||||
)
|
spawn_debug_texts,
|
||||||
.run_if(in_state(GameState::InGame)),
|
),
|
||||||
)
|
)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(draw_view_frame, follow_player_debug, toggle_debug_camera)
|
(
|
||||||
|
draw_view_frame,
|
||||||
|
follow_player_debug,
|
||||||
|
toggle_debug_camera,
|
||||||
|
update_seed_debug_text,
|
||||||
|
update_fps_debug_text,
|
||||||
|
)
|
||||||
.run_if(in_state(GameState::InGame)),
|
.run_if(in_state(GameState::InGame)),
|
||||||
);
|
)
|
||||||
|
.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
||||||
|
.add_systems(OnExit(GameState::InGame), cleanup_debug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-7
@@ -1,12 +1,14 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::game_state::GameState;
|
use crate::{camera::MainCamera, game_state::GameState, world::RunSeed};
|
||||||
|
|
||||||
// To delete game over's components
|
// To delete game over's components
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct GameOver;
|
pub struct GameOver;
|
||||||
|
|
||||||
fn game_over(mut commands: Commands) {
|
fn game_over(mut commands: Commands, mut main_camera: Single<&mut Camera, With<MainCamera>>) {
|
||||||
|
main_camera.is_active = true;
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
GameOver,
|
GameOver,
|
||||||
Node {
|
Node {
|
||||||
@@ -18,6 +20,9 @@ fn game_over(mut commands: Commands) {
|
|||||||
row_gap: Val::Px(30.0),
|
row_gap: Val::Px(30.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
// Black background
|
||||||
|
BackgroundColor(Color::BLACK),
|
||||||
|
// Texts
|
||||||
children![
|
children![
|
||||||
(
|
(
|
||||||
Text::new("GAME OVER"),
|
Text::new("GAME OVER"),
|
||||||
@@ -27,7 +32,7 @@ fn game_over(mut commands: Commands) {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Text::new("| N new map | R restart | T main menu | "),
|
Text::new("N new map | R restart | T main menu"),
|
||||||
TextFont {
|
TextFont {
|
||||||
font_size: FontSize::Px(40.0),
|
font_size: FontSize::Px(40.0),
|
||||||
..default()
|
..default()
|
||||||
@@ -43,15 +48,21 @@ fn cleanup_game_over(mut commands: Commands, game_over: Query<Entity, With<GameO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn game_over_input(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<GameState>>) {
|
// For debug bug same logic on collision (will be renamed)
|
||||||
|
fn game_over_input(
|
||||||
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
|
mut run_seed: ResMut<RunSeed>,
|
||||||
|
mut next_state: ResMut<NextState<GameState>>,
|
||||||
|
) {
|
||||||
if input.just_pressed(KeyCode::KeyN) {
|
if input.just_pressed(KeyCode::KeyN) {
|
||||||
// TODO: Restart with completely reseting the game state (OnEnter maybe)
|
// New seed
|
||||||
|
run_seed.0 = rand::random::<u64>();
|
||||||
next_state.set(GameState::InGame);
|
next_state.set(GameState::InGame);
|
||||||
} else if input.just_pressed(KeyCode::KeyR) {
|
} else if input.just_pressed(KeyCode::KeyR) {
|
||||||
// TODO: restart with the same seed
|
// Same seed
|
||||||
next_state.set(GameState::InGame);
|
next_state.set(GameState::InGame);
|
||||||
} else if input.just_pressed(KeyCode::KeyT) {
|
} else if input.just_pressed(KeyCode::KeyT) {
|
||||||
// TODO: Clear all of the game asset (OnExit)
|
// Return to the Main Menu
|
||||||
next_state.set(GameState::MainMenu);
|
next_state.set(GameState::MainMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-8
@@ -1,6 +1,6 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::game_state::GameState;
|
use crate::{camera::MainCamera, game_state::GameState};
|
||||||
|
|
||||||
// To delete menu's components
|
// To delete menu's components
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@@ -18,6 +18,9 @@ fn main_menu(mut commands: Commands) {
|
|||||||
row_gap: Val::Px(30.0),
|
row_gap: Val::Px(30.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
// Black background
|
||||||
|
BackgroundColor(Color::BLACK),
|
||||||
|
// Texts
|
||||||
children![
|
children![
|
||||||
(
|
(
|
||||||
Text::new("DOWN INTO THE VOID"),
|
Text::new("DOWN INTO THE VOID"),
|
||||||
@@ -37,23 +40,28 @@ fn main_menu(mut commands: Commands) {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cleanup_menu(mut commands: Commands, menu: Query<Entity, With<MainMenu>>) {
|
// Wait player to press enter for starting the fall
|
||||||
for entity in menu {
|
|
||||||
commands.entity(entity).despawn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn menu_input(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<GameState>>) {
|
fn menu_input(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<GameState>>) {
|
||||||
if input.just_pressed(KeyCode::Enter) {
|
if input.just_pressed(KeyCode::Enter) {
|
||||||
next_state.set(GameState::InGame);
|
next_state.set(GameState::InGame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean all menu's entities
|
||||||
|
fn cleanup_menu(mut commands: Commands, menu: Query<Entity, With<MainMenu>>) {
|
||||||
|
for entity in menu {
|
||||||
|
commands.entity(entity).despawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn reset_camera(mut main_camera: Single<&mut Camera, With<MainCamera>>) {
|
||||||
|
main_camera.is_active = true;
|
||||||
|
}
|
||||||
|
|
||||||
pub struct MainMenuPlugin;
|
pub struct MainMenuPlugin;
|
||||||
|
|
||||||
impl Plugin for MainMenuPlugin {
|
impl Plugin for MainMenuPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(OnEnter(GameState::MainMenu), main_menu)
|
app.add_systems(OnEnter(GameState::MainMenu), (main_menu, reset_camera))
|
||||||
.add_systems(Update, menu_input.run_if(in_state(GameState::MainMenu)))
|
.add_systems(Update, menu_input.run_if(in_state(GameState::MainMenu)))
|
||||||
.add_systems(OnExit(GameState::MainMenu), cleanup_menu);
|
.add_systems(OnExit(GameState::MainMenu), cleanup_menu);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
use crate::{collision::Collider, player::reset_player};
|
use crate::collision::Collider;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use rand::RngExt;
|
use rand::RngExt;
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
|
|||||||
+23
-19
@@ -1,7 +1,7 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
use crate::collision::Collider;
|
||||||
use crate::collision::check_collision_with_player;
|
use crate::collision::check_collision_with_player;
|
||||||
use crate::collision::{Collider, HasCollided};
|
|
||||||
use crate::game_state::GameState;
|
use crate::game_state::GameState;
|
||||||
|
|
||||||
const FALL_SPEED: f32 = 600.0; // Falling speed
|
const FALL_SPEED: f32 = 600.0; // Falling speed
|
||||||
@@ -84,48 +84,52 @@ pub(crate) fn move_player(
|
|||||||
transform.translation += velocity.0.extend(0.0) * time.delta_secs();
|
transform.translation += velocity.0.extend(0.0) * time.delta_secs();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset player position
|
// Debug
|
||||||
pub fn reset_player(
|
pub fn debug_game_over(
|
||||||
player: Single<(&mut Transform, &mut Velocity, &mut Sprite), With<Player>>,
|
// player: Single<(&mut Transform, &mut Velocity, &mut Sprite), With<Player>>,
|
||||||
input: Res<ButtonInput<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut has_collided: ResMut<HasCollided>,
|
|
||||||
mut fall_started: ResMut<FallStarted>,
|
mut fall_started: ResMut<FallStarted>,
|
||||||
// mut regenerate_obstacles: ResMut<RegenerateObstacles>,
|
|
||||||
mut next_state: ResMut<NextState<GameState>>, // For debug gameover state
|
mut next_state: ResMut<NextState<GameState>>, // For debug gameover state
|
||||||
) {
|
) {
|
||||||
let (mut transform, mut velocity, mut sprite) = player.into_inner();
|
// let (mut transform, mut velocity, mut sprite) = player.into_inner();
|
||||||
|
|
||||||
// R key for reset or player has collider
|
// R key for reset or player has collider
|
||||||
if input.just_pressed(KeyCode::KeyR) || has_collided.0 {
|
if input.just_pressed(KeyCode::KeyG) {
|
||||||
transform.translation = Vec3::new(START_POSITION.x, START_POSITION.y, START_POSITION.z);
|
// transform.translation = Vec3::new(START_POSITION.x, START_POSITION.y, START_POSITION.z);
|
||||||
velocity.0 = Vec2::ZERO;
|
// velocity.0 = Vec2::ZERO;
|
||||||
sprite.color = Color::WHITE;
|
// sprite.color = Color::WHITE;
|
||||||
|
|
||||||
has_collided.0 = false;
|
|
||||||
fall_started.0 = false;
|
fall_started.0 = false;
|
||||||
// TODO: uncomment when obstacle chunk logic is implemented
|
|
||||||
// regenerate_obstacles.0 = true;
|
|
||||||
} else if input.just_pressed(KeyCode::KeyG) {
|
|
||||||
// Temporary test for gameover state
|
|
||||||
next_state.set(GameState::GameOver);
|
next_state.set(GameState::GameOver);
|
||||||
|
// TODO: uncomment when obstacle chunk logic is implemented
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To freeze player at the begining of the Ingame
|
||||||
|
fn start_run(mut fall_started: ResMut<FallStarted>) {
|
||||||
|
fall_started.0 = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cleanup_player(mut commands: Commands, player: Single<Entity, With<Player>>) {
|
||||||
|
commands.entity(*player).despawn();
|
||||||
|
}
|
||||||
|
|
||||||
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(Startup, spawn_player)
|
app.add_systems(OnEnter(GameState::InGame), (spawn_player, start_run))
|
||||||
.init_resource::<FallStarted>()
|
.init_resource::<FallStarted>()
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(
|
(
|
||||||
move_player,
|
move_player,
|
||||||
reset_player
|
debug_game_over
|
||||||
.after(move_player)
|
.after(move_player)
|
||||||
.after(check_collision_with_player),
|
.after(check_collision_with_player),
|
||||||
)
|
)
|
||||||
.run_if(in_state(GameState::InGame)),
|
.run_if(in_state(GameState::InGame)),
|
||||||
);
|
)
|
||||||
|
.add_systems(OnExit(GameState::InGame), cleanup_player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-11
@@ -35,14 +35,16 @@ fn spawn_depth_text(mut commands: Commands) {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update depth score text
|
// Update depth score texts
|
||||||
fn update_depth_text(
|
fn update_depth_text(depth: Res<Depth>, texts: Query<&mut Text, With<DepthText>>) {
|
||||||
mut commands: Commands,
|
|
||||||
depth: Res<Depth>,
|
|
||||||
texts: Query<&mut Text, With<DepthText>>,
|
|
||||||
) {
|
|
||||||
for mut text in texts {
|
for mut text in texts {
|
||||||
text.0 = format!("Score: {}", depth.0);
|
text.0 = format!("Score: {}", (depth.0 / 100.0).floor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cleanup_score(mut commands: Commands, entities: Query<Entity, With<DepthText>>) {
|
||||||
|
for entity in entities {
|
||||||
|
commands.entity(entity).despawn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +52,16 @@ pub struct ScorePlugin;
|
|||||||
|
|
||||||
impl Plugin for ScorePlugin {
|
impl Plugin for ScorePlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, spawn_depth_text)
|
app.init_resource::<Depth>()
|
||||||
.init_resource::<Depth>()
|
.add_systems(OnEnter(GameState::InGame), spawn_depth_text)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(update_depth_text, update_depth.after(move_player))
|
(
|
||||||
|
update_depth_text.after(spawn_depth_text),
|
||||||
|
update_depth.after(move_player),
|
||||||
|
)
|
||||||
.run_if(in_state(GameState::InGame)),
|
.run_if(in_state(GameState::InGame)),
|
||||||
);
|
)
|
||||||
|
.add_systems(OnExit(GameState::InGame), cleanup_score);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-1
@@ -57,11 +57,19 @@ fn spawn_chunk(commands: &mut Commands, id: i64, run_seed: u64) {
|
|||||||
crate::background::spawn_background_chunk(commands, id);
|
crate::background::spawn_background_chunk(commands, id);
|
||||||
// crate::obstacle::spawn_obstacle_chunk(commands, id, run_seed);
|
// crate::obstacle::spawn_obstacle_chunk(commands, id, run_seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cleanup_chunk(mut commands: Commands, entities: Query<Entity, With<Chunk>>) {
|
||||||
|
for entity in entities {
|
||||||
|
commands.entity(entity).despawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct WorldPlugin;
|
pub struct WorldPlugin;
|
||||||
|
|
||||||
impl Plugin for WorldPlugin {
|
impl Plugin for WorldPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.insert_resource(RunSeed(rand::random::<u64>()))
|
app.insert_resource(RunSeed(rand::random::<u64>()))
|
||||||
.add_systems(Update, stream_world.run_if(in_state(GameState::InGame)));
|
.add_systems(Update, stream_world.run_if(in_state(GameState::InGame)))
|
||||||
|
.add_systems(OnExit(GameState::InGame), cleanup_chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user