diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/display.rs | 5 | ||||
-rw-r--r-- | src/input.rs | 1 | ||||
-rw-r--r-- | src/lib.rs | 29 | ||||
-rw-r--r-- | src/main.rs | 10 | ||||
-rw-r--r-- | src/tetris.rs | 28 | ||||
-rw-r--r-- | src/tetris/piece.rs | 71 |
6 files changed, 144 insertions, 0 deletions
diff --git a/src/display.rs b/src/display.rs new file mode 100644 index 0000000..c3791f8 --- /dev/null +++ b/src/display.rs @@ -0,0 +1,5 @@ +pub fn display(grid: &Vec<Vec<i8>>) { + for y in grid { + println!("{:?}", y); + } +}
\ No newline at end of file diff --git a/src/input.rs b/src/input.rs new file mode 100644 index 0000000..d4a5ddd --- /dev/null +++ b/src/input.rs @@ -0,0 +1 @@ +pub struct Input {}
\ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..7cbe359 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,29 @@ +mod tetris; +mod input; + +use input::Input; + +pub struct Game { + tickrate: u8, // Between + maxfps: u8, // Between 1 and 240 +} +impl Game { + pub fn new() -> Game { + Game{ + tickrate: 20, + maxfps: 30, + } + } + + // The actual game loop + pub fn game_loop(&self, input: &Input) {} +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1abfbd9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,10 @@ +mod lib; +mod display; +mod input; + +fn main() { + println!("Hello World!"); + let tetris = lib::Tetris::new(); + + display::display(tetris.return_grid()); +}
\ No newline at end of file diff --git a/src/tetris.rs b/src/tetris.rs new file mode 100644 index 0000000..9f9cda8 --- /dev/null +++ b/src/tetris.rs @@ -0,0 +1,28 @@ +mod piece; + +use piece::Piece; + +#[derive(Debug)] +pub struct Tetris { + grid: Vec<Vec<i8>> +} +impl Tetris { + pub fn new() -> Tetris { + Tetris{ + grid: vec!(vec!(0; 10); 20), + } + } + + // Return the grid + pub fn return_grid(&self) -> &Vec<Vec<i8>> { + &self.grid + } + + // Set the grid, given a piece + pub fn set_grid(&mut self, piece: Piece) {} + + // Check each row of the grid + // If one is full, remove it and drop + // the rest of the grid down + pub fn check_lines() {} +}
\ No newline at end of file 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 |