|
|
@ -36,7 +36,6 @@ pub fn make_grid(ctx: &mut Context, r: u8, c: u8, board: &[Vec<u8>]) -> GameResu |
|
|
|
0 => Color::WHITE, |
|
|
|
1 => Color::BLACK, |
|
|
|
_ => Color::BLACK, //impossible
|
|
|
|
//2 => Color::RED, 3 => Color::CYAN, 4 => Color::YELLOW, 5 => Color::GREEN, 6 => Color::BLUE, 7 => Color::MAGENTA, _ => Color::BLACK,
|
|
|
|
}, |
|
|
|
)?; |
|
|
|
} |
|
|
@ -58,29 +57,22 @@ impl Apr { |
|
|
|
} |
|
|
|
Ok(Apr { |
|
|
|
grid: make_grid(_ctx, r, c, board.board.as_slice())?, |
|
|
|
board: board, |
|
|
|
board, |
|
|
|
should_update_grid: false, |
|
|
|
|
|
|
|
/*actors: vec![actor::Actor {
|
|
|
|
image: graphics::Image::new(_ctx, "/pawn.png")?, |
|
|
|
posn: actor::ActorPosn::BoardPosn { x: 0, y: 0 }, |
|
|
|
behaviour: 0, |
|
|
|
}],*/ |
|
|
|
//actors: vec![Apr::make_actor(_ctx, "/pawn.png", 0, 0, 0)],
|
|
|
|
actors: temp_vec, |
|
|
|
actors, |
|
|
|
behaviours: vec![behaviour::Behaviour { |
|
|
|
moves: vec![(0, 1)], |
|
|
|
}], //the pawn can go ONE forwards
|
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn make_actor(ctx: &mut Context, img_path: &str, _x: u8, _y: u8, b: u8) -> actor::Actor { |
|
|
|
return actor::Actor {
|
|
|
|
|
|
|
|
pub fn make_actor(ctx: &mut Context, img_path: &str, _x: u8, _y: u8, b: u8) -> actor::Actor { |
|
|
|
actor::Actor { |
|
|
|
image: graphics::Image::new(ctx, img_path).unwrap(), |
|
|
|
posn: actor::ActorPosn::BoardPosn { x: _x, y: _y }, |
|
|
|
behaviour: b, |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
pub fn set_colour(&mut self, r: usize, c: usize, col: u8) { |
|
|
|
//You should only modify self.board through this method.
|
|
|
@ -115,8 +107,7 @@ impl EventHandler for Apr { |
|
|
|
} |
|
|
|
actor::ActorPosn::BoardPosn { x, y } => { |
|
|
|
if mouse::button_pressed(ctx, MouseButton::Left) { |
|
|
|
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 { |
|
|
|
let x = board::START_X + board::BOARD_SQUARE_SIZE * (x as f32); |
|
|
|
let y = board::START_Y + board::BOARD_SQUARE_SIZE * (y as f32); |
|
|
@ -139,7 +130,12 @@ impl EventHandler for Apr { |
|
|
|
let drawparams = graphics::DrawParam::new(); |
|
|
|
|
|
|
|
if self.should_update_grid { |
|
|
|
self.grid = make_grid(ctx, self.board.row, self.board.col, self.board.board.as_slice())?; |
|
|
|
self.grid = make_grid( |
|
|
|
ctx, |
|
|
|
self.board.row, |
|
|
|
self.board.col, |
|
|
|
self.board.board.as_slice(), |
|
|
|
)?; |
|
|
|
self.should_update_grid = false; |
|
|
|
} |
|
|
|
graphics::draw(ctx, &self.grid, drawparams)?; |
|
|
@ -152,10 +148,10 @@ 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 * (x as f32), |
|
|
|
board::START_Y + board::BOARD_SQUARE_SIZE * (y as f32), |
|
|
|
]), |
|
|
|
)?, |
|
|
|
)?, |
|
|
|
} |
|
|
|
} |
|
|
|
// Draw code here...
|
|
|
|