Browse Source

shut up the paperclip

master
e-dt 4 years ago
parent
commit
e51e7d8290
  1. 36
      src/main.rs

36
src/main.rs

@ -17,7 +17,7 @@ struct Apr {
grid: Mesh,
should_update_grid: bool,
// Your state here...
__TEST_state: usize,
__test_state: usize,
//These would go in a dedicated Actor struct in the real game.
__test_pawn_image: graphics::Image,
@ -61,9 +61,9 @@ fn make_grid(ctx: &mut Context, r: i32, c: i32, board: &[Vec<u8>]) -> GameResult
fn make_board(r: i32, c: i32) -> Vec<Vec<u8>> {
let mut init : Vec<Vec<u8>> = vec![vec![0u8; r as usize]; c as usize];
for row in 0..r as usize {
for col in 0..c as usize {
init[row][col] = (row + col) as u8 % 8;
for (row, rowa) in init.iter_mut().enumerate() {
for (col, item) in rowa.iter_mut().enumerate() {
*item = (row + col) as u8 % 8;
}
}
init
@ -77,9 +77,9 @@ impl Apr {
row: r,
col: c,
grid: make_grid(_ctx, r, c, board.as_slice())?,
board: board,
board,
should_update_grid: false,
__TEST_state: 0,
__test_state: 0,
__test_pawn_image: graphics::Image::new(_ctx, "/pawn.png")?,
__test_pawn_x: 20.0,
@ -118,10 +118,10 @@ impl Apr {
impl EventHandler for Apr {
fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
for _x in 0..self.col {
let c = self.__TEST_state % self.col as usize;
let r = (self.__TEST_state / self.row as usize) % self.row as usize;
let c = self.__test_state % self.col as usize;
let r = (self.__test_state / self.row as usize) % self.row as usize;
self.set_colour(r, c, (self.board[r][c] + 1) % 8)?;
self.__TEST_state += 1;
self.__test_state += 1;
}
let posn = mouse::position(ctx);
@ -135,18 +135,16 @@ impl EventHandler for Apr {
self.__test_pawn_x = posn.x + self.__test_pawn_h_x;
self.__test_pawn_y = posn.y + self.__test_pawn_h_y;
}
} else {
if mouse::button_pressed(ctx, MouseButton::Left) {
let posx = posn.x;
let posy = posn.y;
if posx >= self.__test_pawn_x && posx <= self.__test_pawn_x + BOARD_SQUARE_SIZE && posy >= self.__test_pawn_y && posy <= self.__test_pawn_y + BOARD_SQUARE_SIZE {
self.__test_pawn_h_x = self.__test_pawn_x - posx;
self.__test_pawn_h_y = self.__test_pawn_y - posy;
} else if mouse::button_pressed(ctx, MouseButton::Left) {
let posx = posn.x;
let posy = posn.y;
if posx >= self.__test_pawn_x && posx <= self.__test_pawn_x + BOARD_SQUARE_SIZE && posy >= self.__test_pawn_y && posy <= self.__test_pawn_y + BOARD_SQUARE_SIZE {
self.__test_pawn_h_x = self.__test_pawn_x - posx;
self.__test_pawn_h_y = self.__test_pawn_y - posy;
self.__test_pawn_held = true;
}
} else {
self.set_colour(((self.__test_pawn_y - START_Y) / BOARD_SQUARE_SIZE) as usize, ((self.__test_pawn_x - START_X) / BOARD_SQUARE_SIZE) as usize, 3)?;
}
} else {
self.set_colour(((self.__test_pawn_y - START_Y) / BOARD_SQUARE_SIZE) as usize, ((self.__test_pawn_x - START_X) / BOARD_SQUARE_SIZE) as usize, 3)?;
}
Ok(())

Loading…
Cancel
Save