diff --git a/design/v0.txt b/design/v0.txt index 69aee6c..5f59a6e 100644 --- a/design/v0.txt +++ b/design/v0.txt @@ -29,9 +29,9 @@ Single-char ║ ☰ 𜱟 🮴 Documents ■ (with background) - 🮴 Downloads ⬕ blah.json + 🮴 Downloads ⬕ blah.json - 🮴 Applications 🮴 Zomboid + 🮴 Applications 🮴 Zomboid diff --git a/src/game.rs b/src/game.rs index 0302dd4..20e0fb9 100644 --- a/src/game.rs +++ b/src/game.rs @@ -10,6 +10,34 @@ pub struct GameModel { room: Room, } +pub enum GameEvent { + Quit, + Nop, + MovePlayer(V2), +} + +impl GameEvent { + fn from_crossterm(event: Event) -> Self { + if let Event::Key(key_event) = event { + use KeyCode::Char; + match key_event.code { + Char('q') => return GameEvent::Quit, + Char('j') => return GameEvent::MovePlayer(V2::new(0, 1)), + Char('k') => return GameEvent::MovePlayer(V2::new(0, -1)), + Char('h') => return GameEvent::MovePlayer(V2::new(-1, 0)), + Char('l') => return GameEvent::MovePlayer(V2::new(1, 0)), + Char('J') => return GameEvent::MovePlayer(V2::new(0, 2)), + Char('K') => return GameEvent::MovePlayer(V2::new(0, -2)), + Char('H') => return GameEvent::MovePlayer(V2::new(-2, 0)), + Char('L') => return GameEvent::MovePlayer(V2::new(2, 0)), + _ => (), + } + } + + GameEvent::Nop + } +} + struct Room { size: V2, } @@ -25,39 +53,14 @@ impl GameModel { } pub fn update(self, event: Event) -> Option { - match event { - Event::Key(key_event) => match key_event.code { - KeyCode::Char('q') => return None, - KeyCode::Char('j') => { - return Some(Self { - player_pos: self.player_pos + V2::new(0, 1), - ..self - }) - }, - KeyCode::Char('k') => { - return Some(Self { - player_pos: self.player_pos + V2::new(0, -1), - ..self - }) - }, - KeyCode::Char('h') => { - return Some(Self { - player_pos: self.player_pos + V2::new(-1, 0), - ..self - }) - }, - KeyCode::Char('l') => { - return Some(Self { - player_pos: self.player_pos + V2::new(1, 0), - ..self - }) - }, - _ => (), - }, - _ => (), + match GameEvent::from_crossterm(event) { + GameEvent::Quit => None, + GameEvent::Nop => Some(self), + GameEvent::MovePlayer(direction) => Some(Self { + player_pos: self.player_pos + direction, + ..self + }), } - - Some(self) } pub fn render(&self, frame: &mut Frame) { @@ -117,6 +120,7 @@ impl Tile { cell.set_symbol("⚱").set_fg(Color::LightRed); } Tile::Frog => { + // Alternative symbol: Ö̶͈ cell.set_symbol("ä̃").set_fg(Color::Green); } }