different ammo per head (#30)

This commit is contained in:
extrawurst
2025-04-18 19:21:11 +02:00
committed by GitHub
parent 68ea17a93a
commit 94cd9c9cc4
7 changed files with 36 additions and 21 deletions

View File

@@ -77,7 +77,7 @@ fn update(
t.translation,
t.rotation,
t.forward(),
&ShapeCastConfig::from_max_distance(80.),
&ShapeCastConfig::from_max_distance(150.),
&filter,
) {
cmds.entity(first_hit.entity).trigger(Hit { damage: 50 });

View File

@@ -4,6 +4,7 @@ mod ui_head_state;
use crate::{
GameState,
heads::{HEAD_COUNT, HeadState},
heads_database::HeadsDatabase,
};
use bevy::prelude::*;
@@ -36,10 +37,10 @@ pub fn plugin(app: &mut App) {
app.add_systems(OnEnter(GameState::Playing), setup);
}
fn setup(mut commands: Commands) {
fn setup(mut commands: Commands, heads: Res<HeadsDatabase>) {
commands.insert_resource(Backpack {
heads: (0usize..HEAD_COUNT)
.map(|i| HeadState::new(i, 10))
.map(|i| HeadState::new(i, heads.as_ref()))
.collect(),
});
}

View File

@@ -31,7 +31,8 @@ pub struct HeadState {
}
impl HeadState {
pub fn new(head: usize, ammo: u32) -> Self {
pub fn new(head: usize, heads_db: &HeadsDatabase) -> Self {
let ammo = heads_db.head_stats(head).ammo;
Self {
head,
health: 100,

View File

@@ -20,6 +20,12 @@ pub struct HeadStats {
pub controls: HeadControls,
#[serde(default)]
pub projectile: String,
#[serde(default = "default_ammo")]
pub ammo: u32,
}
fn default_ammo() -> u32 {
10
}
#[derive(Debug, Asset, Reflect, Serialize, Deserialize)]

View File

@@ -34,7 +34,13 @@ fn init(mut commands: Commands, query: Query<(Entity, &EnemySpawn)>, heads_db: R
Hitpoints::new(100),
Npc,
ActiveHead(id),
ActiveHeads::new([Some(HeadState::new(id, 10)), None, None, None, None]),
ActiveHeads::new([
Some(HeadState::new(id, heads_db.as_ref())),
None,
None,
None,
None,
]),
Ai,
))
.observe(on_kill);

View File

@@ -57,6 +57,7 @@ fn spawn(
asset_server: Res<AssetServer>,
query: Query<&Transform, With<SpawnPoint>>,
assets: Res<GameAssets>,
heads_db: Res<HeadsDatabase>,
) {
let Some(spawn) = query.iter().next() else {
return;
@@ -76,11 +77,11 @@ fn spawn(
Player,
ActiveHead(0),
ActiveHeads::new([
Some(HeadState::new(0, 10)),
Some(HeadState::new(3, 10)),
Some(HeadState::new(6, 10)),
Some(HeadState::new(10, 10)),
Some(HeadState::new(9, 10)),
Some(HeadState::new(0, heads_db.as_ref())),
Some(HeadState::new(3, heads_db.as_ref())),
Some(HeadState::new(6, heads_db.as_ref())),
Some(HeadState::new(10, heads_db.as_ref())),
Some(HeadState::new(9, heads_db.as_ref())),
]),
Hitpoints::new(100),
CameraTarget,