diff --git a/book/src/chapter_2.md b/book/src/chapter_2.md index 97b956df..248ce47a 100644 --- a/book/src/chapter_2.md +++ b/book/src/chapter_2.md @@ -547,9 +547,9 @@ Now we implement a new function, `try_move_player`: ```rust fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) { let mut positions = ecs.write_storage::(); - let mut players = ecs.write_storage::(); + let players = ecs.read_storage::(); - for (_player, pos) in (&mut players, &mut positions).join() { + for (_player, pos) in (&players, &mut positions).join() { pos.x = min(79 , max(0, pos.x + delta_x)); pos.y = min(49, max(0, pos.y + delta_y)); } @@ -561,7 +561,7 @@ Drawing on our previous experience, we can see that this gains write access to ` We'll add a second function to read the keyboard information provided by RLTK: ```rust -fn player_input(gs: &mut State, ctx: &mut Rltk) { +fn player_input(gs: &mut State, ctx: &Rltk) { // Player movement match ctx.key { None => {} // Nothing happened diff --git a/chapter-02-helloecs/src/main.rs b/chapter-02-helloecs/src/main.rs index 6d036183..0743eaba 100644 --- a/chapter-02-helloecs/src/main.rs +++ b/chapter-02-helloecs/src/main.rs @@ -28,15 +28,15 @@ struct State { fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) { let mut positions = ecs.write_storage::(); - let mut players = ecs.write_storage::(); + let players = ecs.read_storage::(); - for (_player, pos) in (&mut players, &mut positions).join() { + for (_player, pos) in (&players, &mut positions).join() { pos.x = min(79 , max(0, pos.x + delta_x)); pos.y = min(49, max(0, pos.y + delta_y)); } } -fn player_input(gs: &mut State, ctx: &mut Rltk) { +fn player_input(gs: &mut State, ctx: &Rltk) { // Player movement match ctx.key { None => {} // Nothing happened