Pequeños arreglos en la interfaz

This commit is contained in:
2024-08-22 19:57:34 +02:00
parent dbcc7faeba
commit af5bc7dcd6

View File

@@ -6,8 +6,8 @@
#include <iostream>
#include <vector>
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
SDL_Window *window = nullptr;
SDL_Renderer *renderer = nullptr;
SDL_Event *event;
Texture *texture = nullptr;
std::vector<Ball *> balls;
@@ -47,6 +47,7 @@ void initBalls(int value)
Ball *b = new Ball(x, vx, vy, color, texture);
balls.push_back(b);
}
setText();
}
void pushUpBalls()
@@ -88,7 +89,7 @@ bool init()
{
// Create window
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2, SDL_WINDOW_SHOWN);
if (window == NULL)
if (window == nullptr)
{
printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
success = false;
@@ -97,7 +98,7 @@ bool init()
{
// Create renderer for window
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL)
if (renderer == nullptr)
{
printf("Renderer could not be created! SDL Error: %s\n", SDL_GetError());
success = false;
@@ -117,10 +118,9 @@ bool init()
texture = new Texture(renderer, "resources/pelota.png");
ticks = SDL_GetTicks();
srand(time(NULL));
srand(time(nullptr));
dbg_init(renderer);
initBalls(index);
setText();
return success;
}
@@ -165,60 +165,65 @@ void checkEvents()
if (event->type == SDL_KEYDOWN && event->key.repeat == 0)
{
if (event->key.keysym.sym == SDLK_SPACE)
if (event->key.keysym.sym == SDLK_ESCAPE)
{
pushUpBalls();
shouldExit = true;
break;
}
if (event->key.keysym.sym == SDLK_1)
else if (event->key.keysym.sym == SDLK_SPACE)
{
pushUpBalls();
break;
}
else if (event->key.keysym.sym == SDLK_1)
{
index = 0;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_2)
else if (event->key.keysym.sym == SDLK_2)
{
index = 1;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_3)
else if (event->key.keysym.sym == SDLK_3)
{
index = 2;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_4)
else if (event->key.keysym.sym == SDLK_4)
{
index = 3;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_5)
else if (event->key.keysym.sym == SDLK_5)
{
index = 4;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_6)
else if (event->key.keysym.sym == SDLK_6)
{
index = 5;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_7)
else if (event->key.keysym.sym == SDLK_7)
{
index = 6;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_8)
else if (event->key.keysym.sym == SDLK_8)
{
index = 7;
initBalls(index);
}
setText();
}
}
}