head database for aim and ai
This commit is contained in:
10
src/npc.rs
10
src/npc.rs
@@ -2,10 +2,10 @@ use crate::{
|
||||
GameState,
|
||||
ai::Ai,
|
||||
head::ActiveHead,
|
||||
head_asset::HeadsDatabase,
|
||||
heads::{HEAD_COUNT, HeadState},
|
||||
hitpoints::{Hitpoints, Kill},
|
||||
keys::KeySpawn,
|
||||
player::head_id_to_str,
|
||||
tb_entities::EnemySpawn,
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
@@ -19,18 +19,20 @@ pub fn plugin(app: &mut App) {
|
||||
app.add_systems(OnEnter(GameState::Playing), init);
|
||||
}
|
||||
|
||||
fn init(mut commands: Commands, query: Query<(Entity, &EnemySpawn)>) {
|
||||
fn init(mut commands: Commands, query: Query<(Entity, &EnemySpawn)>, heads_db: Res<HeadsDatabase>) {
|
||||
//TODO: move into HeadsDatabase
|
||||
let mut names: HashMap<String, usize> = HashMap::default();
|
||||
for i in 0..HEAD_COUNT {
|
||||
names.insert(head_id_to_str(i).to_string(), i);
|
||||
names.insert(heads_db.head_key(i).to_string(), i);
|
||||
}
|
||||
|
||||
for (e, spawn) in query.iter() {
|
||||
let id = names[&spawn.head];
|
||||
commands
|
||||
.entity(e)
|
||||
.insert((
|
||||
Hitpoints::new(100),
|
||||
Npc(HeadState::new(id, 10).with_ability(crate::abilities::HeadAbility::Thrown)),
|
||||
Npc(HeadState::new(id, 10)),
|
||||
ActiveHead(id),
|
||||
Ai,
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user