aboutsummaryrefslogtreecommitdiff
path: root/src/tetris/piece.rs
blob: a57b2bb61fa89b0c3e91876d4604d3fff8d1308d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
pub struct Pos(i8, i8);

pub const UP: Pos = Pos(1,0);
pub const DOWN: Pos = Pos(-1,0);
pub const LEFT: Pos = Pos(0,-1);
pub const RIGHT: Pos = Pos(0,1);

pub enum Dir {
    Up,
    Down,
    Left,
    Right,
}

const NORMALL: [[i8; 3]; 3] = [[0,1,0],[0,1,0],[0,1,1]];
const REVERSEL: [[i8; 3]; 3] = [[0,1,0],[0,1,0],[1,1,0]];
const CUBE: [[i8; 3]; 3] = [[0,1,1],[0,1,1],[0,0,0]];
const TEE: [[i8; 3]; 3] = [[0,1,0],[1,1,1],[0,0,0]];
const DIAG: [[i8; 3]; 3] = [[0,1,1],[1,1,0],[0,0,0]];
const REVERSEDIAG: [[i8; 3]; 3] = [[1,1,0],[0,1,1],[0,0,0]];

enum Pieces {
    NormalL,
    ReverseL,
    Cube,
    Tee,
    Diag,
    ReverseDiag,
}

pub struct Piece {
    area: [[i8; 3]; 3], // A static 3x3 area
    position: Pos,
    origin: Pos,
    alive: bool,
}
impl Piece {
    pub fn new() -> Piece {
        Piece{
            area: NORMALL,
            position: Pos(0,5),
            origin: Pos(1,1),
            alive: true,
        }
    }

    // Like new(), but return a random piece
    // out of the enum Pieces
    pub fn random() -> Piece {
        Piece{
            area: NORMALL,
            position: Pos(0,5),
            origin: Pos(1,1),
            alive: true,
        }
    }

    // Using a grid and a direction;
    // See if the new position would hit
    // something in the grid
    // If so, return err
    // otherwise return Some(Pos)
    fn hit_detect(&self, grid: &Vec<Vec<i8>>) -> Option<Pos> {
        None
    }

    // Return false if the piece cannot move
    pub fn r#move(&self, dir: Dir) -> bool {
        false
    }
}