tetris/src/srs.rs

124 lines
2.8 KiB
Rust

use crate::playfield::PlayField;
use crate::tetromino::{Position, TetrominoType};
#[derive(Copy, Clone)]
pub struct Offset {
x: i8,
y: i8,
}
pub enum RotationDirection {
Clockwise,
AntiClockwise,
}
pub trait RotationSystem {
fn default() -> Self;
fn get_rotation_offset(
piece: &TetrominoType,
center: &Position,
direction: RotationDirection,
playfield: &PlayField,
) -> Option<Offset>;
}
pub struct SRS {}
impl SRS {
pub fn new() -> Self {
Self {}
}
}
impl RotationSystem for SRS {
fn default() -> Self {
SRS::new()
}
fn get_rotation_offset(
piece: &TetrominoType,
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: &[Offset],
// R: &[Offset],
// U: &[Offset],
// L: &[Offset],
}
impl OffsetData {
pub fn apply_right_rotation() {}
}
// static 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 },
// ],
// };
// static 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 },
// ],
// };
// static 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 }],
// };