Skip to content

Commit

Permalink
reward player on enemy destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
thombruce committed Nov 18, 2023
1 parent 63a9b4b commit 6c5760b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add game score that increases when player damages enemy
- Add game score that increases when player damages or destroys an enemy

### Changed

Expand Down
15 changes: 11 additions & 4 deletions src/ships/ship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,21 @@ pub(crate) fn ship_damage(
commands.entity(event.bullet).despawn();

if let Ok(mut health) = ship.get_mut(event.ship) {
if let Ok(player) = player.get_single() {
if event.bullet_spawner == player {
score.0 += 100;
}
let Ok(player) = player.get_single() else {
return;
};

if event.bullet_spawner == player {
score.0 += 100;
}

health.0 -= 100.0;
if health.0 <= 0. {
// If the destroyed ship is not the player, award XP to the player
if !(event.ship == player) {
score.0 += 1000; // TODO: Make proportionate to player-dealt damage relative to MaxHealth
}

commands.entity(event.ship).despawn();
}
}
Expand Down

0 comments on commit 6c5760b

Please sign in to comment.