diff --git a/src/asteroids.rs b/src/asteroids.rs index 7c3004f..1f351d2 100644 --- a/src/asteroids.rs +++ b/src/asteroids.rs @@ -7,7 +7,7 @@ use std::time::Duration; use bevy::prelude::*; -use crate::{GameAssets, Rotation, WorldSize, physics::Velocity}; +use crate::{GameAssets, WorldSize, physics::Velocity}; #[derive(Component, Deref, DerefMut)] pub struct Asteroid(AsteroidSize); @@ -122,7 +122,6 @@ pub fn spawn_asteroid( Sensor, Transform::from_translation(spawn.pos.extend(0.0)), Velocity(spawn.vel), - Rotation(0.0), Mesh2d(mesh), MeshMaterial2d(material), )); diff --git a/src/lib.rs b/src/lib.rs index 4415e96..1a752fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ use crate::config::{ ASTEROID_SMALL_COLOR, BACKGROUND_COLOR, PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, SHIP_THRUSTER_COLOR_ACTIVE, SHIP_THRUSTER_COLOR_INACTIVE, WINDOW_SIZE, }; -use crate::physics::Rotation; +use crate::physics::AngularVelocity; use crate::ship::Ship; use bevy::prelude::*; @@ -70,7 +70,7 @@ impl Plugin for AsteroidPlugin { .add_event::() .add_event::() .add_event::(); - app.insert_state(GameState::TitleScreen); + app.insert_state(GameState::Playing); } } @@ -237,24 +237,25 @@ fn spawn_camera(mut commands: Commands) { */ fn input_ship_thruster( keyboard_input: Res>, - mut query: Query<(&mut physics::Velocity, &Rotation, &mut Children), With>, + mut query: Query<(&mut physics::Velocity, &Transform, &mut Children), With>, mut commands: Commands, game_assets: Res, ) { // TODO: Maybe change for a Single> so this only runs for the one ship // buuut... that would silently do nothing if there are 0 or >1 ships, and // I might want to crash on purpose in that case. - let Ok((mut velocity, rotation, children)) = query.single_mut() else { + let Ok((mut velocity, transform, children)) = query.single_mut() else { let count = query.iter().count(); panic!("There should be exactly one player ship! Instead, there seems to be {count}."); }; + let rotation = transform.rotation; let thrusters = children .first() .expect("Couldn't find first child, which should be the thruster"); if keyboard_input.pressed(KeyCode::KeyW) { - velocity.0 += Vec2::from_angle(rotation.0) * SHIP_THRUST; + velocity.0 += Vec2::from_angle(rotation.z) * SHIP_THRUST; commands .entity(*thrusters) .insert(MeshMaterial2d(game_assets.thruster_mat_active())); @@ -271,17 +272,17 @@ fn input_ship_thruster( */ fn input_ship_rotation( keyboard_input: Res>, - mut query: Query<&mut Rotation, With>, + mut query: Query<&mut AngularVelocity, With>, ) { - let Ok(mut rotation) = query.single_mut() else { + let Ok(mut angular_vel) = query.single_mut() else { let count = query.iter().count(); panic!("There should be exactly one player ship! Instead, there seems to be {count}."); }; if keyboard_input.pressed(KeyCode::KeyA) { - rotation.0 += SHIP_ROTATION; + angular_vel.0 += SHIP_ROTATION; } else if keyboard_input.pressed(KeyCode::KeyD) { - rotation.0 -= SHIP_ROTATION; + angular_vel.0 -= SHIP_ROTATION; } } diff --git a/src/physics.rs b/src/physics.rs index d41fd75..761b827 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -11,9 +11,6 @@ pub(crate) struct Velocity(pub(crate) bevy::math::Vec2); #[derive(Component)] pub(crate) struct AngularVelocity(pub(crate) f32); -#[derive(Component)] -pub(crate) struct Rotation(pub(crate) f32); - /// Marker for any entity that should wrap on screen edges #[derive(Component)] pub(crate) struct Wrapping; diff --git a/src/ship.rs b/src/ship.rs index fd19e21..aafcf3d 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -1,6 +1,5 @@ use crate::{ - GameAssets, Rotation, - physics::{Velocity, Wrapping}, + physics::{Velocity, Wrapping}, AngularVelocity, GameAssets }; use bevy::prelude::*; @@ -19,7 +18,7 @@ pub fn spawn_player(mut commands: Commands, game_assets: Res) { Ship, Wrapping, Velocity(Vec2::ZERO), - Rotation(0.0), + AngularVelocity(0.0), Mesh2d(game_assets.ship().0), MeshMaterial2d(game_assets.ship().1), Transform::default().with_scale(Vec3::new(20.0, 20.0, 20.0)),