Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions book/src/chapter_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Position>();
let mut players = ecs.write_storage::<Player>();
let players = ecs.read_storage::<Player>();

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));
}
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions chapter-02-helloecs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Position>();
let mut players = ecs.write_storage::<Player>();
let players = ecs.read_storage::<Player>();

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
Expand Down