fix marbles not working in negative quadrants
This commit is contained in:
parent
70d7256e9d
commit
4c976ab8e2
3 changed files with 46 additions and 36 deletions
|
@ -6,5 +6,6 @@
|
|||
"is_sandbox": true,
|
||||
"init_board": null,
|
||||
"inputs": [],
|
||||
"outputs": []
|
||||
"outputs": [],
|
||||
"input_is_text": true
|
||||
}
|
|
@ -35,14 +35,7 @@ impl Machine {
|
|||
}
|
||||
|
||||
pub fn set_board(&mut self, board: Board) {
|
||||
self.marbles.clear();
|
||||
for y in 0..board.height() {
|
||||
for x in 0..board.width() {
|
||||
if let Some(Tile::Marble { value: _, dir: _ }) = board.get((x, y).into()) {
|
||||
self.marbles.push((x, y).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
self.marbles = board.get_marbles();
|
||||
self.board = board;
|
||||
}
|
||||
|
||||
|
@ -73,33 +66,33 @@ impl Machine {
|
|||
|
||||
pub fn draw_marble_values(&self, d: &mut RaylibDrawHandle, offset: Vector2, zoom: i32) {
|
||||
let tile_size = 16 << zoom;
|
||||
for x in 0..self.board.width() {
|
||||
for y in 0..self.board.height() {
|
||||
if let Some(tile) = self.board.get((x, y).into()) {
|
||||
let px = x as i32 * tile_size + offset.x as i32 + tile_size / 2;
|
||||
let py = y as i32 * tile_size + offset.y as i32 + tile_size / 2;
|
||||
if let Tile::Marble { value, dir } = tile {
|
||||
let fontsize = (zoom + 1) * 10;
|
||||
d.draw_text(
|
||||
&format!("{value}"),
|
||||
px - tile_size / 2 + 2,
|
||||
py - tile_size / 2 + 2,
|
||||
fontsize,
|
||||
Color::MAGENTA,
|
||||
);
|
||||
d.draw_text(
|
||||
match dir {
|
||||
Direction::Up => "^",
|
||||
Direction::Down => "v",
|
||||
Direction::Left => "<",
|
||||
Direction::Right => ">",
|
||||
},
|
||||
px - tile_size / 2 + 2,
|
||||
py - tile_size / 2 + fontsize,
|
||||
fontsize,
|
||||
Color::MAGENTA,
|
||||
);
|
||||
}
|
||||
for marble in &self.marbles {
|
||||
let x = marble.x;
|
||||
let y = marble.y;
|
||||
if let Some(tile) = self.board.get(*marble) {
|
||||
let px = x as i32 * tile_size + offset.x as i32 + tile_size / 2;
|
||||
let py = y as i32 * tile_size + offset.y as i32 + tile_size / 2;
|
||||
if let Tile::Marble { value, dir } = tile {
|
||||
let fontsize = (zoom + 1) * 10;
|
||||
d.draw_text(
|
||||
&format!("{value}"),
|
||||
px - tile_size / 2 + 2,
|
||||
py - tile_size / 2 + 2,
|
||||
fontsize,
|
||||
Color::MAGENTA,
|
||||
);
|
||||
d.draw_text(
|
||||
match dir {
|
||||
Direction::Up => "^",
|
||||
Direction::Down => "v",
|
||||
Direction::Left => "<",
|
||||
Direction::Right => ">",
|
||||
},
|
||||
px - tile_size / 2 + 2,
|
||||
py - tile_size / 2 + fontsize,
|
||||
fontsize,
|
||||
Color::MAGENTA,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,6 +283,22 @@ impl Board {
|
|||
self.height
|
||||
}
|
||||
|
||||
pub fn get_marbles(&self) -> Vec<Pos> {
|
||||
let mut out = Vec::new();
|
||||
for y in 0..self.height {
|
||||
for x in 0..self.width {
|
||||
if let Tile::Marble { value: _, dir: _ } = self.rows[y][x] {
|
||||
out.push(Pos {
|
||||
x: x as isize - self.offset_x,
|
||||
y: y as isize - self.offset_y,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
dbg!(&out);
|
||||
out
|
||||
}
|
||||
|
||||
pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, zoom: i32) {
|
||||
let tile_size = 16 << zoom;
|
||||
|
||||
|
|
Loading…
Reference in a new issue