-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.h
75 lines (65 loc) · 1.53 KB
/
Game.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
// ----------------------------------------------------------------
// From Game Programming in C++ by Sanjay Madhav
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
//
// Released under the BSD License
// See LICENSE in root directory for full details.
// ----------------------------------------------------------------
#pragma once
#include "SDL/SDL.h"
// Vector2 struct just stores x/y coordinates
// (for now)
struct Vector2
{
float x;
float y;
};
struct Ball
{
Vector2 position;
Vector2 velocity;
bool onScreen = true;
};
struct Paddle
{
int direction;
Vector2 position;
bool left;
};
// Game class
class Game
{
public:
Game();
// Initialize the game
bool Initialize();
// Runs the game loop until the game is over
void RunLoop();
// Shutdown the game
void Shutdown();
private:
// Helper functions for the game loop
void ProcessInput();
void UpdateGame();
void GenerateOutput();
void UpdatePaddle(Vector2 &paddlePos, int paddleDir, float deltaTime);
Ball InitializeBall(float posX, float posY, float velX, float velY);
bool HasCollision(Ball ball, Paddle paddle);
void UpdateBall(Ball &ball, float deltaTime);
// Window created by SDL
SDL_Window* mWindow;
// Renderer for 2D drawing
SDL_Renderer* mRenderer;
// Number of ticks since start of game
Uint32 mTicksCount;
// Game should continue to run
bool mIsRunning;
// Pong specific
// Left Paddle
Paddle mLeftPaddle;
// Right Paddle
Paddle mRightPaddle;
// the ball
Ball mBall1;
Ball mBall2;
};