tetris/src/srs.rs

112 lines
2.5 KiB
Rust

use crate::playfield::{PlayField, Position};
use crate::Tetromino;
#[derive(Copy)]
pub struct Offset {
x: i8,
y: i8,
}
pub enum RotationDirection {
Clockwise,
AntiClockwise,
}
pub trait RotationSystem {
fn get_rotation_offset(
piece: &Tetromino,
center: &Position,
direction: RotationDirection,
playfield: &PlayField,
) -> Option<Offset>;
}
pub struct SRS {}
impl RotationSystem for SRS {
fn get_rotation_offset(
piece: &Tetromino,
center: &Position,
direction: RotationDirection,
playfield: &PlayField,
) -> Option<Offset> {
None
}
}
#[derive(PartialEq, Eq, Hash)]
enum Rotation {
O, // Spawn state
R, // Right rotation: clockwise rotation from spawn state
U, // Upside-down rotation: rotation after 2 left or right rotations from spawn state
L, // Left rotation: counterclockwise rotation from spawn state
}
struct OffsetData {
O: Vec<Offset>,
R: Vec<Offset>,
U: Vec<Offset>,
L: Vec<Offset>,
}
impl OffsetData {
pub fn apply_right_rotation() {}
}
const JLSTZOffsetData: OffsetData = OffsetData {
O: vec![Offset { x: 0, y: 0 }],
R: vec![
Offset { x: 0, y: 0 },
Offset { x: 1, y: 0 },
Offset { x: 1, y: -1 },
Offset { x: 0, y: 2 },
Offset { x: 1, y: 2 },
],
U: vec![Offset { x: 0, y: 0 }],
L: vec![
Offset { x: 0, y: 0 },
Offset { x: -1, y: 0 },
Offset { x: -1, y: -1 },
Offset { x: 0, y: 2 },
Offset { x: -1, y: 2 },
],
};
const IOffsetData: OffsetData = OffsetData {
O: vec![
Offset { x: 0, y: 0 },
Offset { x: -1, y: 0 },
Offset { x: 2, y: 0 },
Offset { x: -1, y: 0 },
Offset { x: 2, y: 0 },
],
R: vec![
Offset { x: -1, y: 0 },
Offset { x: 0, y: 0 },
Offset { x: 0, y: 0 },
Offset { x: 0, y: 1 },
Offset { x: 0, y: -2 },
],
U: vec![
Offset { x: -1, y: 1 },
Offset { x: 1, y: 1 },
Offset { x: -2, y: 1 },
Offset { x: 1, y: 0 },
Offset { x: -2, y: 0 },
],
L: vec![
Offset { x: 0, y: 1 },
Offset { x: 0, y: 1 },
Offset { x: 0, y: 1 },
Offset { x: 0, y: -1 },
Offset { x: 0, y: 2 },
],
};
const OOffsetData: OffsetData = OffsetData {
O: vec![Offset { x: 0, y: 0 }],
R: vec![Offset { x: 0, y: -1 }],
U: vec![Offset { x: -1, y: -1 }],
L: vec![Offset { x: -1, y: 0 }],
};