diff --git a/src/drops.rs b/src/drops.rs index 18d1a2e..7815ad3 100644 --- a/src/drops.rs +++ b/src/drops.rs @@ -7,11 +7,7 @@ use bevy_rand::prelude::*; use bevy_rapier2d::prelude::*; use rand::Rng; -use crate::{ - player::{LifeChangeEvent, Player}, - scene::SceneObj, - METER, -}; +use crate::{player::Player, scene::SceneObj, METER}; #[derive(Component)] struct SpawnTimer(pub Timer); @@ -31,13 +27,7 @@ pub fn spawner_plugin(app: &mut App) { .add_systems(Startup, add_timer) .add_systems( Update, - ( - drop_crates, - do_drop, - crate_collisions, - delete_on_env_coll, - player_coll, - ), + (drop_crates, do_drop, crate_collisions, delete_on_env_coll), ); } @@ -140,27 +130,10 @@ fn delete_on_env_coll(mut ev_colls: EventReader, mut commands: C if let CollisionType::Player(_) = with { continue; } + // let CollisionType::Scene(obj) = with else { + // unreachable!() + // }; - if let Some(mut e) = commands.get_entity(*coll_crate) { - e.despawn(); - } - } -} - -fn player_coll( - mut ev_colls: EventReader, - mut ev_lives: EventWriter, - mut commands: Commands, -) { - for CrateCollision { coll_crate, with } in ev_colls.read() { - if let CollisionType::Scene(_) = with { - continue; - } - - ev_lives.send(LifeChangeEvent::Lost); - - if let Some(mut e) = commands.get_entity(*coll_crate) { - e.despawn(); - } + commands.entity(*coll_crate).despawn(); } } diff --git a/src/main.rs b/src/main.rs index e3abb07..79860b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,6 @@ use bevy::{ }; use bevy_rapier2d::prelude::*; use drops::spawner_plugin; -use player::LifeChangeEvent; const METER: f32 = 48.; fn main() { @@ -20,12 +19,12 @@ fn main() { .insert_resource(rapier_config) .add_plugins(RapierPhysicsPlugin::::pixels_per_meter(METER)) .add_plugins(RapierDebugRenderPlugin::default()) - .add_plugins(( - spawner_plugin, - game_state::state_and_ui_plugin, - player::player_plugin, - )) - .add_systems(Startup, (scene::setup_scene, setup_cam)) + .add_plugins((spawner_plugin)) + .add_systems(Startup, (scene::setup_scene, setup_cam, player::add_player)) + .add_systems( + Update, + (player::move_player, player::player_ground_collision), + ) .run() } @@ -39,62 +38,3 @@ fn setup_cam(mut commands: Commands) { mod drops; mod player; mod scene; -mod game_state { - use bevy::{prelude::*, time::Stopwatch}; - - #[derive(Component)] - pub struct GameState { - score: u32, - game_time: Stopwatch, - } - - #[derive(Component)] - struct StateText; - - pub fn state_and_ui_plugin(app: &mut App) { - app.add_systems(Startup, (setup_gamestate, setup_ui)) - .add_systems(Update, (update_time)); - } - - fn setup_gamestate(mut commands: Commands) { - commands.spawn(GameState { - score: 0, - game_time: Stopwatch::new(), - }); - } - - fn setup_ui(mut commands: Commands) { - commands.spawn(( - TextBundle::from_sections([ - TextSection::new("Score: ", TextStyle::default()), - TextSection::new("0", TextStyle::default()), - TextSection::new("\n", TextStyle::default()), - TextSection::new("Time: ", TextStyle::default()), - TextSection::new("0", TextStyle::default()), - TextSection::new("s", TextStyle::default()), - ]) - .with_style(Style { - position_type: PositionType::Absolute, - top: Val::Px(5.0), - right: Val::Px(5.0), - ..default() - }), - StateText, - )); - } - - fn update_time( - mut state_txt: Query<&mut Text, With>, - mut game_state: Query<&mut GameState>, - time: Res