cleanup
This commit is contained in:
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 |
|
@ -76,6 +76,7 @@ impl Machine {
|
|||
zoom: i32,
|
||||
) {
|
||||
let tile_size = 16 << zoom;
|
||||
let scale = (1 << zoom) as f32;
|
||||
for marble in &self.marbles {
|
||||
let x = marble.x;
|
||||
let y = marble.y;
|
||||
|
@ -83,11 +84,10 @@ impl Machine {
|
|||
let px = x as i32 * tile_size + offset.x as i32;
|
||||
let py = y as i32 * tile_size + offset.y as i32;
|
||||
if let Tile::Marble { value, dir } = tile {
|
||||
let scale = 1 << zoom;
|
||||
let texture = textures.get(dir.arrow_texture_name());
|
||||
let pos = Vector2::new(px as f32, py as f32);
|
||||
let faded = Color::new(255, 255, 255, 100);
|
||||
d.draw_texture_ex(texture, pos, 0., scale as f32, faded);
|
||||
let faded_white = Color::new(255, 255, 255, 100);
|
||||
d.draw_texture_ex(texture, pos, 0., scale, faded_white);
|
||||
draw_usize_small(d, textures, value as usize, px, py, scale);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -232,6 +232,7 @@ impl Board {
|
|||
|
||||
pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, zoom: i32) {
|
||||
let tile_size = 16 << zoom;
|
||||
let scale = (1 << zoom) as f32;
|
||||
|
||||
let start_x = (-offset.x as i32) / tile_size - 1;
|
||||
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 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 py = y * tile_size + offset.y as i32;
|
||||
if self.in_bounds((tx, ty).into()) {
|
||||
let tile = self.rows[ty][tx];
|
||||
if let Some(tile) = self.get((x, y).into()) {
|
||||
let texname = tile.texture();
|
||||
if texname.is_empty() {
|
||||
continue;
|
||||
}
|
||||
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 {
|
||||
d.draw_rectangle(px, py, tile_size, tile_size, Color::new(0, 0, 0, 80));
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
fn from(vec: Vector2) -> Self {
|
||||
Self {
|
||||
|
|
19
src/util.rs
19
src/util.rs
|
@ -224,26 +224,21 @@ pub fn draw_usize_small(
|
|||
mut num: usize,
|
||||
mut x: i32,
|
||||
y: i32,
|
||||
scale: u8,
|
||||
scale: f32,
|
||||
) {
|
||||
const MAX_DIGITS: usize = 8;
|
||||
let mut digits = [0u8; MAX_DIGITS];
|
||||
let mut digits = [0; MAX_DIGITS];
|
||||
let mut i = 0;
|
||||
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;
|
||||
i += 1;
|
||||
}
|
||||
let texture = textures.get("digits_small");
|
||||
for digit in (MAX_DIGITS - i)..MAX_DIGITS {
|
||||
d.draw_texture_pro(
|
||||
texture,
|
||||
Rectangle::new(4. * digits[digit] as f32, 0., 4., 6.),
|
||||
Rectangle::new(x as f32, y as f32, 4. * scale as f32, 6. * scale as f32),
|
||||
Vector2::zero(),
|
||||
0.,
|
||||
Color::RED,
|
||||
);
|
||||
for &digit in &digits[(MAX_DIGITS - i)..] {
|
||||
let source = Rectangle::new(4. * digit as f32, 0., 4., 6.);
|
||||
let dest = Rectangle::new(x as f32, y as f32, 4. * scale, 6. * scale);
|
||||
d.draw_texture_pro(texture, source, dest, Vector2::zero(), 0., Color::RED);
|
||||
x += 4 * scale as i32;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue