Browse Source

fixed dir implementation. basically moves is the pattern to be replicated.

master
SilverEmber 4 years ago
parent
commit
209a5e96c9
  1. 4
      src/apr.rs
  2. 9
      src/behaviour.rs

4
src/apr.rs

@ -55,7 +55,7 @@ impl Apr {
actors.push(actor::Actor::new(_ctx, "/pawn.png", i, 1, 0)); actors.push(actor::Actor::new(_ctx, "/pawn.png", i, 1, 0));
behaviours.push(behaviour::Behaviour::new( behaviours.push(behaviour::Behaviour::new(
vec![(-1, -1), (1, -1)], vec![(-1, -1), (1, -1)],
[0, 0, 1, 0], vec![(1, -1)],
)); ));
} }
for i in 0..r { for i in 0..r {
@ -63,7 +63,7 @@ impl Apr {
actors.push(actor::Actor::new(_ctx, "/pawn2.png", i, c - 2, 0)); actors.push(actor::Actor::new(_ctx, "/pawn2.png", i, c - 2, 0));
behaviours.push(behaviour::Behaviour::new( behaviours.push(behaviour::Behaviour::new(
vec![(1, 1), (-1, 1)], vec![(1, 1), (-1, 1)],
[1, 0, 0, 0], vec![(1, 1)],
)); ));
} }
Ok(Apr { Ok(Apr {

9
src/behaviour.rs

@ -1,10 +1,10 @@
pub struct Behaviour { pub struct Behaviour {
pub moves: Vec<(i8, i8)>, //this is a placeholder pub moves: Vec<(i8, i8)>, //this is a placeholder
pub dirs: [u8; 4], // up right down left pub dirs: Vec<(i8, i8)>, // up right down left
} }
impl Behaviour { impl Behaviour {
pub fn new(m: Vec<(i8, i8)>, d: [u8; 4]) -> Behaviour { pub fn new(m: Vec<(i8, i8)>, d: Vec<(i8, i8)>) -> Behaviour {
Behaviour { moves: m, dirs: d } Behaviour { moves: m, dirs: d }
} }
@ -14,9 +14,10 @@ impl Behaviour {
for moveset in self.moves.iter() { for moveset in self.moves.iter() {
for dir in self.dirs.iter() { for dir in self.dirs.iter() {
// mind blanking need to add something to confirm which direction we are iterating through // mind blanking need to add something to confirm which direction we are iterating through
// println!("Permissible: ({}, {})", (origin.0 as i8) + dir.0 * moveset.0,(origin.1 as i8) - dir.1 * moveset.1);
if ( if (
((origin.0 as i8) + (*dir as i8) * moveset.0) as u8, ((origin.0 as i8) + dir.0 * moveset.0) as u8,
((origin.1 as i8) - (*dir as i8) * moveset.1) as u8, ((origin.1 as i8) - dir.1 * moveset.1) as u8,
) == destination ) == destination
{ {
return true; return true;

Loading…
Cancel
Save