-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
66 lines (50 loc) · 1.21 KB
/
Game.cpp
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
#include <assert.h>
#include "Game.h"
#include <raylib.h>
#include "Settings.h"
Game::Game(int width, int height, int fps, std::string title)
:
board(settings::boardPosition,
settings::boardWidthHeight,
settings::cellSize,
settings::padding),
tetromino(board)
{
assert(!GetWindowHandle()); // If assertion triggers : Window is already opened
SetTargetFPS(fps);
InitWindow(width, height, title.c_str());
}
Game::~Game() noexcept // We promise to compilator that exception is never thrown here // If it is : std::terminate() is called
{
assert(GetWindowHandle()); // If assertion triggers : Window is already closed
CloseWindow();
}
bool Game::GameShouldClose() const // We promise that we do not change the returnable value // Good practice to use it for getters that return value how it is
{
return WindowShouldClose();
}
void Game::Tick()
{
SetWindowTitle(TextFormat("Tetris Raylib | %d fps",GetFPS()));
BeginDrawing();
Update();
Draw();
EndDrawing();
}
void Game::Update()
{
if(IsKeyPressed(KEY_E))
{
tetromino.RotateClockwise();
}
if(IsKeyPressed(KEY_Q))
{
tetromino.RotateCounterClockwise();
}
}
void Game::Draw()
{
ClearBackground(BLACK);
board.Draw();
tetromino.Draw();
}