-
Notifications
You must be signed in to change notification settings - Fork 164
Open
Description
rustrogueliketutorial/chapter-70-missiles/src/player.rs
Lines 54 to 80 in 33872fe
fn fire_on_target(ecs: &mut World) -> RunState { | |
let targets = ecs.write_storage::<Target>(); | |
let entities = ecs.entities(); | |
let mut current_target : Option<Entity> = None; | |
let mut log = ecs.fetch_mut::<GameLog>(); | |
for (e,_t) in (&entities, &targets).join() { | |
current_target = Some(e); | |
} | |
if let Some(target) = current_target { | |
let player_entity = ecs.fetch::<Entity>(); | |
let mut shoot_store = ecs.write_storage::<WantsToShoot>(); | |
let names = ecs.read_storage::<Name>(); | |
if let Some(name) = names.get(target) { | |
log.entries.push(format!("You fire at {}", name.name)); | |
} | |
shoot_store.insert(*player_entity, WantsToShoot{ target }).expect("Insert Fail"); | |
RunState::Ticking | |
} else { | |
log.entries.push("You don't have a target selected!".to_string()); | |
RunState::AwaitingInput | |
} | |
} |
https://github.com/amethyst/rustrogueliketutorial/blob/master/chapter-70-missiles/src/player.rs#L482
The chapter 70 forgets to add the fire_on_target
function and to call it from player.rs
(to fire with the F
key). The code for it is in the repo, but not mentioned in the book.
Metadata
Metadata
Assignees
Labels
No labels