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