Browse Source

fixed unneeded as conversions

master
e-dt 4 years ago
parent
commit
0264e4234b
  1. 12
      src/apr.rs
  2. 4
      src/board.rs
  3. 4
      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(
DrawMode::fill(),
graphics::Rect {
x: board::START_X + (board::BOARD_SQUARE_SIZE * col as f32),
y: board::START_Y + (board::BOARD_SQUARE_SIZE * row as f32),
x: board::START_X + (board::BOARD_SQUARE_SIZE * f32::from(col)),
y: board::START_Y + (board::BOARD_SQUARE_SIZE * f32::from(row)),
w: board::BOARD_SQUARE_SIZE,
h: board::BOARD_SQUARE_SIZE,
},
@ -144,8 +144,8 @@ impl EventHandler for Apr {
if mouse::button_pressed(ctx, MouseButton::Left) && !self.dragging {
let (posx, posy) = self.board.closest_square_coords(posn.x, posn.y);
if posx == x && posy == y {
let x = board::START_X + board::BOARD_SQUARE_SIZE * (x as f32);
let y = board::START_Y + board::BOARD_SQUARE_SIZE * (y as f32);
let x = board::START_X + board::BOARD_SQUARE_SIZE * f32::from(x);
let y = board::START_Y + board::BOARD_SQUARE_SIZE * f32::from(y);
self.dragging = true;
actor.posn = actor::ActorPosn::FloatingPosn {
x,
@ -186,8 +186,8 @@ impl EventHandler for Apr {
ctx,
&actor.image,
drawparams.dest([
board::START_X + board::BOARD_SQUARE_SIZE * (x as f32),
board::START_Y + board::BOARD_SQUARE_SIZE * (y as f32),
board::START_X + board::BOARD_SQUARE_SIZE * f32::from(x),
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.
let mut x = 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;
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
x -= START_X;

4
src/main.rs

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

Loading…
Cancel
Save