Fix render

This commit is contained in:
eraden 2024-10-01 05:31:59 +02:00
parent ffde674b89
commit 14b63b5ad3
4 changed files with 23 additions and 15 deletions

View File

@ -105,23 +105,25 @@ impl App for MazeGame {
Button::Up if self.map.can_move(self.player_pos(), Direction::North) => {
self.player.y -= 1;
self.old_player = Some(player_old);
Some(Action::PartialRender)
}
Button::Down if self.map.can_move(self.player_pos(), Direction::South) => {
self.player.y += 1;
self.old_player = Some(player_old);
Some(Action::PartialRender)
}
Button::Left if self.map.can_move(self.player_pos(), Direction::West) => {
self.player.x -= 1;
self.old_player = Some(player_old);
Some(Action::PartialRender)
}
Button::Right if self.map.can_move(self.player_pos(), Direction::East) => {
self.player.x += 1;
self.old_player = Some(player_old);
Some(Action::PartialRender)
}
Button::Back => return Some(Action::GoToMenu),
_ => {}
_ => None,
}
None
}
}

View File

@ -52,13 +52,13 @@ impl App for Menu {
MenuEntry::Labirynth => return None,
MenuEntry::Pairs => {
self.selected = MenuEntry::Labirynth;
None
Some(Action::Render)
}
},
Button::Down => match self.selected {
MenuEntry::Labirynth => {
self.selected = MenuEntry::Pairs;
None
Some(Action::Render)
}
MenuEntry::Pairs => None,
},

View File

@ -21,6 +21,8 @@ pub enum Action {
GoToMenu,
StartMaze,
StartPairs,
Render,
PartialRender,
}
pub enum Application {
@ -35,8 +37,10 @@ impl Default for Application {
}
impl Application {
pub fn draw(&self, ctx: &mut Context) {
ctx.epaper.full_erase();
pub fn draw(&self, ctx: &mut Context, full: bool) {
if full {
ctx.epaper.full_erase();
}
match self {
Self::Menu(menu) => menu.draw(ctx),
Self::Maze(maze) => maze.draw(ctx),
@ -58,17 +62,22 @@ impl Application {
let mut maze = MazeGame::new();
maze.start(trng);
*self = Application::Maze(maze);
self.draw(ctx);
self.draw(ctx, true);
}
Action::GoToMenu => {
let mut menu = Menu::new();
menu.start(trng);
*self = Application::Menu(menu);
self.draw(ctx);
self.draw(ctx, true);
}
Action::StartPairs => {}
Action::Render => {
self.draw(ctx, true);
}
Action::PartialRender => {
self.draw(ctx, false);
}
};
self.draw(ctx);
}
}

View File

@ -93,7 +93,7 @@ fn main() -> ! {
let mut app = Application::default();
let mut trng = Trng::new(peripherals.RNG, peripherals.ADC1);
app.draw(&mut ctx);
app.draw(&mut ctx, true);
app.update_and_draw(&mut ctx, &mut trng);
// ctx.epaper.sleep();
@ -102,13 +102,10 @@ fn main() -> ! {
ctx.button_pressed = kbd.pressed();
if !ctx.button_pressed.is_none() {
log::info!("Wake up!");
// ctx.epaper.wake_up();
app.update_and_draw(&mut ctx, &mut trng);
}
// log::info!("Sleeping for 100ms...");
//driver.sleep().unwrap();
delay.delay(300.millis());
delay.delay(100.millis());
}
}