e-dt 4 years ago
parent
commit
100fee78ec
  1. 18
      src/main.rs

18
src/main.rs

@ -8,7 +8,7 @@ use std::path;
const START_X: f32 = 20.0; const START_X: f32 = 20.0;
const START_Y: f32 = 20.0; const START_Y: f32 = 20.0;
const SIZE: f32 = 20.0; const BOARD_SQUARE_SIZE: f32 = 20.0;
struct Apr { struct Apr {
row: i32, row: i32,
@ -36,10 +36,10 @@ fn make_grid(ctx: &mut Context, r: i32, c: i32, board: &[Vec<u8>]) -> GameResult
builder.rectangle( builder.rectangle(
DrawMode::fill(), DrawMode::fill(),
graphics::Rect { graphics::Rect {
x: START_X + (SIZE * col as f32), x: START_X + (BOARD_SQUARE_SIZE * col as f32),
y: START_Y + (SIZE * row as f32), y: START_Y + (BOARD_SQUARE_SIZE * row as f32),
w: SIZE, w: BOARD_SQUARE_SIZE,
h: SIZE, h: BOARD_SQUARE_SIZE,
}, },
match board[row as usize][col as usize] { match board[row as usize][col as usize] {
0 => Color::WHITE, 0 => Color::WHITE,
@ -100,16 +100,16 @@ impl Apr {
//First, normalise to within the grid. //First, normalise to within the grid.
let mut x = x; let mut x = x;
x = x.max(START_X); x = x.max(START_X);
x = x.min(START_X + (SIZE * self.col as f32) - 1.0); x = x.min(START_X + (BOARD_SQUARE_SIZE * self.col as f32) - 1.0);
let mut y = y; let mut y = y;
y = y.max(START_Y); y = y.max(START_Y);
y = y.min(START_Y + (SIZE * self.row as f32) - 1.0); y = y.min(START_Y + (BOARD_SQUARE_SIZE * self.row as f32) - 1.0);
//Then, snap to top left. //Then, snap to top left.
x = (x / SIZE).trunc() * SIZE; x = (x / BOARD_SQUARE_SIZE).trunc() * BOARD_SQUARE_SIZE;
y = (y / SIZE).trunc() * SIZE; y = (y / BOARD_SQUARE_SIZE).trunc() * BOARD_SQUARE_SIZE;
(x, y) (x, y)
} }

Loading…
Cancel
Save