-
Notifications
You must be signed in to change notification settings - Fork 0
/
spong.h
69 lines (52 loc) · 1.48 KB
/
spong.h
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
60
61
62
63
64
65
66
67
68
69
#include <string>
#include <iostream>
#include <SDL2/SDL_ttf.h> // SDL font library
#include "ball.h"
enum Controllers {mouse, keyboard};
class Paddle;
class Ball;
// Game class
class Game
{
public:
Game();
~Game();
// Initialize the game
bool Initialize();
// Runs the game loop until the game is over
void RunLoop();
static constexpr int wallThickness = 15;
static const int WIND_WIDTH = 1024;
static const int WIND_HEIGHT = 768;
// Controllers
Controllers controller;
private:
void ProcessInput();
void UpdateGame();
void GenerateOutput();
void textRender(Paddle& paddle);
void reset();
// Window created by SDL
SDL_Window* window;
// Renderer for 2D drawing
SDL_Renderer* renderer;
// Number of ticks since start of game
Uint32 ticksCount;
// Game should continue to run
bool isRunning;
bool isPaused;
unsigned int number_collisions; // counts the number of collisions with the 2 paddles
Paddle left_paddle = {SDL_Rect{WIND_WIDTH * 4 / 10, WIND_HEIGHT / 12, 30, 30}};
Paddle right_paddle = {SDL_Rect{WIND_WIDTH * 6 / 10 - 12, WIND_HEIGHT/ 12, 30, 30}};
Ball ball;
int mouse_x, mouse_y; // Mouse coordinates
// Sounds
Mix_Chunk* score_sound;
// Indicates when rendering new score is necessary
bool left_score_update;
// Indicates when rendering new score is necessary
bool right_score_update;
TTF_Font* font;
SDL_Color font_color;
const Uint8* state;
};