Skip to content

Commit

Permalink
推箱子完成xsb格式解析
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleGuest committed May 13, 2024
1 parent 2b64b7a commit 6fef225
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 176 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@

## 三方库

- https://github.com/smart-leds-rs/smart-leds-matrix.git,修改了部分源码
- https://github.com/smart-leds-rs/ws2812-spi-rs,修改了部分源码
4 changes: 1 addition & 3 deletions cube/src/cube_man.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//! 是方块人就下一百层
//!
use alloc::{collections::VecDeque, vec::Vec};
use cube_rand::CubeRng;
use embassy_time::Timer;
Expand All @@ -15,6 +12,7 @@ use log::{debug, info};

use crate::{App, Gd, Position, RNG};

/// 是方块人就下一百层
#[derive(Debug)]
pub struct CubeManGame {
man: CubeMan,
Expand Down
26 changes: 5 additions & 21 deletions cube/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use snake::SnakeGame;
use timers::Timers;
use ui::Ui;

use crate::sokoban::Sokoban;

#[macro_use]
extern crate alloc;

Expand All @@ -49,12 +51,6 @@ mod sokoban;
mod timers;
mod ui;

// lazy_static::lazy_static! {
// static ref App:App<'d>={};
// static ref LC: LEDC<'d>={};
// pub static ref Io:IO=IO::new(gpio, io_mux);
// }

pub static mut RNG: MaybeUninit<Rng> = MaybeUninit::uninit();

struct PositionVec(Vec<Position>);
Expand Down Expand Up @@ -148,13 +144,6 @@ impl From<&Position> for Pixel<Rgb888> {
}
}

// impl FromIterator<Position> for Iterator<Item = Pixel<Rgb888>> {}
// impl From<Vec<Position>> for Vec<Pixel<Rgb888>> {
// fn from(value: Vec<Position>) -> Self {
// todo!()
// }
// }

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Direction {
Up,
Expand Down Expand Up @@ -235,34 +224,27 @@ where
let ax = accel.x();
let ay = accel.y();

// let ax_abs = ax.abs();
// let ay_abs = ay.abs();
let ax_abs = if ax <= 0.0 { 0.0 - ax } else { ax };
let ay_abs = if ay <= 0.0 { 0.0 - ay } else { ay };
if ax_abs > 0.5 || ay_abs > 0.5 {
if ax_abs > ay_abs {
if ax < -0.5 {
// self.ledc.gd = Gd::Right;
self.gd = Gd::Right;
}
if ax > 0.5 {
// self.ledc.gd = Gd::Left;
self.gd = Gd::Left;
}
}

if ax_abs < ay_abs {
if ay < -0.5 {
// self.ledc.gd = Gd::Up;
self.gd = Gd::Up;
}
if ay > 0.5 {
// self.ledc.gd = Gd::Down;
self.gd = Gd::Down;
}
}
} else {
// self.ledc.gd = Gd::None;
self.gd = Gd::None;
}
}
Expand Down Expand Up @@ -345,7 +327,9 @@ where
flash_data[0x01] = cm.highest;
flash.write(flash_addr, &flash_data).ok();
}
Ui::Sokoban => {}
Ui::Sokoban => {
Sokoban::new().run(&mut self).await;
}
Ui::Sound => {}
},
Gd::Right => {
Expand Down
4 changes: 1 addition & 3 deletions cube/src/maze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Maze {
impl Maze {
pub fn new(width: usize, height: usize) -> Self {
let map = MazeMap::new(width, height);
// 随机玩家坐标
// FIXME: 随机玩家坐标,这里可能导致起始位置较近,后续使用路径算法生成
let pp = loop {
let pp = Position::random_range_usize(1..width, 1..height);
let md = map.data[pp.x as usize][pp.y as usize];
Expand All @@ -39,7 +39,6 @@ impl Maze {
if player.pos.x - 3 <= 0 {
0
} else if player.pos.x + 5 >= width as i32 {
// W as i8 - 8 + (W as i8 - player.pos.x) - 1
player.pos.x - 8 + width as i32 - player.pos.x
} else {
player.pos.x - 3
Expand All @@ -49,7 +48,6 @@ impl Maze {
if player.pos.y - 3 <= 0 {
0
} else if player.pos.y + 5 >= height as i32 {
// H as i8 - 8 + (H as i8 - player.pos.y) - 1
player.pos.y - 8 + height as i32 - player.pos.y
} else {
player.pos.y - 3
Expand Down
Loading

0 comments on commit 6fef225

Please sign in to comment.