Browse Source

Fixed a bug

master
e-dt 4 years ago
parent
commit
eb372464c0
  1. 8
      src/main.rs

8
src/main.rs

@ -123,20 +123,20 @@ impl EventHandler for Apr {
self.set_colour(r, c, (self.board[r][c] + 1) % 8)?; self.set_colour(r, c, (self.board[r][c] + 1) % 8)?;
self.__TEST_state += 1; self.__TEST_state += 1;
} }
let posn = mouse::position(ctx);
if self.__test_pawn_held { if self.__test_pawn_held {
if !mouse::button_pressed(ctx, MouseButton::Left) { // no long clicking and dragging if !mouse::button_pressed(ctx, MouseButton::Left) { // no long clicking and dragging
let (x, y) = self.closest_square_coords(self.__test_pawn_x, self.__test_pawn_y); let (x, y) = self.closest_square_coords(posn.x, posn.y);
self.__test_pawn_x = x; self.__test_pawn_x = x;
self.__test_pawn_y = y; self.__test_pawn_y = y;
self.__test_pawn_held = false;
} else { } else {
let posn = mouse::position(ctx);
self.__test_pawn_x = posn.x + self.__test_pawn_h_x; self.__test_pawn_x = posn.x + self.__test_pawn_h_x;
self.__test_pawn_y = posn.y + self.__test_pawn_h_y; self.__test_pawn_y = posn.y + self.__test_pawn_h_y;
} }
} else { } else {
if mouse::button_pressed(ctx, MouseButton::Left) { if mouse::button_pressed(ctx, MouseButton::Left) {
let posn = mouse::position(ctx);
let posx = posn.x; let posx = posn.x;
let posy = posn.y; let posy = posn.y;
if posx >= self.__test_pawn_x && posx <= self.__test_pawn_x + 20.0 && posy >= self.__test_pawn_y && posy <= self.__test_pawn_y + 20.0 { //In real game don't hardcode size if posx >= self.__test_pawn_x && posx <= self.__test_pawn_x + 20.0 && posy >= self.__test_pawn_y && posy <= self.__test_pawn_y + 20.0 { //In real game don't hardcode size

Loading…
Cancel
Save