Browse Source

ok why was silverember not in here

master
SilverEmber 4 years ago
parent
commit
275bdf008f
  1. 23
      src/apr.rs
  2. 19
      src/behaviour.rs
  3. 2
      src/main.rs

23
src/apr.rs

@ -53,12 +53,18 @@ impl Apr {
for i in 0..r {
// white side
actors.push(actor::Actor::new(_ctx, "/pawn.png", i, 1, 0));
behaviours.push(behaviour::Behaviour::new(vec![(-1, -1), (1, -1)], [0, 0, 1, 0]));
behaviours.push(behaviour::Behaviour::new(
vec![(-1, -1), (1, -1)],
[0, 0, 1, 0],
));
}
for i in 0..r {
// black side
actors.push(actor::Actor::new(_ctx, "/pawn2.png", i, c - 2, 0));
behaviours.push(behaviour::Behaviour::new(vec![(1, 1), (-1, 1)], [1, 0, 0, 0]));
behaviours.push(behaviour::Behaviour::new(
vec![(1, 1), (-1, 1)],
[1, 0, 0, 0],
));
}
Ok(Apr {
grid: make_grid(_ctx, r, c, board.board.as_slice())?,
@ -94,9 +100,16 @@ impl EventHandler for Apr {
if !mouse::button_pressed(ctx, MouseButton::Left) {
// no long clicking and dragging
let (x, y) = self.board.closest_square_coords(posn.x, posn.y);
if self.dragging { // released, so now we check destination
if !self.behaviours[index].validate_dest((prev_x, prev_y), (x, y)) { actor.posn = actor::ActorPosn::BoardPosn { x: prev_x, y: prev_y }; }
else { actor.posn = actor::ActorPosn::BoardPosn { x, y }; }
if self.dragging {
// released, so now we check destination
if !self.behaviours[index].validate_dest((prev_x, prev_y), (x, y)) {
actor.posn = actor::ActorPosn::BoardPosn {
x: prev_x,
y: prev_y,
};
} else {
actor.posn = actor::ActorPosn::BoardPosn { x, y };
}
}
self.dragging = false;
} else {

19
src/behaviour.rs

@ -5,17 +5,22 @@ pub struct Behaviour {
impl Behaviour {
pub fn new(m: Vec<(i8, i8)>, d: [u8; 4]) -> Behaviour {
Behaviour {
moves: m,
dirs: d,
}
Behaviour { moves: m, dirs: d }
}
pub fn validate_dest(&self, origin: (u8, u8), destination: (u8, u8)) -> bool { // original plan was to use match but i felt for loops would work better since we dont yet know the extent of moves vector
pub fn validate_dest(&self, origin: (u8, u8), destination: (u8, u8)) -> bool {
// original plan was to use match but i felt for loops would work better since we dont yet know the extent of moves vector
//println!("origin: ({}, {}), destination: ({}, {})", origin.0, origin.1, destination.0, destination.1);
for moveset in self.moves.iter() {
for dir in self.dirs.iter() { // mind blanking need to add something to confirm which direction we are iterating through
if (((origin.0 as i8) + (*dir as i8) * moveset.0) as u8, ((origin.1 as i8) - (*dir as i8) * moveset.1) as u8) == destination { return true; } // flip the second component of calculation because the grid works from top left isntead of bot left like a piss
for dir in self.dirs.iter() {
// mind blanking need to add something to confirm which direction we are iterating through
if (
((origin.0 as i8) + (*dir as i8) * moveset.0) as u8,
((origin.1 as i8) - (*dir as i8) * moveset.1) as u8,
) == destination
{
return true;
} // flip the second component of calculation because the grid works from top left isntead of bot left like a piss
}
}
return false;

2
src/main.rs

@ -10,7 +10,7 @@ mod behaviour;
mod board;
fn main() -> GameResult<()> {
let mut cb = ContextBuilder::new("apruebo", "s1m7u and e-dt");
let mut cb = ContextBuilder::new("apruebo", "s1m7u, e-dt and silverember");
if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
let mut path = path::PathBuf::from(manifest_dir);

Loading…
Cancel
Save