aboutsummaryrefslogtreecommitdiff
path: root/src/tetris
diff options
context:
space:
mode:
authorcurly <curlybryce@protonmail.com>2022-08-13 17:21:42 -0600
committercurly <curlybryce@protonmail.com>2022-08-13 17:21:42 -0600
commit1d1ca2fdae780efdb9d27394f5d3720fe9282c91 (patch)
treece6c36767bba6e594d5ea63834041232f058a3ce /src/tetris
downloadtetris-1d1ca2fdae780efdb9d27394f5d3720fe9282c91.tar.gz
tetris-1d1ca2fdae780efdb9d27394f5d3720fe9282c91.tar.bz2
tetris-1d1ca2fdae780efdb9d27394f5d3720fe9282c91.zip
define everthing I can think of
Diffstat (limited to 'src/tetris')
-rw-r--r--src/tetris/piece.rs71
1 files changed, 71 insertions, 0 deletions
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<Vec<i8>>) -> Option<Pos> {
+ None
+ }
+
+ // Return false if the piece cannot move
+ pub fn r#move(&self, dir: Dir) -> bool {
+ false
+ }
+} \ No newline at end of file