use super::Mino;
#[derive(Debug)]
pub struct Piece {
pub kind: Mino,
pub pivot: (isize, isize),
pub parts: Vec<(isize, isize)>,
pub dir: Rotation,
}
impl Piece {
pub fn new(bounds: (usize, usize), kind: Mino) -> Self {
let pivot = ((bounds.0 / 2 - 1) as isize, (bounds.1 / 2) as isize);
let mut parts = kind.shape().to_vec();
for (x, y) in &mut parts {
*x += pivot.0;
*y += pivot.1;
}
Self {
kind,
pivot,
parts,
dir: Rotation::Spawn,
}
}
}
#[derive(Debug, Clone, Copy)]
#[repr(i8)]
pub enum Rotation {
Spawn = 0,
Right = 1,
Down = 2,
Left = 3,
}
#[derive(Debug, Clone, Copy)]
#[repr(i8)]
pub enum Turn {
Cw = 1,
Ccw = -1,
}
impl Rotation {
pub fn from(r: i8) -> Self {
match r.rem_euclid(4) {
0 => Self::Spawn,
1 => Self::Right,
2 => Self::Down,
_ => Self::Left,
}
}
}