Move Asteroid components to the objects.rs mod
This commit is contained in:
@@ -8,29 +8,9 @@ use std::time::Duration;
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::ASTEROID_LIFETIME, events::{AsteroidDestroy, SpawnAsteroid}, physics::Velocity, GameAssets, Lifetime, WorldSize
|
config::ASTEROID_LIFETIME, events::{AsteroidDestroy, SpawnAsteroid}, objects::{Asteroid, AsteroidSize}, physics::Velocity, GameAssets, Lifetime, WorldSize
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Component, Deref, DerefMut)]
|
|
||||||
pub struct Asteroid(AsteroidSize);
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub enum AsteroidSize {
|
|
||||||
Small,
|
|
||||||
Medium,
|
|
||||||
Large,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsteroidSize {
|
|
||||||
fn next(&self) -> Option<Self> {
|
|
||||||
match self {
|
|
||||||
AsteroidSize::Small => None,
|
|
||||||
AsteroidSize::Medium => Some(AsteroidSize::Small),
|
|
||||||
AsteroidSize::Large => Some(AsteroidSize::Medium),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct AsteroidSpawner {
|
pub struct AsteroidSpawner {
|
||||||
rng: std::sync::Mutex<rand::rngs::StdRng>,
|
rng: std::sync::Mutex<rand::rngs::StdRng>,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::asteroids::AsteroidSize;
|
use crate::objects::AsteroidSize;
|
||||||
|
|
||||||
/// Signals that the player's ship has been destroyed.
|
/// Signals that the player's ship has been destroyed.
|
||||||
/// Used when the player collides with an asteroid.
|
/// Used when the player collides with an asteroid.
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
mod asteroids;
|
mod asteroids;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
mod events;
|
mod events;
|
||||||
|
mod objects;
|
||||||
mod physics;
|
mod physics;
|
||||||
mod preparation_widget;
|
mod preparation_widget;
|
||||||
mod ship;
|
mod ship;
|
||||||
mod title_screen;
|
mod title_screen;
|
||||||
|
|
||||||
use crate::asteroids::{Asteroid, AsteroidSpawner};
|
use crate::asteroids::{AsteroidSpawner};
|
||||||
use crate::config::{
|
use crate::config::{
|
||||||
ASTEROID_SMALL_COLOR, BACKGROUND_COLOR, BULLET_COLOR, BULLET_LIFETIME, BULLET_SPEED,
|
ASTEROID_SMALL_COLOR, BACKGROUND_COLOR, BULLET_COLOR, BULLET_LIFETIME, BULLET_SPEED,
|
||||||
PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, SHIP_THRUSTER_COLOR_ACTIVE,
|
PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, SHIP_THRUSTER_COLOR_ACTIVE,
|
||||||
SHIP_THRUSTER_COLOR_INACTIVE, WINDOW_SIZE,
|
SHIP_THRUSTER_COLOR_INACTIVE, WINDOW_SIZE,
|
||||||
};
|
};
|
||||||
|
use crate::objects::Asteroid;
|
||||||
use crate::physics::AngularVelocity;
|
use crate::physics::AngularVelocity;
|
||||||
use crate::ship::{Bullet, Ship};
|
use crate::ship::{Bullet, Ship};
|
||||||
|
|
||||||
|
|||||||
25
src/objects.rs
Normal file
25
src/objects.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
//! This module contains all the "things" in the game.
|
||||||
|
//!
|
||||||
|
//! Asteroids, the player's ship, and such.
|
||||||
|
|
||||||
|
use bevy::{ecs::component::Component, prelude::{Deref, DerefMut}};
|
||||||
|
|
||||||
|
#[derive(Component, Deref, DerefMut)]
|
||||||
|
pub struct Asteroid(pub AsteroidSize);
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub enum AsteroidSize {
|
||||||
|
Small,
|
||||||
|
Medium,
|
||||||
|
Large,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsteroidSize {
|
||||||
|
pub fn next(&self) -> Option<Self> {
|
||||||
|
match self {
|
||||||
|
AsteroidSize::Small => None,
|
||||||
|
AsteroidSize::Medium => Some(AsteroidSize::Small),
|
||||||
|
AsteroidSize::Large => Some(AsteroidSize::Medium),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
AngularVelocity, GameAssets, GameState, Lives,
|
AngularVelocity, GameAssets, GameState, Lives,
|
||||||
asteroids::Asteroid,
|
objects::Asteroid,
|
||||||
events::{BulletDestroy, ShipDestroy},
|
events::{BulletDestroy, ShipDestroy},
|
||||||
physics::{Velocity, Wrapping},
|
physics::{Velocity, Wrapping},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user