botó per a donar energiaa les pilotes
This commit is contained in:
@@ -67,6 +67,7 @@ void Ball::update()
|
|||||||
{
|
{
|
||||||
y = 0;
|
y = 0;
|
||||||
vy = -vy;
|
vy = -vy;
|
||||||
|
vy = -vy * loss;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones con la parte inferior
|
// Comprueba las colisiones con la parte inferior
|
||||||
@@ -89,7 +90,7 @@ void Ball::update()
|
|||||||
{
|
{
|
||||||
vx = 0.0f;
|
vx = 0.0f;
|
||||||
stopped = true;
|
stopped = true;
|
||||||
//exit(0);
|
// exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,4 +104,13 @@ void Ball::render()
|
|||||||
{
|
{
|
||||||
sprite->setColor(color.r, color.g, color.b);
|
sprite->setColor(color.r, color.g, color.b);
|
||||||
sprite->render();
|
sprite->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modifica la velocidad
|
||||||
|
void Ball::modVel(float vx, float vy)
|
||||||
|
{
|
||||||
|
this->vx = this->vx + vx;
|
||||||
|
this->vy = this->vy + vy;
|
||||||
|
onFloor = false;
|
||||||
|
stopped = false;
|
||||||
}
|
}
|
||||||
@@ -31,4 +31,7 @@ public:
|
|||||||
|
|
||||||
// Pinta la clase
|
// Pinta la clase
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
// Modifica la velocidad
|
||||||
|
void modVel(float vx, float vy);
|
||||||
};
|
};
|
||||||
@@ -20,8 +20,9 @@ void initBalls(int value)
|
|||||||
{
|
{
|
||||||
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;
|
||||||
const float x = (rand()%(SCREEN_WIDTH/2)) + (SCREEN_WIDTH / 4);
|
;
|
||||||
|
const float x = (rand() % (SCREEN_WIDTH / 2)) + (SCREEN_WIDTH / 4);
|
||||||
const float vx = (((rand() % 20) + 10) * 0.1f) * sign;
|
const float vx = (((rand() % 20) + 10) * 0.1f) * sign;
|
||||||
const float vy = ((rand() % 60) - 30) * 0.1f;
|
const float vy = ((rand() % 60) - 30) * 0.1f;
|
||||||
const color_t color = {(rand() % 192) + 32, (rand() % 192) + 32, (rand() % 192) + 32};
|
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()
|
bool init()
|
||||||
{
|
{
|
||||||
// Initialization flag
|
// Initialization flag
|
||||||
@@ -87,7 +99,7 @@ bool init()
|
|||||||
|
|
||||||
texture = new Texture(renderer, "resources/pelota.png");
|
texture = new Texture(renderer, "resources/pelota.png");
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
srand (time(NULL));
|
srand(time(NULL));
|
||||||
initBalls(2);
|
initBalls(2);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
@@ -139,6 +151,14 @@ void checkEvents()
|
|||||||
shouldExit = true;
|
shouldExit = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event->type == SDL_KEYDOWN)
|
||||||
|
{
|
||||||
|
if (event->key.keysym.sym == SDLK_SPACE)
|
||||||
|
{
|
||||||
|
pushUpBalls();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user