draw marble direction

This commit is contained in:
Crispy 2024-10-05 20:48:05 +02:00
parent fc6c66ff31
commit 682dff48f9
2 changed files with 19 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 B

After

Width:  |  Height:  |  Size: 176 B

View file

@ -70,14 +70,27 @@ impl Machine {
if let Some(tile) = self.board.get((x, y).into()) { 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 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; let py = y as i32 * tile_size + offset.y as i32 + tile_size / 2;
if let Tile::Marble { value, dir: _ } = tile { if let Tile::Marble { value, dir } = tile {
let fontsize = (zoom + 1) * 10;
d.draw_text( d.draw_text(
&format!("{value}"), &format!("{value}"),
px - tile_size / 2 + 2, px - tile_size / 2 + 2,
py - tile_size / 2 + 2, py - tile_size / 2 + 2,
20, fontsize,
Color::MAGENTA, 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,
);
} }
} }
} }
@ -114,9 +127,7 @@ impl Machine {
new_tile = Some(Tile::Blank); new_tile = Some(Tile::Blank);
} }
Tile::Digit(d) => { Tile::Digit(d) => {
let new_val = value let new_val = value.wrapping_mul(10).wrapping_add(*d as MarbleValue);
.wrapping_mul(10)
.wrapping_add(*d as MarbleValue);
*target = Tile::Marble { *target = Tile::Marble {
value: new_val, value: new_val,
dir, dir,
@ -258,7 +269,7 @@ impl Machine {
|| !self.board.get_or_blank(pos_b).is_blank()) || !self.board.get_or_blank(pos_b).is_blank())
&& self.board.get_or_blank(front_pos).is_blank() && self.board.get_or_blank(front_pos).is_blank()
{ {
let result = match op { let value = match op {
MathOp::Add => val_a.wrapping_add(val_b), MathOp::Add => val_a.wrapping_add(val_b),
MathOp::Sub => val_a.wrapping_sub(val_b), MathOp::Sub => val_a.wrapping_sub(val_b),
MathOp::Mul => val_a.wrapping_mul(val_b), MathOp::Mul => val_a.wrapping_mul(val_b),
@ -266,7 +277,7 @@ impl Machine {
MathOp::Rem => val_a.checked_rem(val_b).unwrap_or_default(), MathOp::Rem => val_a.checked_rem(val_b).unwrap_or_default(),
}; };
// println!("{op:?} a:{val_a} b:{val_b}"); // println!("{op:?} a:{val_a} b:{val_b}");
*self.board.get_mut_unchecked(front_pos) = Tile::Marble { value: result, dir }; *self.board.get_mut_unchecked(front_pos) = Tile::Marble { value, dir };
self.marbles.push(front_pos); self.marbles.push(front_pos);
} }
} }
@ -314,4 +325,3 @@ impl Machine {
} }
} }
} }