|
|
|
@ -19,12 +19,11 @@ fn main() {
|
|
|
|
file_path: "assets".into(),
|
|
|
|
file_path: "assets".into(),
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
.init_resource::<Coordinates>()
|
|
|
|
.init_resource::<NextCoordinates>()
|
|
|
|
.init_resource::<CellAssets>()
|
|
|
|
.init_resource::<CellAssets>()
|
|
|
|
.init_resource::<Panning>()
|
|
|
|
.init_resource::<Panning>()
|
|
|
|
.init_state::<SimulationPlayback>()
|
|
|
|
.init_state::<SimulationPlayback>()
|
|
|
|
.init_state::<AudioPlayback>()
|
|
|
|
.init_state::<AudioPlayback>()
|
|
|
|
.insert_resource(GlobalVolume::new(Volume::Linear(1.0)))
|
|
|
|
|
|
|
|
.add_message::<Lifecycle>()
|
|
|
|
.add_message::<Lifecycle>()
|
|
|
|
.add_systems(Startup, setup)
|
|
|
|
.add_systems(Startup, setup)
|
|
|
|
.add_systems(Startup, load_audio_tones)
|
|
|
|
.add_systems(Startup, load_audio_tones)
|
|
|
|
@ -249,7 +248,10 @@ fn setup(mut commands: Commands) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Hash, Eq, Component, Resource)]
|
|
|
|
#[derive(Default, Debug, Resource)]
|
|
|
|
|
|
|
|
struct NextCoordinates(Coordinates);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Hash, Eq, Component)]
|
|
|
|
#[require(Visibility, Transform)]
|
|
|
|
#[require(Visibility, Transform)]
|
|
|
|
struct Coordinates {
|
|
|
|
struct Coordinates {
|
|
|
|
x: isize,
|
|
|
|
x: isize,
|
|
|
|
@ -375,23 +377,23 @@ fn on_add_coordinates(
|
|
|
|
|
|
|
|
|
|
|
|
/// When the cursor moves, update the Coordiantes
|
|
|
|
/// When the cursor moves, update the Coordiantes
|
|
|
|
fn update_grid_position(
|
|
|
|
fn update_grid_position(
|
|
|
|
mut coordinates: ResMut<Coordinates>,
|
|
|
|
mut coordinates: ResMut<NextCoordinates>,
|
|
|
|
q_window: Single<&Window>,
|
|
|
|
q_window: Single<&Window>,
|
|
|
|
q_camera: Single<(&Camera, &GlobalTransform)>,
|
|
|
|
q_camera: Single<(&Camera, &GlobalTransform)>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
if let Some(cursor_pos) = q_window.cursor_position() {
|
|
|
|
if let Some(cursor_pos) = q_window.cursor_position() {
|
|
|
|
let (cam, cam_gt) = *q_camera;
|
|
|
|
let (cam, cam_gt) = *q_camera;
|
|
|
|
if let Ok(pos) = cam.viewport_to_world_2d(cam_gt, cursor_pos) {
|
|
|
|
if let Ok(pos) = cam.viewport_to_world_2d(cam_gt, cursor_pos) {
|
|
|
|
coordinates.x = (pos / SCALE).round().x as isize;
|
|
|
|
coordinates.0.x = (pos / SCALE).round().x as isize;
|
|
|
|
coordinates.y = (pos / SCALE).round().y as isize;
|
|
|
|
coordinates.0.y = (pos / SCALE).round().y as isize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Draw a gizmo at the current coordiantes
|
|
|
|
/// Draw a gizmo at the current coordiantes
|
|
|
|
fn grid_gizmo(mut gizmos: Gizmos, coordinates: Res<Coordinates>) {
|
|
|
|
fn grid_gizmo(mut gizmos: Gizmos, coordinates: Res<NextCoordinates>) {
|
|
|
|
let isometry = Isometry2d {
|
|
|
|
let isometry = Isometry2d {
|
|
|
|
translation: coordinates.as_translation().truncate(),
|
|
|
|
translation: coordinates.0.as_translation().truncate(),
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
gizmos.rect_2d(isometry, Vec2::ONE * SCALE, PURPLE)
|
|
|
|
gizmos.rect_2d(isometry, Vec2::ONE * SCALE, PURPLE)
|
|
|
|
@ -402,17 +404,17 @@ struct Cell;
|
|
|
|
|
|
|
|
|
|
|
|
// When left mouse clicked, spawn a cell at GridPosition
|
|
|
|
// When left mouse clicked, spawn a cell at GridPosition
|
|
|
|
fn de_spawn_cells(
|
|
|
|
fn de_spawn_cells(
|
|
|
|
coordinates: Res<Coordinates>,
|
|
|
|
coordinates: Res<NextCoordinates>,
|
|
|
|
cells: Query<(Entity, &Coordinates), With<Cell>>,
|
|
|
|
cells: Query<(Entity, &Coordinates), With<Cell>>,
|
|
|
|
mut lifecycle: MessageWriter<Lifecycle>,
|
|
|
|
mut lifecycle: MessageWriter<Lifecycle>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
if let Some(e) = cells
|
|
|
|
if let Some(e) = cells
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.find_map(|(e, c)| (*coordinates == *c).then_some(e))
|
|
|
|
.find_map(|(e, c)| (coordinates.0 == *c).then_some(e))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lifecycle.write(Lifecycle::Dead(e));
|
|
|
|
lifecycle.write(Lifecycle::Dead(e));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
lifecycle.write(Lifecycle::Alive(coordinates.clone()));
|
|
|
|
lifecycle.write(Lifecycle::Alive(coordinates.0.clone()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|