Compare commits
13
Commits
9df830bf18
...
c39993fc01
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c39993fc01 | ||
|
|
1a850787c7 | ||
|
|
33cbdb5443 | ||
|
|
c0ed583d5a | ||
|
|
90ef45ab47 | ||
|
|
832d4ba847 | ||
|
|
452d39dd45 | ||
|
|
3910eb4261 | ||
|
|
05616061ed | ||
|
|
f2f3e5c76c | ||
|
|
7234a3d664 | ||
|
|
9127d9bb1c | ||
|
|
d42f5af75f |
@@ -9,25 +9,28 @@
|
||||
|
||||
## Player
|
||||
- Reset seed on reset
|
||||
- Don't reset on replayer
|
||||
|
||||
## Game over
|
||||
- Create Events to replace global bool resources
|
||||
|
||||
## Game states
|
||||
- Add game states (Menu, Playing, GameOver, EscMenu, ...)
|
||||
- Add EscMenu
|
||||
- Add SettingsMenu
|
||||
|
||||
## UI
|
||||
- Menu ui
|
||||
- Playing score etc ui
|
||||
- GameOver screen
|
||||
- Better menu ui
|
||||
- Better playing score etc ui
|
||||
- Better GameOver screen with final score
|
||||
- Settings ui
|
||||
- ...
|
||||
|
||||
## Ideas
|
||||
- Camera shake / non-following patterns
|
||||
- Player trail (particuls) with normal / speed trails
|
||||
|
||||
## Bugs
|
||||
- Camera adapts to screen...
|
||||
|
||||
## Assets
|
||||
- Make assets for actual better looking
|
||||
- Make assets for better looking
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
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(
|
||||
mut player: Single<(&Collider, &mut Transform), With<Player>>,
|
||||
@@ -20,6 +20,6 @@ pub struct BoundsPlugin;
|
||||
|
||||
impl Plugin for BoundsPlugin {
|
||||
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::player::Player;
|
||||
use crate::player::move_player;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct MainCamera;
|
||||
|
||||
fn spawn_main_camera(mut commands: Commands) {
|
||||
commands.spawn((Camera2d, MainCamera));
|
||||
commands.spawn((Camera2d, MainCamera, IsDefaultUiCamera));
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
fn reset_camera(mut main_camera: Single<&mut Camera, With<MainCamera>>) {
|
||||
main_camera.is_active = true;
|
||||
}
|
||||
|
||||
pub struct CameraPlugin;
|
||||
|
||||
impl Plugin for CameraPlugin {
|
||||
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,
|
||||
follow_player
|
||||
.run_if(in_state(GameState::InGame))
|
||||
|
||||
+3
-10
@@ -12,19 +12,12 @@ pub struct Collider {
|
||||
pub size: Vec2,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct HasCollided(pub bool);
|
||||
|
||||
// Check collision with Player
|
||||
pub fn check_collision_with_player(
|
||||
player: Single<(&Transform, &Collider, &mut Sprite), With<Player>>,
|
||||
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();
|
||||
|
||||
// Check whether or not each obstacles overlap the player
|
||||
@@ -36,7 +29,7 @@ pub fn check_collision_with_player(
|
||||
collider_collider.size / 2.0,
|
||||
) {
|
||||
// player_sprite.color = Color::srgb(1.0, 0.0, 0.0); // Change sprite color
|
||||
has_collided.0 = true;
|
||||
next_state.set(GameState::GameOver);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -53,7 +46,7 @@ pub struct CollisionPlugin;
|
||||
|
||||
impl Plugin for CollisionPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<HasCollided>().add_systems(
|
||||
app.add_systems(
|
||||
Update,
|
||||
check_collision_with_player
|
||||
.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)]
|
||||
pub struct DebugCamera;
|
||||
|
||||
fn spawn_debug_camera(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Debug,
|
||||
DebugCamera,
|
||||
Camera2d,
|
||||
Camera {
|
||||
@@ -63,6 +70,7 @@ fn spawn_debug_frame(mut commands: Commands) {
|
||||
};
|
||||
|
||||
commands.spawn((
|
||||
Debug,
|
||||
FramePart(side),
|
||||
Sprite::from_color(Color::srgb(1.0, 0.0, 0.0), size),
|
||||
Visibility::Hidden,
|
||||
@@ -99,23 +107,104 @@ fn draw_view_frame(
|
||||
*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;
|
||||
|
||||
impl Plugin for DebugPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
Startup,
|
||||
OnEnter(GameState::InGame),
|
||||
(
|
||||
spawn_debug_camera,
|
||||
setup_debug_camera.after(spawn_debug_camera),
|
||||
spawn_debug_frame,
|
||||
)
|
||||
.run_if(in_state(GameState::InGame)),
|
||||
spawn_debug_texts,
|
||||
),
|
||||
)
|
||||
.add_systems(
|
||||
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)),
|
||||
);
|
||||
)
|
||||
.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_systems(OnExit(GameState::InGame), cleanup_debug);
|
||||
}
|
||||
}
|
||||
|
||||
+18
-7
@@ -1,12 +1,14 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::game_state::GameState;
|
||||
use crate::{camera::MainCamera, game_state::GameState, world::RunSeed};
|
||||
|
||||
// To delete game over's components
|
||||
#[derive(Component)]
|
||||
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((
|
||||
GameOver,
|
||||
Node {
|
||||
@@ -18,6 +20,9 @@ fn game_over(mut commands: Commands) {
|
||||
row_gap: Val::Px(30.0),
|
||||
..default()
|
||||
},
|
||||
// Black background
|
||||
BackgroundColor(Color::BLACK),
|
||||
// Texts
|
||||
children![
|
||||
(
|
||||
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 {
|
||||
font_size: FontSize::Px(40.0),
|
||||
..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) {
|
||||
// TODO: Restart with completely reseting the game state (OnEnter maybe)
|
||||
// New seed
|
||||
run_seed.0 = rand::random::<u64>();
|
||||
next_state.set(GameState::InGame);
|
||||
} else if input.just_pressed(KeyCode::KeyR) {
|
||||
// TODO: restart with the same seed
|
||||
// Same seed
|
||||
next_state.set(GameState::InGame);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-8
@@ -1,6 +1,6 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::game_state::GameState;
|
||||
use crate::{camera::MainCamera, game_state::GameState};
|
||||
|
||||
// To delete menu's components
|
||||
#[derive(Component)]
|
||||
@@ -18,6 +18,9 @@ fn main_menu(mut commands: Commands) {
|
||||
row_gap: Val::Px(30.0),
|
||||
..default()
|
||||
},
|
||||
// Black background
|
||||
BackgroundColor(Color::BLACK),
|
||||
// Texts
|
||||
children![
|
||||
(
|
||||
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>>) {
|
||||
for entity in menu {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
// Wait player to press enter for starting the fall
|
||||
fn menu_input(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<GameState>>) {
|
||||
if input.just_pressed(KeyCode::Enter) {
|
||||
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;
|
||||
|
||||
impl Plugin for MainMenuPlugin {
|
||||
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(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 rand::RngExt;
|
||||
use rand::SeedableRng;
|
||||
|
||||
+23
-19
@@ -1,7 +1,7 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::collision::Collider;
|
||||
use crate::collision::check_collision_with_player;
|
||||
use crate::collision::{Collider, HasCollided};
|
||||
use crate::game_state::GameState;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
// Reset player position
|
||||
pub fn reset_player(
|
||||
player: Single<(&mut Transform, &mut Velocity, &mut Sprite), With<Player>>,
|
||||
// Debug
|
||||
pub fn debug_game_over(
|
||||
// player: Single<(&mut Transform, &mut Velocity, &mut Sprite), With<Player>>,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
mut has_collided: ResMut<HasCollided>,
|
||||
mut fall_started: ResMut<FallStarted>,
|
||||
// mut regenerate_obstacles: ResMut<RegenerateObstacles>,
|
||||
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
|
||||
if input.just_pressed(KeyCode::KeyR) || has_collided.0 {
|
||||
transform.translation = Vec3::new(START_POSITION.x, START_POSITION.y, START_POSITION.z);
|
||||
velocity.0 = Vec2::ZERO;
|
||||
sprite.color = Color::WHITE;
|
||||
if input.just_pressed(KeyCode::KeyG) {
|
||||
// transform.translation = Vec3::new(START_POSITION.x, START_POSITION.y, START_POSITION.z);
|
||||
// velocity.0 = Vec2::ZERO;
|
||||
// sprite.color = Color::WHITE;
|
||||
|
||||
has_collided.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);
|
||||
// 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;
|
||||
|
||||
impl Plugin for PlayerPlugin {
|
||||
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>()
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
move_player,
|
||||
reset_player
|
||||
debug_game_over
|
||||
.after(move_player)
|
||||
.after(check_collision_with_player),
|
||||
)
|
||||
.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
|
||||
fn update_depth_text(
|
||||
mut commands: Commands,
|
||||
depth: Res<Depth>,
|
||||
texts: Query<&mut Text, With<DepthText>>,
|
||||
) {
|
||||
// Update depth score texts
|
||||
fn update_depth_text(depth: Res<Depth>, texts: Query<&mut Text, With<DepthText>>) {
|
||||
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 {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_depth_text)
|
||||
.init_resource::<Depth>()
|
||||
app.init_resource::<Depth>()
|
||||
.add_systems(OnEnter(GameState::InGame), spawn_depth_text)
|
||||
.add_systems(
|
||||
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)),
|
||||
);
|
||||
)
|
||||
.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::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;
|
||||
|
||||
impl Plugin for WorldPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
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