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

Loading…
Cancel
Save