mirror of
https://github.com/pcvolkmer/winelounge.git
synced 2025-04-19 18:36:50 +00:00
Code cleanup
This commit is contained in:
parent
96cb88610b
commit
b3253490b9
31
src/world.rs
31
src/world.rs
@ -66,9 +66,9 @@ impl World {
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Up));
|
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Up));
|
||||||
if self.collides_with_stop() || !self.player.within_rect(&Self::playable_rect()) {
|
if self.collides() {
|
||||||
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Down));
|
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Down));
|
||||||
self.execute_command(Command::FacePlayer(player_id.clone(), Direction::Up));
|
self.execute_command(Command::FacePlayer(player_id, Direction::Up));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::KeyDown {
|
Event::KeyDown {
|
||||||
@ -76,9 +76,9 @@ impl World {
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Down));
|
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Down));
|
||||||
if self.collides_with_stop() || !self.player.within_rect(&Self::playable_rect()) {
|
if self.collides() {
|
||||||
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Up));
|
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Up));
|
||||||
self.execute_command(Command::FacePlayer(player_id.clone(), Direction::Down));
|
self.execute_command(Command::FacePlayer(player_id, Direction::Down));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::KeyDown {
|
Event::KeyDown {
|
||||||
@ -86,9 +86,9 @@ impl World {
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Left));
|
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Left));
|
||||||
if self.collides_with_stop() || !self.player.within_rect(&Self::playable_rect()) {
|
if self.collides() {
|
||||||
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Right));
|
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Right));
|
||||||
self.execute_command(Command::FacePlayer(player_id.clone(), Direction::Left));
|
self.execute_command(Command::FacePlayer(player_id, Direction::Left));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::KeyDown {
|
Event::KeyDown {
|
||||||
@ -96,27 +96,25 @@ impl World {
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Right));
|
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Right));
|
||||||
if self.collides_with_stop() || !self.player.within_rect(&Self::playable_rect()) {
|
if self.collides() {
|
||||||
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Left));
|
self.execute_command(Command::MovePlayer(player_id.clone(), Direction::Left));
|
||||||
self.execute_command(Command::FacePlayer(player_id.clone(), Direction::Right));
|
self.execute_command(Command::FacePlayer(player_id, Direction::Right));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::KeyUp { .. } => self.execute_command(Command::StopPlayer(player_id.clone())),
|
Event::KeyUp { .. } => self.execute_command(Command::StopPlayer(player_id)),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn collides(&mut self) -> bool {
|
||||||
|
self.collides_with_stop() || !self.player.within_rect(&Self::playable_rect())
|
||||||
|
}
|
||||||
|
|
||||||
/// Executes a command for world update.
|
/// Executes a command for world update.
|
||||||
pub fn execute_command(&mut self, command: Command) {
|
pub fn execute_command(&mut self, command: Command) {
|
||||||
debug!("{}", command);
|
debug!("{}", command);
|
||||||
|
|
||||||
match command {
|
match command {
|
||||||
Command::SpawnPlayer(player_id, x, y) => &mut {
|
|
||||||
// TBD
|
|
||||||
},
|
|
||||||
Command::RemovePlayer(player_id) => &mut {
|
|
||||||
// TBD
|
|
||||||
},
|
|
||||||
Command::FacePlayer(player_id, Direction::Down) => {
|
Command::FacePlayer(player_id, Direction::Down) => {
|
||||||
&mut self.get_player(player_id).face_down()
|
&mut self.get_player(player_id).face_down()
|
||||||
},
|
},
|
||||||
@ -163,7 +161,8 @@ impl World {
|
|||||||
self.right_top_box_area.last_update = chrono::Utc::now().timestamp();
|
self.right_top_box_area.last_update = chrono::Utc::now().timestamp();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
|
_ => unimplemented!()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user