refactoring
This commit is contained in:
parent
5a50497cf7
commit
2164102257
1 changed files with 26 additions and 42 deletions
42
main.cpp
42
main.cpp
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
FlappyBird
|
FlappyBird
|
||||||
Copyright (C) 2024 Patrick_Pluto
|
Copyright (C) 2024 Patrick_Pluto
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ bool sdlPipe(SDL_Rect *pipeRect, SDL_Rect *birdRect, SDL_Renderer *renderer,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPipe(SDL_Rect* pipeRect, int offsetX) {
|
void setPipe(SDL_Rect *pipeRect, int offsetX) {
|
||||||
|
|
||||||
// Create a random number generator
|
// Create a random number generator
|
||||||
std::random_device rd; // Obtain a random number from hardware
|
std::random_device rd; // Obtain a random number from hardware
|
||||||
|
@ -124,22 +124,13 @@ int main(int argc, char *argv[]) {
|
||||||
birdRect.w = 48; // Width of the sprite
|
birdRect.w = 48; // Width of the sprite
|
||||||
birdRect.h = 36; // Height of the sprite
|
birdRect.h = 36; // Height of the sprite
|
||||||
|
|
||||||
// Create a random number generator
|
SDL_Rect *pipeRect[4];
|
||||||
std::random_device rd; // Obtain a random number from hardware
|
int dist = 650;
|
||||||
std::mt19937 eng(rd()); // Seed the generator
|
for (int i = 0; i < 4; i++) {
|
||||||
std::uniform_int_distribution<> distr(-950, -650); // Define the range
|
pipeRect[i] = new SDL_Rect();
|
||||||
|
setPipe(pipeRect[i], dist);
|
||||||
SDL_Rect pipe1Rect;
|
dist += 210;
|
||||||
setPipe(&pipe1Rect, 650);
|
}
|
||||||
|
|
||||||
SDL_Rect pipe2Rect;
|
|
||||||
setPipe(&pipe2Rect, 850);
|
|
||||||
|
|
||||||
SDL_Rect pipe3Rect;
|
|
||||||
setPipe(&pipe3Rect, 1050);
|
|
||||||
|
|
||||||
SDL_Rect pipe4Rect;
|
|
||||||
setPipe(&pipe4Rect, 1250);
|
|
||||||
|
|
||||||
// Sprite Velocity
|
// Sprite Velocity
|
||||||
double velocityY = 0;
|
double velocityY = 0;
|
||||||
|
@ -197,18 +188,11 @@ int main(int argc, char *argv[]) {
|
||||||
// Render the sprite
|
// Render the sprite
|
||||||
SDL_RenderCopy(renderer, flappyBird, nullptr, &birdRect);
|
SDL_RenderCopy(renderer, flappyBird, nullptr, &birdRect);
|
||||||
|
|
||||||
quit = sdlPipe(&pipe1Rect, &birdRect, renderer, flappyBird, pipe);
|
for (int i = 0; i < 4; i++) {
|
||||||
|
quit = sdlPipe(pipeRect[i], &birdRect, renderer, flappyBird, pipe);
|
||||||
if (!quit) {
|
if (quit) {
|
||||||
quit = sdlPipe(&pipe2Rect, &birdRect, renderer, flappyBird, pipe);
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!quit) {
|
|
||||||
quit = sdlPipe(&pipe3Rect, &birdRect, renderer, flappyBird, pipe);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!quit) {
|
|
||||||
quit = sdlPipe(&pipe4Rect, &birdRect, renderer, flappyBird, pipe);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present the renderer
|
// Present the renderer
|
||||||
|
|
Loading…
Reference in a new issue