botó per a donar energiaa les pilotes

This commit is contained in:
2024-08-21 13:12:52 +02:00
parent cdd6e7bc5d
commit e5fb176ef6
3 changed files with 37 additions and 4 deletions
+23 -3
View File
@@ -20,8 +20,9 @@ void initBalls(int value)
{
for (int i = 0; i < test[value]; ++i)
{
const int sign = ((rand() % 2) * 2) - 1;;
const float x = (rand()%(SCREEN_WIDTH/2)) + (SCREEN_WIDTH / 4);
const int sign = ((rand() % 2) * 2) - 1;
;
const float x = (rand() % (SCREEN_WIDTH / 2)) + (SCREEN_WIDTH / 4);
const float vx = (((rand() % 20) + 10) * 0.1f) * sign;
const float vy = ((rand() % 60) - 30) * 0.1f;
const color_t color = {(rand() % 192) + 32, (rand() % 192) + 32, (rand() % 192) + 32};
@@ -30,6 +31,17 @@ void initBalls(int value)
}
}
void pushUpBalls()
{
for (auto ball : balls)
{
const int sign = ((rand() % 2) * 2) - 1;
const float vx = (((rand() % 20) + 10) * 0.1f) * sign;
const float vy = ((rand() % 40) * 0.1f) + 5;
ball->modVel(vx, -vy);
}
}
bool init()
{
// Initialization flag
@@ -87,7 +99,7 @@ bool init()
texture = new Texture(renderer, "resources/pelota.png");
ticks = SDL_GetTicks();
srand (time(NULL));
srand(time(NULL));
initBalls(2);
return success;
@@ -139,6 +151,14 @@ void checkEvents()
shouldExit = true;
break;
}
if (event->type == SDL_KEYDOWN)
{
if (event->key.keysym.sym == SDLK_SPACE)
{
pushUpBalls();
}
}
}
}