Move ship parts into it's own submodule
This commit is contained in:
32
src/lib.rs
32
src/lib.rs
@@ -1,6 +1,7 @@
|
|||||||
mod asteroids;
|
mod asteroids;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
mod preparation_widget;
|
mod preparation_widget;
|
||||||
|
mod ship;
|
||||||
mod title_screen;
|
mod title_screen;
|
||||||
|
|
||||||
use crate::config::{BACKGROUND_COLOR, PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, WINDOW_SIZE};
|
use crate::config::{BACKGROUND_COLOR, PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, WINDOW_SIZE};
|
||||||
@@ -16,6 +17,7 @@ use bevy_rapier2d::{
|
|||||||
render::RapierDebugRenderPlugin,
|
render::RapierDebugRenderPlugin,
|
||||||
};
|
};
|
||||||
use config::{ASTEROID_SMALL_COLOR, SHIP_THRUSTER_COLOR_ACTIVE, SHIP_THRUSTER_COLOR_INACTIVE};
|
use config::{ASTEROID_SMALL_COLOR, SHIP_THRUSTER_COLOR_ACTIVE, SHIP_THRUSTER_COLOR_INACTIVE};
|
||||||
|
use ship::Ship;
|
||||||
|
|
||||||
pub struct AsteroidPlugin;
|
pub struct AsteroidPlugin;
|
||||||
|
|
||||||
@@ -38,7 +40,7 @@ impl Plugin for AsteroidPlugin {
|
|||||||
.insert_resource(AsteroidSpawner::new())
|
.insert_resource(AsteroidSpawner::new())
|
||||||
.init_resource::<GameAssets>()
|
.init_resource::<GameAssets>()
|
||||||
.add_systems(Startup, spawn_camera)
|
.add_systems(Startup, spawn_camera)
|
||||||
.add_systems(OnEnter(GameState::Playing), (spawn_player, spawn_ui))
|
.add_systems(OnEnter(GameState::Playing), (ship::spawn_player, spawn_ui))
|
||||||
.add_systems(
|
.add_systems(
|
||||||
FixedUpdate,
|
FixedUpdate,
|
||||||
(
|
(
|
||||||
@@ -85,9 +87,6 @@ struct Velocity(bevy::math::Vec2);
|
|||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Rotation(f32);
|
struct Rotation(f32);
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
struct Ship;
|
|
||||||
|
|
||||||
/// Marker for any entity that should wrap on screen edges
|
/// Marker for any entity that should wrap on screen edges
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Wrapping;
|
struct Wrapping;
|
||||||
@@ -188,31 +187,6 @@ fn spawn_camera(mut commands: Commands) {
|
|||||||
commands.spawn(Camera2d);
|
commands.spawn(Camera2d);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_player(mut commands: Commands, game_assets: Res<GameAssets>) {
|
|
||||||
commands
|
|
||||||
.spawn((
|
|
||||||
Collider::ball(0.7),
|
|
||||||
Sensor,
|
|
||||||
ActiveEvents::COLLISION_EVENTS,
|
|
||||||
ActiveCollisionTypes::STATIC_STATIC,
|
|
||||||
Ship,
|
|
||||||
Wrapping,
|
|
||||||
Position(Vec2::default()),
|
|
||||||
Velocity(Vec2::ZERO),
|
|
||||||
Rotation(0.0),
|
|
||||||
Mesh2d(game_assets.ship().0),
|
|
||||||
MeshMaterial2d(game_assets.ship().1),
|
|
||||||
Transform::default().with_scale(Vec3::new(20.0, 20.0, 20.0)),
|
|
||||||
))
|
|
||||||
.with_child((
|
|
||||||
Mesh2d(game_assets.thruster_mesh()),
|
|
||||||
MeshMaterial2d(game_assets.thruster_mat_inactive()),
|
|
||||||
Transform::default()
|
|
||||||
.with_scale(Vec3::splat(0.5))
|
|
||||||
.with_translation(Vec3::new(-0.5, 0.0, -0.1)),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Checks if "W" is pressed and increases velocity accordingly.
|
Checks if "W" is pressed and increases velocity accordingly.
|
||||||
*/
|
*/
|
||||||
|
|||||||
32
src/ship.rs
Normal file
32
src/ship.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
use bevy_rapier2d::prelude::*;
|
||||||
|
|
||||||
|
use crate::{GameAssets, Position, Rotation, Velocity, Wrapping};
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Ship;
|
||||||
|
|
||||||
|
pub fn spawn_player(mut commands: Commands, game_assets: Res<GameAssets>) {
|
||||||
|
commands
|
||||||
|
.spawn((
|
||||||
|
Collider::ball(0.7),
|
||||||
|
Sensor,
|
||||||
|
ActiveEvents::COLLISION_EVENTS,
|
||||||
|
ActiveCollisionTypes::STATIC_STATIC,
|
||||||
|
Ship,
|
||||||
|
Wrapping,
|
||||||
|
Position(Vec2::default()),
|
||||||
|
Velocity(Vec2::ZERO),
|
||||||
|
Rotation(0.0),
|
||||||
|
Mesh2d(game_assets.ship().0),
|
||||||
|
MeshMaterial2d(game_assets.ship().1),
|
||||||
|
Transform::default().with_scale(Vec3::new(20.0, 20.0, 20.0)),
|
||||||
|
))
|
||||||
|
.with_child((
|
||||||
|
Mesh2d(game_assets.thruster_mesh()),
|
||||||
|
MeshMaterial2d(game_assets.thruster_mat_inactive()),
|
||||||
|
Transform::default()
|
||||||
|
.with_scale(Vec3::splat(0.5))
|
||||||
|
.with_translation(Vec3::new(-0.5, 0.0, -0.1)),
|
||||||
|
));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user