This commit is contained in:
Crispy 2024-10-12 23:27:28 +02:00
parent 27ff77f133
commit ed956ffbe4
5 changed files with 22 additions and 20 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 B

After

Width:  |  Height:  |  Size: 168 B

View file

@ -76,6 +76,7 @@ impl Machine {
zoom: i32, zoom: i32,
) { ) {
let tile_size = 16 << zoom; let tile_size = 16 << zoom;
let scale = (1 << zoom) as f32;
for marble in &self.marbles { for marble in &self.marbles {
let x = marble.x; let x = marble.x;
let y = marble.y; let y = marble.y;
@ -83,11 +84,10 @@ impl Machine {
let px = x as i32 * tile_size + offset.x as i32; let px = x as i32 * tile_size + offset.x as i32;
let py = y as i32 * tile_size + offset.y as i32; let py = y as i32 * tile_size + offset.y as i32;
if let Tile::Marble { value, dir } = tile { if let Tile::Marble { value, dir } = tile {
let scale = 1 << zoom;
let texture = textures.get(dir.arrow_texture_name()); let texture = textures.get(dir.arrow_texture_name());
let pos = Vector2::new(px as f32, py as f32); let pos = Vector2::new(px as f32, py as f32);
let faded = Color::new(255, 255, 255, 100); let faded_white = Color::new(255, 255, 255, 100);
d.draw_texture_ex(texture, pos, 0., scale as f32, faded); d.draw_texture_ex(texture, pos, 0., scale, faded_white);
draw_usize_small(d, textures, value as usize, px, py, scale); draw_usize_small(d, textures, value as usize, px, py, scale);
} }
} }

View file

@ -232,6 +232,7 @@ impl Board {
pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, zoom: i32) { pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, zoom: i32) {
let tile_size = 16 << zoom; let tile_size = 16 << zoom;
let scale = (1 << zoom) as f32;
let start_x = (-offset.x as i32) / tile_size - 1; let start_x = (-offset.x as i32) / tile_size - 1;
let tile_width = d.get_screen_width() / tile_size + 2; let tile_width = d.get_screen_width() / tile_size + 2;
@ -240,18 +241,15 @@ impl Board {
for x in start_x..(start_x + tile_width) { for x in start_x..(start_x + tile_width) {
for y in start_y..(start_y + tile_height) { for y in start_y..(start_y + tile_height) {
let tx = x as usize;
let ty = y as usize;
let px = x * tile_size + offset.x as i32; let px = x * tile_size + offset.x as i32;
let py = y * tile_size + offset.y as i32; let py = y * tile_size + offset.y as i32;
if self.in_bounds((tx, ty).into()) { if let Some(tile) = self.get((x, y).into()) {
let tile = self.rows[ty][tx];
let texname = tile.texture(); let texname = tile.texture();
if texname.is_empty() { if texname.is_empty() {
continue; continue;
} }
let texture = textures.get(&texname); let texture = textures.get(&texname);
draw_scaled_texture(d, texture, px, py, (1 << zoom) as f32); draw_scaled_texture(d, texture, px, py, scale);
} else { } else {
d.draw_rectangle(px, py, tile_size, tile_size, Color::new(0, 0, 0, 80)); d.draw_rectangle(px, py, tile_size, tile_size, Color::new(0, 0, 0, 80));
} }

View file

@ -40,6 +40,15 @@ impl From<(usize, usize)> for Pos {
} }
} }
impl From<(i32, i32)> for Pos {
fn from(value: (i32, i32)) -> Self {
Self {
x: value.0 as isize,
y: value.1 as isize,
}
}
}
impl From<Vector2> for Pos { impl From<Vector2> for Pos {
fn from(vec: Vector2) -> Self { fn from(vec: Vector2) -> Self {
Self { Self {

View file

@ -224,26 +224,21 @@ pub fn draw_usize_small(
mut num: usize, mut num: usize,
mut x: i32, mut x: i32,
y: i32, y: i32,
scale: u8, scale: f32,
) { ) {
const MAX_DIGITS: usize = 8; const MAX_DIGITS: usize = 8;
let mut digits = [0u8; MAX_DIGITS]; let mut digits = [0; MAX_DIGITS];
let mut i = 0; let mut i = 0;
while (num != 0 || i == 0) && i < MAX_DIGITS { while (num != 0 || i == 0) && i < MAX_DIGITS {
digits[MAX_DIGITS - i - 1] = (num % 10) as u8; digits[MAX_DIGITS - i - 1] = num % 10;
num /= 10; num /= 10;
i += 1; i += 1;
} }
let texture = textures.get("digits_small"); let texture = textures.get("digits_small");
for digit in (MAX_DIGITS - i)..MAX_DIGITS { for &digit in &digits[(MAX_DIGITS - i)..] {
d.draw_texture_pro( let source = Rectangle::new(4. * digit as f32, 0., 4., 6.);
texture, let dest = Rectangle::new(x as f32, y as f32, 4. * scale, 6. * scale);
Rectangle::new(4. * digits[digit] as f32, 0., 4., 6.), d.draw_texture_pro(texture, source, dest, Vector2::zero(), 0., Color::RED);
Rectangle::new(x as f32, y as f32, 4. * scale as f32, 6. * scale as f32),
Vector2::zero(),
0.,
Color::RED,
);
x += 4 * scale as i32; x += 4 * scale as i32;
} }
} }