From 1d1ca2fdae780efdb9d27394f5d3720fe9282c91 Mon Sep 17 00:00:00 2001 From: curly Date: Sat, 13 Aug 2022 17:21:42 -0600 Subject: define everthing I can think of --- src/tetris/piece.rs | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/tetris/piece.rs (limited to 'src/tetris') diff --git a/src/tetris/piece.rs b/src/tetris/piece.rs new file mode 100644 index 0000000..a57b2bb --- /dev/null +++ b/src/tetris/piece.rs @@ -0,0 +1,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>) -> Option { + None + } + + // Return false if the piece cannot move + pub fn r#move(&self, dir: Dir) -> bool { + false + } +} \ No newline at end of file -- cgit v1.2.3