diff --git a/O12/TetrisWindow.cpp b/O12/TetrisWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..31dbfda2731baa39dd651c10c40bdf32a8bfb453 --- /dev/null +++ b/O12/TetrisWindow.cpp @@ -0,0 +1,48 @@ +#include "TetrisWindow.h" + + +void TetrisWindow::run() { + unsigned int framesSinceLastTetronimoMove = 0; + const unsigned int framesPerTetronimoMove = 20; + + while(!should_close()) { + framesSinceLastTetronimoMove++; + if(framesSinceLastTetronimoMove >= framesPerTetronimoMove) { + framesSinceLastTetronimoMove = 0; + /********************************************************/ + //Kall moveTetrominoDown() her + /********************************************************/ + } + handleInput(); + + /********************************************************/ + //Kall draw-funksjonene her + /********************************************************/ + + next_frame(); + } +} + + +void TetrisWindow::handleInput() { + + static bool lastZKeyState = false; + static bool lastUpKeyState = false; + + bool currentZKeyState = is_key_down(KeyboardKey::Z); + bool currentUpKeyState = is_key_down(KeyboardKey::UP); + + + if(currentZKeyState && !lastZKeyState) { + cout << "Hello from z\n"; + } + + if(currentUpKeyState && !lastUpKeyState) { + cout << "Hello from up\n"; + } + + + lastZKeyState = currentZKeyState; + lastUpKeyState = currentUpKeyState; +} + diff --git a/O12/TetrisWindow.h b/O12/TetrisWindow.h new file mode 100644 index 0000000000000000000000000000000000000000..33ee07f78b3bff8d428a3ae791bd2b3b1ac6e881 --- /dev/null +++ b/O12/TetrisWindow.h @@ -0,0 +1,19 @@ +#pragma once +#include "AnimationWindow.h" +#include "Tetromino.h" +#include "GUI.h" +#include <atomic> + +class TetrisWindow : public AnimationWindow { + +public: + TetrisWindow(); + void run(); + + + +private: + + void handleInput(); + +}; diff --git a/O12/Tetromino.cpp b/O12/Tetromino.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a536bf2d752fe11df4f6a9588820d240db596a86 --- /dev/null +++ b/O12/Tetromino.cpp @@ -0,0 +1,72 @@ +#include "Tetromino.h" + +const map<TetrominoType, vector<vector<int>>> initialMatrixMap { + + { + TetrominoType::J, + { + {0, 0, 0}, + {1, 1, 1}, + {0, 0, 1} + } + }, + { + TetrominoType::L, + { + {0, 0, 0}, + {1, 1, 1}, + {1, 0, 0} + } + }, + { + TetrominoType::I, + { + //Denne er representert som en 6x6 matrise for å få en bedre rotasjonsfunksjonalitet + {0, 0, 1, 0, 0, 0}, + {0, 0, 1, 0, 0, 0}, + {0, 0, 1, 0, 0, 0}, + {0, 0, 1, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0} + } + } +}; + +Tetromino::Tetromino(Point startingPoint, TetrominoType tetType) : +topLeftCorner{startingPoint} +{ + +} + +void Tetromino::rotateCounterClockwise() { + //Første rotasjon, med hensyn på diagonalen + for(int row = 0; row < matrixSize; row++){ + for(int column = 0; column < row; column++){ + std::swap(blockMatrix[row][column], blockMatrix[column][row]); + } + } + + //Andre rotasjon, med hensyn på den midtre raden + for(int row = 0; row < matrixSize/2; row++){ + for(int column = 0; column < matrixSize; column++){ + std::swap(blockMatrix[row][column], blockMatrix[matrixSize-row-1][column]); + + } + } +} + +void Tetromino::rotateClockwise() { + //Første rotasjon, med hensyn på diagonalen + for(int row = 0; row < matrixSize; row++){ + for(int column = 0; column < row; column++){ + std::swap(blockMatrix[row][column], blockMatrix[column][row]); + } + } + + //Andre rotasjon, med hensyn på den midtre kolonnen + for(int row = 0; row < matrixSize; row++){ + for(int column = 0; column < matrixSize/2; column++){ + std::swap(blockMatrix[row][column], blockMatrix[row][matrixSize-column-1]); + } + } +} diff --git a/O12/Tetromino.h b/O12/Tetromino.h new file mode 100644 index 0000000000000000000000000000000000000000..4e9a1a1365ba8ef953fbf1f8f0b9f68aaf84f472 --- /dev/null +++ b/O12/Tetromino.h @@ -0,0 +1,22 @@ +#pragma once +#include "Graph.h" + + +enum class TetrominoType{J, L, T, S, Z, O, I, NONE}; + +class Tetromino { +public: + static constexpr int blockSize {30}; + + Tetromino(Point startingPoint, TetrominoType tetType); + + void rotateClockwise(); + void rotateCounterClockwise(); + + + +private: + int matrixSize; + Point topLeftCorner; + vector<vector<TetrominoType>> blockMatrix; +}; diff --git a/O12/main.cpp b/O12/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6db321866e9c6a0804867c78e35cca36b53a61bf --- /dev/null +++ b/O12/main.cpp @@ -0,0 +1,13 @@ +#include "Tetromino.h" +#include "TetrisWindow.h" + + + +int main() +{ + /********************************************************/ + //Opprett vindu her + /********************************************************/ + //kall run på det her + return 0; +}