-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameplay.h
198 lines (169 loc) · 4.83 KB
/
gameplay.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#pragma once
#include <iostream>
#include <SDL.h>
#include <SDL_mixer.h>
#include "paddle.h"
#include "paddleController.h"
#include "wall.h"
#include "ball.h"
#include "ui.h"
#include "appSettings.h"
#include "audioManager.h"
struct gameplay {
bool win = false;
bool quit = false;
int scoreToWin = 5;
int leftScore = 0;
bool leftScoreChanged = false;
int rightScore = 0;
bool rightScoreChanged = false;
audioManager* audioManager = NULL;
appSettings* appSettings = NULL;
float paddleWidth = 20; // screenWidth / 64
float paddleHeight = 90; // screenHeight / 8
float paddleSpeed = 300;
float leftPaddleInitX = 160; // screenWidth / 8
float leftPaddleInitY = 360; // screenHeight / 2
paddleController leftPaddleController = {
SDL_SCANCODE_W,
false,
SDL_SCANCODE_S,
false
};
paddle leftPaddle = {
paddleWidth,
paddleHeight,
paddleSpeed,
0.0f,
{leftPaddleInitX, leftPaddleInitY},
{leftPaddleInitX, leftPaddleInitY, paddleWidth, paddleHeight},
white,
leftPaddleController
};
//float rightPaddleInitX = screenWidth - (screenWidth / 8);
//float rightPaddleInitY = screenHeight / 2;
float rightPaddleInitX = 1280 - (1280/ 8); // screenWidth - (screenWidth / 8);
float rightPaddleInitY = 720 / 2; // screenHeight / 2
paddleController rightPaddleController = {
SDL_SCANCODE_UP,
false,
SDL_SCANCODE_DOWN,
false
};
paddle rightPaddle = {
paddleWidth,
paddleHeight,
paddleSpeed,
0.0f,
{rightPaddleInitX, rightPaddleInitY},
{rightPaddleInitX, rightPaddleInitY, paddleWidth, paddleHeight},
white,
rightPaddleController
};
SDL_Color wallColor = white;
float horzWallWidth = 10; // screenWidth / 128
float horzWallHeight = 720; // screenHeight
float leftWallX = 1280 / 16; // screenWidth / 16
float leftWallY = 0; // Starts at top left corner not center (0 not screenHeight / 2)
SDL_FRect leftWallRectTranform = {
leftWallX,
leftWallY,
horzWallWidth,
horzWallHeight
};
wall leftWall = {
leftWallRectTranform,
white
};
float rightWallX = 1280 * 15 / 16; // screenWidth * 15 / 16
float rightWallY = 0; // Starts at top left corner not center (0 not screenHeight / 2)
SDL_FRect rightWallRectTranform = {
rightWallX,
rightWallY,
horzWallWidth,
horzWallHeight
};
wall rightWall = {
rightWallRectTranform,
white
};
float vertWallWidth = 1280; // screenWidth
float vertWallHeight = 1280 / 128; // screenWidth / 128
float topWallX = 0; // Starts at top left corner not center (0 not screenWidth / 2)
float topWallY = -vertWallHeight;
SDL_FRect topWallRectTransform = {
topWallX,
topWallY,
vertWallWidth,
vertWallHeight
};
wall topWall = {
topWallRectTransform,
white
};
float bottomWallX = 0; // Starts at top left corner not center (0 not screenWidth / 2)
//float bottomWallY = 720 - vertWallHeight * 2.0f; // Move above the bottom edge of window // screenHeight - vertWallHeight * 2.0f
float bottomWallY = 720; // Move above the bottom edge of window // screenHeight - vertWallHeight * 2.0f
SDL_FRect bottomWallRectTransform = {
bottomWallX,
bottomWallY,
vertWallWidth,
vertWallHeight
};
wall bottomWall = {
bottomWallRectTransform,
white
};
float ballRadius = 1280 / 64; // Same width as paddle // screenWidth / 64
float ballInitX = 1280 / 2; // screenWidth / 2
float ballInitY = 720 / 2; // screenHeight / 2
float ballSpeed = 600;
SDL_FPoint ballInitTransform = { ballInitX, ballInitY };
SDL_FPoint ballInitVelocity = { 0.6f, 0.6f };
circleCollider ballCollider = {
ballInitTransform,
ballRadius
};
ball ball = {
ballInitTransform,
white,
ballCollider,
ballInitVelocity
};
float resetBallTimer = 0.0f;
float timeToResetBall = 1.0f;
bool resettingBall = false;
float scoreTextWidth = 1280 / 32; // screenWidth / 32
float scoreTextHeight = 720 / 8; // Same Height as paddle // screenHeight / 8
float scoreTextXOffset = 1280 / 16; // screenWidth / 16
float scoreTextYOffset = 1280 / 64; // screenWidth / 64
float leftScoreTextX = (1280 / 2) - scoreTextWidth - scoreTextXOffset; // (screenWidth / 2) - scoreTextWidth - scoreTextXOffset
float leftScoreTextY = scoreTextYOffset;
uiText leftScoreText = {
"leftScore",
NULL,
"assets/font/DotGothic16-Regular.ttf",
100,
{leftScoreTextX, leftScoreTextY, scoreTextWidth, scoreTextHeight},
white,
NULL,
false
};
float rightScoreTextX = (1280 / 2) + scoreTextXOffset; // (screenWidth / 2) + scoreTextXOffset
float rightScoreTextY = scoreTextYOffset;
uiText rightScoreText = {
"rightScore",
NULL,
"assets/font/DotGothic16-Regular.ttf",
100,
{rightScoreTextX, rightScoreTextY, scoreTextWidth, scoreTextHeight},
white,
NULL,
false
};
};
void init(gameplay* gameplay);
void processInput(inputs* inputs, gameplay* gameplay);
void preUpdate(gameplay* gameplay);
void update(float deltaTime, inputs* inputs, gameplay* gameplay);
void render(SDL_Renderer* renderer, gameplay* gameplay);