SilverEmber 4 years ago
parent
commit
ebc4b431bb
  1. 12
      src/apr.rs
  2. 4
      src/board.rs
  3. 2
      src/main.rs

12
src/apr.rs

@ -27,8 +27,8 @@ pub fn make_grid(ctx: &mut Context, r: u8, c: u8, board: &[Vec<u8>]) -> GameResu
builder.rectangle( builder.rectangle(
DrawMode::fill(), DrawMode::fill(),
graphics::Rect { graphics::Rect {
x: board::START_X + (board::BOARD_SQUARE_SIZE * col as f32), x: board::START_X + (board::BOARD_SQUARE_SIZE * f32::from(col)),
y: board::START_Y + (board::BOARD_SQUARE_SIZE * row as f32), y: board::START_Y + (board::BOARD_SQUARE_SIZE * f32::from(row)),
w: board::BOARD_SQUARE_SIZE, w: board::BOARD_SQUARE_SIZE,
h: board::BOARD_SQUARE_SIZE, h: board::BOARD_SQUARE_SIZE,
}, },
@ -168,8 +168,8 @@ impl EventHandler for Apr {
if mouse::button_pressed(ctx, MouseButton::Left) && !self.dragging { if mouse::button_pressed(ctx, MouseButton::Left) && !self.dragging {
let (posx, posy) = self.board.closest_square_coords(posn.x, posn.y); let (posx, posy) = self.board.closest_square_coords(posn.x, posn.y);
if posx == x && posy == y { if posx == x && posy == y {
let x = board::START_X + board::BOARD_SQUARE_SIZE * (x as f32); let x = board::START_X + board::BOARD_SQUARE_SIZE * f32::from(x);
let y = board::START_Y + board::BOARD_SQUARE_SIZE * (y as f32); let y = board::START_Y + board::BOARD_SQUARE_SIZE * f32::from(y);
self.dragging = true; self.dragging = true;
actor.posn = actor::ActorPosn::FloatingPosn { actor.posn = actor::ActorPosn::FloatingPosn {
x, x,
@ -210,8 +210,8 @@ impl EventHandler for Apr {
ctx, ctx,
&actor.image, &actor.image,
drawparams.dest([ drawparams.dest([
board::START_X + board::BOARD_SQUARE_SIZE * (x as f32), board::START_X + board::BOARD_SQUARE_SIZE * f32::from(x),
board::START_Y + board::BOARD_SQUARE_SIZE * (y as f32), board::START_Y + board::BOARD_SQUARE_SIZE * f32::from(y),
]), ]),
)?, )?,
} }

4
src/board.rs

@ -27,11 +27,11 @@ impl Board {
//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 + (BOARD_SQUARE_SIZE * self.col as f32) - 1.0); x = x.min(START_X + (BOARD_SQUARE_SIZE * f32::from(self.col)) - 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 + (BOARD_SQUARE_SIZE * self.row as f32) - 1.0); y = y.min(START_Y + (BOARD_SQUARE_SIZE * f32::from(self.row)) - 1.0);
//Then, remove the start x and y //Then, remove the start x and y
x -= START_X; x -= START_X;

2
src/main.rs

@ -1,3 +1,5 @@
#![warn(clippy::cast_lossless)]
use ggez::event; use ggez::event;
use ggez::{ContextBuilder, GameResult}; use ggez::{ContextBuilder, GameResult};

Loading…
Cancel
Save