mirror of
https://github.com/thepigeongenerator/breakout_clone.git
synced 2025-12-17 06:15:46 +01:00
make ball more reliable
This commit is contained in:
@@ -3,5 +3,4 @@ I wanted a project to learn C and the SDL framework in, and settled upon this ga
|
|||||||
|
|
||||||
### TODO:
|
### TODO:
|
||||||
- make a better input system (one that doesn't crash the game)
|
- make a better input system (one that doesn't crash the game)
|
||||||
- make the bouncer collisions more reliable
|
|
||||||
- make beeping sound effects
|
- make beeping sound effects
|
||||||
|
|||||||
@@ -91,10 +91,11 @@ void level_update(Level* level, bool* keys) {
|
|||||||
// check bouncer collisions
|
// check bouncer collisions
|
||||||
if ((ball->pos.x + ball->size) > bouncer->pos.x && ball->pos.x < (bouncer->pos.x + bouncer->width) &&
|
if ((ball->pos.x + ball->size) > bouncer->pos.x && ball->pos.x < (bouncer->pos.x + bouncer->width) &&
|
||||||
(ball->pos.y + ball->size) > bouncer->pos.y && ball->pos.y < (bouncer->pos.y + BOUNCER_HEIGHT)) {
|
(ball->pos.y + ball->size) > bouncer->pos.y && ball->pos.y < (bouncer->pos.y + BOUNCER_HEIGHT)) {
|
||||||
float x = ball->pos.x - bouncer->pos.x + (ball->size / 2);
|
float x = ball->pos.x - bouncer->pos.x + (ball->size / 2); // get the X axis relative to the bouncer
|
||||||
unsigned max = bouncer->width;
|
unsigned max = bouncer->width + 2; // get the maxiumum of this X axis (add 2 to make it feel more accurate)
|
||||||
float angle = (x - (0.5F * max)) / max * PI;
|
float angle = (x - (max / 2.0F)) / max * PI; // calculate the angle in radians where the bouncer X axis falls on -(pi/2) to pi/2
|
||||||
|
|
||||||
|
// change the ball direction
|
||||||
ball->direction.x = SDL_sinf(angle) * BALL_SPEED;
|
ball->direction.x = SDL_sinf(angle) * BALL_SPEED;
|
||||||
ball->direction.y = -SDL_cosf(angle) * BALL_SPEED;
|
ball->direction.y = -SDL_cosf(angle) * BALL_SPEED;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user