Added ANGLE_MIN_OFFSET and ANGLE_MAX_OFFSET
This commit is contained in:
parent
5ced7d7ade
commit
5b18911111
10
src/ball.c
10
src/ball.c
@ -12,6 +12,8 @@ Ball_init(int screen_width, int screen_height, int posX_start)
|
||||
*(int *)&b->BALL_WIDTH = 20;
|
||||
*(int *)&b->BALL_HEIGHT = 20;
|
||||
*(int *)&b->BALL_VELOCITY = 7;
|
||||
*(int *)&b->BALL_ANGLE_MIN_OFFSET = 10;
|
||||
*(int *)&b->BALL_ANGLE_MAX_OFFSET = 60;
|
||||
*(int *)&b->BALL_POSX_START = posX_start;
|
||||
*(int *)&b->SCREEN_WIDTH = screen_width;
|
||||
*(int *)&b->SCREEN_HEIGHT = screen_height;
|
||||
@ -24,8 +26,8 @@ Ball_reset(Ball *b, int direction) {
|
||||
// 120 deg angle with norm horizontal vector
|
||||
int angle;
|
||||
do {
|
||||
angle = rand() % 60 + 60;
|
||||
} while (angle == 90);
|
||||
angle = rand() % b->BALL_ANGLE_MAX_OFFSET*2 + b->BALL_ANGLE_MAX_OFFSET/2 - 90;
|
||||
} while (-b->BALL_ANGLE_MIN_OFFSET <= angle && angle <= b->BALL_ANGLE_MIN_OFFSET);
|
||||
if (direction < 0) {
|
||||
b->posX = b->BALL_POSX_START;
|
||||
}
|
||||
@ -33,8 +35,8 @@ Ball_reset(Ball *b, int direction) {
|
||||
b->posX = b->SCREEN_WIDTH - b->BALL_POSX_START;
|
||||
}
|
||||
b->posY = b->SCREEN_HEIGHT/2;
|
||||
b->velX = direction * b->BALL_VELOCITY * cos(angle * 2 * M_PI / 180);
|
||||
b->velY = b->BALL_VELOCITY * sin(angle * 2 * M_PI / 180);
|
||||
b->velX = -direction * b->BALL_VELOCITY * cos(angle * M_PI / 180);
|
||||
b->velY = b->BALL_VELOCITY * sin(angle * M_PI / 180);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -11,6 +11,8 @@ typedef struct Ball {
|
||||
const int BALL_HEIGHT;
|
||||
const int BALL_VELOCITY;
|
||||
const int BALL_POSX_START;
|
||||
const int BALL_ANGLE_MIN_OFFSET;
|
||||
const int BALL_ANGLE_MAX_OFFSET;
|
||||
const int SCREEN_WIDTH;
|
||||
const int SCREEN_HEIGHT;
|
||||
int posX;
|
||||
|
Loading…
Reference in New Issue
Block a user