Fix render
This commit is contained in:
parent
ffde674b89
commit
14b63b5ad3
@ -105,23 +105,25 @@ impl App for MazeGame {
|
|||||||
Button::Up if self.map.can_move(self.player_pos(), Direction::North) => {
|
Button::Up if self.map.can_move(self.player_pos(), Direction::North) => {
|
||||||
self.player.y -= 1;
|
self.player.y -= 1;
|
||||||
self.old_player = Some(player_old);
|
self.old_player = Some(player_old);
|
||||||
|
Some(Action::PartialRender)
|
||||||
}
|
}
|
||||||
Button::Down if self.map.can_move(self.player_pos(), Direction::South) => {
|
Button::Down if self.map.can_move(self.player_pos(), Direction::South) => {
|
||||||
self.player.y += 1;
|
self.player.y += 1;
|
||||||
self.old_player = Some(player_old);
|
self.old_player = Some(player_old);
|
||||||
|
Some(Action::PartialRender)
|
||||||
}
|
}
|
||||||
Button::Left if self.map.can_move(self.player_pos(), Direction::West) => {
|
Button::Left if self.map.can_move(self.player_pos(), Direction::West) => {
|
||||||
self.player.x -= 1;
|
self.player.x -= 1;
|
||||||
self.old_player = Some(player_old);
|
self.old_player = Some(player_old);
|
||||||
|
Some(Action::PartialRender)
|
||||||
}
|
}
|
||||||
Button::Right if self.map.can_move(self.player_pos(), Direction::East) => {
|
Button::Right if self.map.can_move(self.player_pos(), Direction::East) => {
|
||||||
self.player.x += 1;
|
self.player.x += 1;
|
||||||
self.old_player = Some(player_old);
|
self.old_player = Some(player_old);
|
||||||
|
Some(Action::PartialRender)
|
||||||
}
|
}
|
||||||
Button::Back => return Some(Action::GoToMenu),
|
Button::Back => return Some(Action::GoToMenu),
|
||||||
_ => {}
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,13 +52,13 @@ impl App for Menu {
|
|||||||
MenuEntry::Labirynth => return None,
|
MenuEntry::Labirynth => return None,
|
||||||
MenuEntry::Pairs => {
|
MenuEntry::Pairs => {
|
||||||
self.selected = MenuEntry::Labirynth;
|
self.selected = MenuEntry::Labirynth;
|
||||||
None
|
Some(Action::Render)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Button::Down => match self.selected {
|
Button::Down => match self.selected {
|
||||||
MenuEntry::Labirynth => {
|
MenuEntry::Labirynth => {
|
||||||
self.selected = MenuEntry::Pairs;
|
self.selected = MenuEntry::Pairs;
|
||||||
None
|
Some(Action::Render)
|
||||||
}
|
}
|
||||||
MenuEntry::Pairs => None,
|
MenuEntry::Pairs => None,
|
||||||
},
|
},
|
||||||
|
@ -21,6 +21,8 @@ pub enum Action {
|
|||||||
GoToMenu,
|
GoToMenu,
|
||||||
StartMaze,
|
StartMaze,
|
||||||
StartPairs,
|
StartPairs,
|
||||||
|
Render,
|
||||||
|
PartialRender,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Application {
|
pub enum Application {
|
||||||
@ -35,8 +37,10 @@ impl Default for Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Application {
|
impl Application {
|
||||||
pub fn draw(&self, ctx: &mut Context) {
|
pub fn draw(&self, ctx: &mut Context, full: bool) {
|
||||||
ctx.epaper.full_erase();
|
if full {
|
||||||
|
ctx.epaper.full_erase();
|
||||||
|
}
|
||||||
match self {
|
match self {
|
||||||
Self::Menu(menu) => menu.draw(ctx),
|
Self::Menu(menu) => menu.draw(ctx),
|
||||||
Self::Maze(maze) => maze.draw(ctx),
|
Self::Maze(maze) => maze.draw(ctx),
|
||||||
@ -58,17 +62,22 @@ impl Application {
|
|||||||
let mut maze = MazeGame::new();
|
let mut maze = MazeGame::new();
|
||||||
maze.start(trng);
|
maze.start(trng);
|
||||||
*self = Application::Maze(maze);
|
*self = Application::Maze(maze);
|
||||||
self.draw(ctx);
|
self.draw(ctx, true);
|
||||||
}
|
}
|
||||||
Action::GoToMenu => {
|
Action::GoToMenu => {
|
||||||
let mut menu = Menu::new();
|
let mut menu = Menu::new();
|
||||||
menu.start(trng);
|
menu.start(trng);
|
||||||
*self = Application::Menu(menu);
|
*self = Application::Menu(menu);
|
||||||
self.draw(ctx);
|
self.draw(ctx, true);
|
||||||
}
|
}
|
||||||
Action::StartPairs => {}
|
Action::StartPairs => {}
|
||||||
|
Action::Render => {
|
||||||
|
self.draw(ctx, true);
|
||||||
|
}
|
||||||
|
Action::PartialRender => {
|
||||||
|
self.draw(ctx, false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
self.draw(ctx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ fn main() -> ! {
|
|||||||
let mut app = Application::default();
|
let mut app = Application::default();
|
||||||
let mut trng = Trng::new(peripherals.RNG, peripherals.ADC1);
|
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);
|
app.update_and_draw(&mut ctx, &mut trng);
|
||||||
|
|
||||||
// ctx.epaper.sleep();
|
// ctx.epaper.sleep();
|
||||||
@ -102,13 +102,10 @@ fn main() -> ! {
|
|||||||
ctx.button_pressed = kbd.pressed();
|
ctx.button_pressed = kbd.pressed();
|
||||||
if !ctx.button_pressed.is_none() {
|
if !ctx.button_pressed.is_none() {
|
||||||
log::info!("Wake up!");
|
log::info!("Wake up!");
|
||||||
// ctx.epaper.wake_up();
|
|
||||||
app.update_and_draw(&mut ctx, &mut trng);
|
app.update_and_draw(&mut ctx, &mut trng);
|
||||||
}
|
}
|
||||||
|
|
||||||
// log::info!("Sleeping for 100ms...");
|
delay.delay(100.millis());
|
||||||
//driver.sleep().unwrap();
|
|
||||||
delay.delay(300.millis());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user