Añadido texto para ver cuantas pelotas se estan utilizando

This commit is contained in:
2024-08-22 11:35:51 +02:00
parent 066188f6bf
commit dbcc7faeba
4 changed files with 129 additions and 10 deletions
+45 -9
View File
@@ -2,6 +2,7 @@
#include "texture.h"
#include "ball.h"
#include "defines.h"
#include "dbgtxt.h"
#include <iostream>
#include <vector>
@@ -14,9 +15,24 @@ int test[8] = {1, 10, 100, 500, 1000, 10000, 50000, 100000};
bool shouldExit = false;
Uint32 ticks = 0;
int index = 0;
std::string text = "";
int textPos = 0;
bool showText = true;
int counter = 0;
void deleteBalls();
void setText()
{
const std::string text2 = test[index] == 1 ? " PELOTA" : " PELOTAS";
text = std::to_string(test[index]) + text2;
const int size = text.size() * 8;
textPos = SCREEN_WIDTH / 2 - size / 2;
counter = TEXT_TIME;
showText = true;
}
void initBalls(int value)
{
deleteBalls();
@@ -102,7 +118,9 @@ bool init()
texture = new Texture(renderer, "resources/pelota.png");
ticks = SDL_GetTicks();
srand(time(NULL));
initBalls(2);
dbg_init(renderer);
initBalls(index);
setText();
return success;
}
@@ -154,43 +172,53 @@ void checkEvents()
if (event->key.keysym.sym == SDLK_1)
{
initBalls(0);
index = 0;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_2)
{
initBalls(1);
index = 1;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_3)
{
initBalls(2);
index = 2;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_4)
{
initBalls(3);
index = 3;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_5)
{
initBalls(4);
index = 4;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_6)
{
initBalls(5);
index = 5;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_7)
{
initBalls(6);
index = 6;
initBalls(index);
}
if (event->key.keysym.sym == SDLK_8)
{
initBalls(7);
index = 7;
initBalls(index);
}
setText();
}
}
}
@@ -205,6 +233,11 @@ void update()
{
ball->update();
}
if (counter > 0)
counter--;
else
showText = false;
}
}
@@ -218,6 +251,9 @@ void render()
ball->render();
}
if (showText)
dbg_print(textPos, 8, text.c_str(), 255, 255, 255);
SDL_RenderPresent(renderer);
}