-
Notifications
You must be signed in to change notification settings - Fork 2
/
GameEngine.h
82 lines (80 loc) · 2.68 KB
/
GameEngine.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
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include <iostream>
#include <string>
#include <algorithm>
#include <SDL.h>
#include <SDL_ttf.h> // to render ttf fonts
#include "Sprite.h"
using namespace std;
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
class GameEngine
{
private:
SDL_Event event; // to handle events
int mouseX, mouseY; // for mouse coordinates
SDL_Window* window; // moved from InitGameEngine
SDL_Renderer* renderer;
bool isRunning = true;
TTF_Font* font; // font declarations
SDL_Surface* fontSurface;
SDL_Texture* fontTexture;
SDL_Rect textRectScore; // defines 'score' text on screen
void RenderFont(const char* text, int x, int y, bool isRefreshText); // font related function
int p1score = 0; // for demo score is hardcoded, this score will be tracked and made in a different function
int aiscore = 0; // AI paddle score
string s1 = to_string(p1score);
string s2 = to_string(aiscore);
string aiwins = ".";
string p1wins = ".";
Sprite* background; // Sprite Actors
Sprite* paddleHuman;
Sprite* paddleAI;
Sprite* ball;
void InitializeSpriteBackground(const char* loadPath, int cellX, int cellY, int cellWidth, int cellHeight,
int destX, int destY, int destW, int destH);
void InitializeSpritepaddleHuman(const char* loadPath, int cellX, int cellY, int cellWidth, int cellHeight,
int destX, int destY, int destW, int destH);
void InitializeSpritepaddleAI(const char* loadPath, int cellX, int cellY, int cellWidth, int cellHeight,
int destX, int destY, int destW, int destH);
void InitializeSpriteBall(const char* loadPath, int cellX, int cellY, int cellWidth, int cellHeight,
int destX, int destY, int destW, int destH);
SDL_Rect divider; // Visual Improvements: center divider
SDL_Rect p1goal;
SDL_Rect aigoal;
SDL_Rect hide1;
SDL_Rect hide2;
public:
int speed_x, speed_y; // x and y speeds of the ball
int direction[2] = { -1, 1 }; // x and y array directions
static GameEngine* Instance(); // function returns
bool InitGameEngine();
bool CheckCollision(SDL_Rect A, SDL_Rect B);
void PaddleHumanMoveMouse(); // Sprite, to:
void UpdateBallPosition();
void ReverseBallPositionY();
void ResetBallPositionX();
void PaddleAIMove();
void ResetPaddleAIBallNotAIArea();
void BallInAIArea();
void CheckBallPaddleCollision();
void BallInPaddleHumanGoalArea();
void BallInPaddleAIGoalArea(); // Sprite, from
bool NotAIArea(SDL_Rect BALL, SDL_Rect AIAREA);
bool InAIArea(SDL_Rect BALL, SDL_Rect AIAREA);
void PlayerServe();
void AIServe();
void AI();
void AddToPlayerScore();
void AddToAIScore();
void KeepPlayerScore();
void KeepAIScore();
void PlayerWins();
void AIWins();
void InitGameWorld();
void Render();
void Input();
void Quit();
void Update();
bool IsRunning() { return isRunning; }
};