cambia el numero de pelotas con las teclas de los numeros
This commit is contained in:
@@ -11,13 +11,16 @@ SDL_Renderer *renderer = NULL;
|
|||||||
SDL_Event *event;
|
SDL_Event *event;
|
||||||
Texture *texture = nullptr;
|
Texture *texture = nullptr;
|
||||||
std::vector<Ball *> balls;
|
std::vector<Ball *> balls;
|
||||||
int test[5] = {1, 10, 100, 500, 1000};
|
int test[6] = {1, 10, 100, 500, 1000, 10000};
|
||||||
|
|
||||||
bool shouldExit = false;
|
bool shouldExit = false;
|
||||||
Uint32 ticks = 0;
|
Uint32 ticks = 0;
|
||||||
|
|
||||||
|
void deleteBalls();
|
||||||
|
|
||||||
void initBalls(int value)
|
void initBalls(int value)
|
||||||
{
|
{
|
||||||
|
deleteBalls();
|
||||||
for (int i = 0; i < test[value]; ++i)
|
for (int i = 0; i < test[value]; ++i)
|
||||||
{
|
{
|
||||||
const int sign = ((rand() % 2) * 2) - 1;
|
const int sign = ((rand() % 2) * 2) - 1;
|
||||||
@@ -42,6 +45,19 @@ void pushUpBalls()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deleteBalls()
|
||||||
|
{
|
||||||
|
for (auto ball : balls)
|
||||||
|
{
|
||||||
|
if (ball)
|
||||||
|
{
|
||||||
|
delete ball;
|
||||||
|
ball = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
balls.clear();
|
||||||
|
}
|
||||||
|
|
||||||
bool init()
|
bool init()
|
||||||
{
|
{
|
||||||
// Initialization flag
|
// Initialization flag
|
||||||
@@ -62,7 +78,7 @@ bool init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create window
|
// Create window
|
||||||
window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2, SDL_WINDOW_SHOWN);
|
window = SDL_CreateWindow("Demo Pelotas 2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2, SDL_WINDOW_SHOWN);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
|
printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
|
||||||
@@ -125,15 +141,7 @@ void close()
|
|||||||
texture = nullptr;
|
texture = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto ball : balls)
|
deleteBalls();
|
||||||
{
|
|
||||||
if (ball)
|
|
||||||
{
|
|
||||||
delete ball;
|
|
||||||
ball = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
balls.clear();
|
|
||||||
|
|
||||||
// Quit SDL subsystems
|
// Quit SDL subsystems
|
||||||
IMG_Quit();
|
IMG_Quit();
|
||||||
@@ -158,6 +166,36 @@ void checkEvents()
|
|||||||
{
|
{
|
||||||
pushUpBalls();
|
pushUpBalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event->key.keysym.sym == SDLK_1)
|
||||||
|
{
|
||||||
|
initBalls(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->key.keysym.sym == SDLK_2)
|
||||||
|
{
|
||||||
|
initBalls(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->key.keysym.sym == SDLK_3)
|
||||||
|
{
|
||||||
|
initBalls(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->key.keysym.sym == SDLK_4)
|
||||||
|
{
|
||||||
|
initBalls(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->key.keysym.sym == SDLK_5)
|
||||||
|
{
|
||||||
|
initBalls(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->key.keysym.sym == SDLK_6)
|
||||||
|
{
|
||||||
|
initBalls(5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user