Skip to content

[Chapter 70] Missing text for fire_on_target #233

@PierreGuyot

Description

@PierreGuyot

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions