Skip to content

Commit

Permalink
Feature/outro (#40)
Browse files Browse the repository at this point in the history
* add outro to engine for desktop
* update engine interface in all implenentations
* wasm: use relative path to service-worker
  • Loading branch information
georgik authored Dec 23, 2022
1 parent 9581355 commit 2148a6e
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 246 deletions.
Binary file added assets/img/smiley.bmp
Binary file not shown.
17 changes: 8 additions & 9 deletions desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use embedded_graphics_framebuf::{FrameBuf};

use std::time::Duration;

use spooky_core::{ spritebuf::SpriteBuf, engine::Engine };
use spooky_core::{ spritebuf::SpriteBuf, engine::Engine, engine::Action::{ Up, Down, Left, Right, Teleport, PlaceDynamite } };

pub struct Universe<D> {
engine: Engine<D>,
Expand All @@ -34,38 +34,37 @@ impl <D:embedded_graphics::draw_target::DrawTarget<Color = Rgb565>> Universe <D>
}

pub fn move_up(&mut self) {
self.engine.move_up();
self.engine.action(Up);
}

pub fn move_down(&mut self) {
self.engine.move_down();
self.engine.action(Down);
}

pub fn move_left(&mut self) {
self.engine.move_left();
self.engine.action(Left);
}

pub fn move_right(&mut self) {
self.engine.move_right();
self.engine.action(Right);
}

pub fn teleport(&mut self) {
self.engine.teleport();
self.engine.action(Teleport);
}

pub fn initialize(&mut self) {
self.engine.initialize();
self.engine.start();
}

pub fn place_dynamite(&mut self) {
self.engine.place_dynamite();
self.engine.action(PlaceDynamite);
}

pub fn render_frame(&mut self) -> &D {
self.engine.tick();
self.engine.draw()
// display.flush().unwrap();

}
}

Expand Down
21 changes: 8 additions & 13 deletions esp-wrover-kit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ use embedded_graphics::{

#[cfg(feature = "esp32")]
use esp32_hal as hal;
#[cfg(feature = "esp32c3")]
use esp32c3_hal as hal;
#[cfg(feature = "esp32s2")]
use esp32s2_hal as hal;
#[cfg(feature = "esp32s3")]
use esp32s3_hal as hal;

use hal::{
clock::{ClockControl, CpuClock},
Expand All @@ -40,7 +34,7 @@ use xtensa_lx_rt::entry;

use embedded_graphics::pixelcolor::Rgb565;

use spooky_core::{engine::Engine, spritebuf::SpriteBuf};
use spooky_core::{engine::Engine, spritebuf::SpriteBuf, engine::Action::{ Up, Down, Left, Right, Teleport, PlaceDynamite }};

#[cfg(any(feature = "imu_controls"))]
use shared_bus::BusManagerSimple;
Expand All @@ -59,30 +53,31 @@ impl<D: embedded_graphics::draw_target::DrawTarget<Color = Rgb565>> Universe<D>

pub fn initialize(&mut self) {
self.engine.initialize();
self.engine.start();
}

pub fn move_up(&mut self) {
self.engine.move_up();
self.engine.action(Up);
}

pub fn move_down(&mut self) {
self.engine.move_down();
self.engine.action(Down);
}

pub fn move_left(&mut self) {
self.engine.move_left();
self.engine.action(Left);
}

pub fn move_right(&mut self) {
self.engine.move_right();
self.engine.action(Right);
}

pub fn teleport(&mut self) {
self.engine.teleport();
self.engine.action(Teleport);
}

pub fn place_dynamite(&mut self) {
self.engine.place_dynamite();
self.engine.action(PlaceDynamite);
}

pub fn render_frame(&mut self) -> &D {
Expand Down
20 changes: 8 additions & 12 deletions esp32-c3-devkit-rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use xtensa_lx_rt::entry;
use embedded_graphics::pixelcolor::Rgb565;
// use esp32s2_hal::Rng;

use spooky_core::{engine::Engine, spritebuf::SpriteBuf};
use spooky_core::{engine::Engine, spritebuf::SpriteBuf, engine::Action::{ Up, Down, Left, Right, Teleport, PlaceDynamite }};

#[cfg(any(feature = "imu_controls"))]
use icm42670::{accelerometer::Accelerometer, Address, Icm42670};
Expand All @@ -67,10 +67,7 @@ use embedded_hal::digital::v2::OutputPin;

pub struct Universe<I, D> {
pub engine: Engine<D>,
// #[cfg(any(feature = "imu_controls"))]
icm: I,
// icm: Option<Icm42670<shared_bus::I2cProxy<shared_bus::NullMutex<i2c::I2C<I2C0>>>>>
// delay: Some(Delay),
}

impl<I: Accelerometer, D: embedded_graphics::draw_target::DrawTarget<Color = Rgb565>>
Expand All @@ -79,14 +76,13 @@ impl<I: Accelerometer, D: embedded_graphics::draw_target::DrawTarget<Color = Rgb
pub fn new(icm: I, seed: Option<[u8; 32]>, engine: Engine<D>) -> Universe<I, D> {
Universe {
engine,
// #[cfg(any(feature = "imu_controls"))]
icm,
// delay: None,
}
}

pub fn initialize(&mut self) {
self.engine.initialize();
self.engine.start();
}

pub fn render_frame(&mut self) -> &D {
Expand All @@ -96,27 +92,27 @@ impl<I: Accelerometer, D: embedded_graphics::draw_target::DrawTarget<Color = Rgb
let accel_norm = self.icm.accel_norm().unwrap();

if accel_norm.y > accel_threshold {
self.engine.move_left();
self.engine.action(Left);
}

if accel_norm.y < -accel_threshold {
self.engine.move_right();
self.engine.action(Right);
}

if accel_norm.x > accel_threshold {
self.engine.move_down();
self.engine.action(Down);
}

if accel_norm.x < -accel_threshold {
self.engine.move_up();
self.engine.action(Up);
}

// Quickly move up to teleport
// Quickly move down to place dynamite
if accel_norm.z < -1.2 {
self.engine.teleport();
self.engine.action(Teleport);
} else if accel_norm.z > 1.5 {
self.engine.place_dynamite();
self.engine.action(PlaceDynamite);
}
}

Expand Down
22 changes: 10 additions & 12 deletions esp32-s2-kaluga/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ use riscv_rt::entry;
use embedded_graphics::{pixelcolor::Rgb565};
// use esp32s2_hal::Rng;

#[cfg(any(feature = "esp32s2_ili9341", feature = "esp32_wrover_kit", feature = "esp32c3_ili9341"))]
use ili9341::{DisplaySize240x320, Ili9341, Orientation};

use spooky_core::{spritebuf::SpriteBuf, engine::Engine};
use spooky_core::{spritebuf::SpriteBuf, engine::Engine, engine::Action::{ Up, Down, Left, Right, Teleport, PlaceDynamite }};

use embedded_hal::digital::v2::OutputPin;
use embedded_graphics_framebuf::{FrameBuf};
Expand All @@ -82,22 +79,23 @@ impl <D:embedded_graphics::draw_target::DrawTarget<Color = Rgb565>> Universe <D>

pub fn initialize(&mut self) {
self.engine.initialize();
self.engine.start();
}

pub fn move_up(&mut self) {
self.engine.move_up();
self.engine.action(Up);
}

pub fn move_down(&mut self) {
self.engine.move_down();
self.engine.action(Down);
}

pub fn move_left(&mut self) {
self.engine.move_left();
self.engine.action(Left);
}

pub fn move_right(&mut self) {
self.engine.move_right();
self.engine.action(Right);
}

pub fn render_frame(&mut self) -> &D {
Expand Down Expand Up @@ -205,13 +203,13 @@ fn main() -> ! {
let button_value: u16 = nb::block!(adc1.read(&mut button_ladder_pin)).unwrap();
// Based on https://github.com/espressif/esp-bsp/blob/master/esp32_s2_kaluga_kit/include/bsp/esp32_s2_kaluga_kit.h#L299
if button_value > 4000 && button_value < 5000 {
universe.engine.move_right();
universe.move_right();
} else if button_value >= 5000 && button_value < 6000 {
universe.engine.move_left();
universe.move_left();
} else if button_value >= 6000 && button_value < 7000 {
universe.engine.move_down();
universe.move_down();
} else if button_value >= 7000 && button_value < 8180 {
universe.engine.move_up();
universe.move_up();
}

display.draw_iter(universe.render_frame().into_iter()).unwrap();
Expand Down
28 changes: 17 additions & 11 deletions esp32-s2-usb-otg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ use riscv_rt::entry;
use embedded_graphics::{pixelcolor::Rgb565};
// use esp32s2_hal::Rng;

#[cfg(any(feature = "esp32s2_ili9341", feature = "esp32_wrover_kit", feature = "esp32c3_ili9341"))]
use ili9341::{DisplaySize240x320, Ili9341, Orientation};

use spooky_core::{spritebuf::SpriteBuf, engine::Engine};
use spooky_core::{spritebuf::SpriteBuf, engine::Engine, engine::Action::{ Up, Down, Left, Right, Teleport, PlaceDynamite }};

use embedded_hal::digital::v2::OutputPin;
use embedded_graphics_framebuf::{FrameBuf};
Expand All @@ -75,22 +72,31 @@ impl <D:embedded_graphics::draw_target::DrawTarget<Color = Rgb565>> Universe <D>

pub fn initialize(&mut self) {
self.engine.initialize();
self.engine.start()
}

pub fn move_up(&mut self) {
self.engine.move_up();
self.engine.action(Up);
}

pub fn move_down(&mut self) {
self.engine.move_down();
self.engine.action(Down);
}

pub fn move_left(&mut self) {
self.engine.move_left();
self.engine.action(Left);
}

pub fn move_right(&mut self) {
self.engine.move_right();
self.engine.action(Right);
}

pub fn teleport(&mut self) {
self.engine.action(Teleport);
}

pub fn place_dynamite(&mut self) {
self.engine.action(PlaceDynamite);
}

pub fn render_frame(&mut self) -> &D {
Expand Down Expand Up @@ -243,11 +249,11 @@ fn main() -> ! {
let button_menu = button_menu_pin.is_low().unwrap();

if button_up && button_down {
universe.engine.teleport();
universe.teleport();
} else if button_menu && button_ok {
universe.engine.place_dynamite();
universe.place_dynamite();
} else if button_down {
universe.engine.move_down();
universe.move_down();
} else if button_up {
universe.move_up();
} else if button_menu {
Expand Down
Loading

0 comments on commit 2148a6e

Please sign in to comment.