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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
// Header //
#include "CGame.h"
extern CGame Game;
// Konstruktor //
CPaddle::CPaddle()
{
m_s_Paddle = NULL; // Schlägerfläche
x = 220; // Position x
y = 550; // Position y
m_r_location.x = x; // Rechteck oben links
m_r_location.y = y; // Rechteck unten links
m_r_location.w = 100; // Rechteck oben rechts
m_r_location.h = 20; // Rechteck unten rechts
xVel = 0; // Geschwindigkeit
}
// Läd das Bild
bool CPaddle::LoadImage(std::string filename)
{
// Bild Laden
m_s_Paddle = Load_Image(filename, false, true);
if(m_s_Paddle == NULL)
return false;
return true;
}
// Schläger Kontrolle //
void CPaddle::Handle()
{
// Unwichtig
}
// Bewegung //
void CPaddle::Move()
{
// Unwichtig
}
// Render //
void CPaddle::Show()
{
// Rendern
Render_Surface(m_r_location.x, y, m_s_Paddle, s_screen, NULL);
}
// Löschen //
void CPaddle::Clear()
{
SDL_FreeSurface(m_s_Paddle);
}
// --------------------------------------------------------------- //
// Konstruktor //
CInterface::CInterface()
{
// Interfacefläche
m_s_interface = NULL;
}
// Bildlade Funktion //
bool CInterface::LoadImage(std::string filename)
{
// Bildladen
m_s_interface = Load_Image(filename, false, true);
if(m_s_interface == NULL)
return false;
return true;
}
// Render Funktion //
void CInterface::Show()
{
// Rendern
Render_Surface(0, 0, m_s_interface, s_screen, NULL);
}
// Löschen //
void CInterface::Clear()
{
SDL_FreeSurface(m_s_interface);
}
// --------------------------------------------------------------- //
// Konstruktor
CBall::CBall()
{
location.x = Game.Player.m_r_location.x + 50;
location.y = 530;
location.w = 20;
location.h = 20;
image_location.x = 0;
image_location.y = 0;
image_location.w = 20;
image_location.h = 20;
xVel = -5;
yVel = -5;
}
// Ladet das Bild
bool CBall::LoadImage(std::string filename)
{
// Lade Bild
m_s_Ball = Load_Image(filename, false, true);
if(m_s_Ball == NULL)
return false;
return true;
}
// Rendern
void CBall::Show()
{
// Renderen
SDL_BlitSurface(m_s_Ball, &image_location, s_screen, &location);
}
// Checkt Kolloson
bool CBall::CheckBallCollisions()
{
// Unwichtig
}
void CBall::Handle()
{
// Unwichtig
}
void CBall::CheckBlockCollisions()
{
// Unwichtig
}
void CBall::HandleBlockCollision(int index)
{
// Unwichtig
}
bool CBall::CheckPointInRect(int x, int y, SDL_Rect rect)
{
// Unwichtig
}
void CBall::Clear()
{
SDL_FreeSurface(m_s_Ball);
}
// --------------------------------------------------------------- //
CGame::CGame()
{
m_Quit = false;
m_Level = 1;
m_Score = 0;
m_Combo = 1;
}
bool CGame::Init_Files()
{
if(Interface.LoadImage("Interface.png") == false)
return false;
if(Player.LoadImage("Paddle.png") == false)
return false;
if(Ball.LoadImage("Ball.png") == false)
return false;
return true;
}
bool CGame::Init_Level()
{
// Unwichtig
}
bool CGame::Init_RandomLevel()
{
// Unwichtig
}
bool CGame::Game()
{
// Variablen //
char Buffer[256]; // Zwischenspeicher für Text
SDL_Color textColor = {255, 255, 255}; // Textfarbe Weiß
SDL_Color textColorGreen = {0 , 255, 0 }; // Textfarbe Grün
// Schleife
while(m_Quit == false)
{
// Event Schleife
while(SDL_PollEvent(&e_Event))
{
// Spieler Kontrolle
Player.Handle();
switch(e_Event.type)
{
case SDL_KEYDOWN:
// Wenn ESC gedrückt wurde
if(e_Event.key.keysym.sym == SDLK_ESCAPE)
m_Quit = true;
}
// Wenn oben auf X gedrückt wurde
if(e_Event.type == SDL_QUIT)
m_Quit = true;
}
sprintf(Buffer, "Score: %i",m_Score);
s_score = TTF_RenderText_Solid(font, Buffer, textColor);
sprintf(Buffer, "Combo: x %i",m_Combo);
s_combo = TTF_RenderText_Solid(font, Buffer, textColorGreen);
// Bewegung wird berechnet
for(int i = 0; i < 1; i++)
{
Player.Move();
Ball.Handle();
}
Interface.Show(); // Oberfläche wird gerendert
Player.Show(); // Spieler wird gerendert
Ball.Show();
Render_Surface(550, 50, s_score, s_screen, NULL);
if(m_Combo > 1)
Render_Surface(550, 63, s_combo, s_screen, NULL);
for(int i=0; i< g_NumBlocks; i++)
SDL_BlitSurface(s_blocks, &g_Block[i].image_location, s_screen, &g_Block[i].location);
// Flipen
if(SDL_Flip(s_screen) == -1)
return 1;
// Frames
if(FPS.get_ticks() < 1000 / FRAMES_PER_SECOND)
SDL_Delay((1000 / FRAMES_PER_SECOND) - FPS.get_ticks());
}
return true;
}
void CGame::Clear()
{
Player.Clear();
Interface.Clear();
Ball.Clear();
}
|