Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawn Enemies #112

Merged
merged 5 commits into from
Nov 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
spawn indicators on update
thombruce committed Nov 18, 2023
commit 5dd1e5527fe16b7b5a3845d5ed0a5c9c0ab1c8cd
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Decrease static orbit scale (planets are now closer)
- Clamp orbit distance (prevents Moon orbiting inside of Earth sprite)
- Indicators spawn on update allowing new entities to be pointed to

## [0.0.25] - 2023-11-17

1 change: 1 addition & 0 deletions src/systems/mod.rs
Original file line number Diff line number Diff line change
@@ -182,6 +182,7 @@ impl Plugin for SystemsPlugin {
enemy::spawn_enemies,
ship::bullet_timers_system,
dynamic_orbit::dynamic_orbital_positioning_system,
hud::indicator::spawn_indicator_children.before(hud::indicator::indicators_system),
hud::indicator::indicators_system,
hud::speedometer::hud_speedometer,
hud::health::hud_health,
51 changes: 31 additions & 20 deletions src/ui/hud/indicator.rs
Original file line number Diff line number Diff line change
@@ -15,29 +15,39 @@ pub struct Indicator {
#[derive(Component, Clone, Debug)]
pub struct Bounds {}

pub(crate) fn spawn_indicators(
#[derive(Component, Clone, Debug)]
pub struct IndicatorsContainer;

pub(crate) fn spawn_indicators(mut commands: Commands) {
commands.spawn((
NodeBundle {
style: Style {
position_type: PositionType::Absolute,
width: Val::Percent(100.0),
height: Val::Percent(100.0),
..default()
},
..default()
},
Name::new("Indicators"),
Bounds {},
IndicatorsContainer,
));
}

pub(crate) fn spawn_indicator_children(
mut commands: Commands,
asset_server: Res<AssetServer>,
entities_query: Query<(Entity, &Indicated)>,
parent: Query<Entity, With<IndicatorsContainer>>,
indicators: Query<&Indicator>,
) {
commands
.spawn((
NodeBundle {
style: Style {
position_type: PositionType::Absolute,
width: Val::Percent(100.0),
height: Val::Percent(100.0),
..default()
},
..default()
},
Name::new("Indicators"),
Bounds {},
))
.with_children(|parent| {
// TODO: Spawn indicators when new enemies spawn
// TODO: Spawn indicators when in range, despawn when out of range
for (entity, indicated) in entities_query.iter() {
let parent = parent.get_single().unwrap();

commands.entity(parent).with_children(|parent| {
// TODO: Spawn indicators when in range, despawn when out of range
for (entity, indicated) in entities_query.iter() {
if !indicators.iter().any(|i| i.entity == entity) {
parent.spawn((
ImageBundle {
image: UiImage::new(asset_server.load("images/grey_arrowUpWhite.png")),
@@ -53,7 +63,8 @@ pub(crate) fn spawn_indicators(
Indicator { entity: entity },
));
}
});
}
});
}

pub(crate) fn indicators_system(