mirror of
https://github.com/thepigeongenerator/breakout_clone.git
synced 2025-12-17 22:35:45 +01:00
sort functions better based on when they're called
This commit is contained in:
42
src/level.c
42
src/level.c
@@ -47,6 +47,27 @@ void level_init(Level* level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// updates the player's "bouncer"
|
||||||
|
static void update_player(Bouncer* bouncer, Ball* ball, const Uint8* keys) {
|
||||||
|
// if move bouncer LEFT
|
||||||
|
if (keys[SDL_SCANCODE_A] || keys[SDL_SCANCODE_LEFT]) {
|
||||||
|
ball->moving = true;
|
||||||
|
|
||||||
|
if (bouncer->pos.x < 0 == false) {
|
||||||
|
bouncer->pos.x -= BOUNCER_SPEED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if move bouncer RIGHT
|
||||||
|
if (keys[SDL_SCANCODE_D] || keys[SDL_SCANCODE_RIGHT]) {
|
||||||
|
ball->moving = true;
|
||||||
|
|
||||||
|
if ((bouncer->pos.x + bouncer->width) > SCREEN_WIDTH == false) {
|
||||||
|
bouncer->pos.x += BOUNCER_SPEED; // increase the bouncer pos
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// updates the player's ball
|
// updates the player's ball
|
||||||
static void update_ball(Level* level, Ball* ball, Bouncer* bouncer) {
|
static void update_ball(Level* level, Ball* ball, Bouncer* bouncer) {
|
||||||
// update ball position
|
// update ball position
|
||||||
@@ -115,27 +136,6 @@ static void update_ball(Level* level, Ball* ball, Bouncer* bouncer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// updates the player's "bouncer"
|
|
||||||
static void update_player(Bouncer* bouncer, Ball* ball, const Uint8* keys) {
|
|
||||||
// if move bouncer LEFT
|
|
||||||
if (keys[SDL_SCANCODE_A] || keys[SDL_SCANCODE_LEFT]) {
|
|
||||||
ball->moving = true;
|
|
||||||
|
|
||||||
if (bouncer->pos.x < 0 == false) {
|
|
||||||
bouncer->pos.x -= BOUNCER_SPEED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if move bouncer RIGHT
|
|
||||||
if (keys[SDL_SCANCODE_D] || keys[SDL_SCANCODE_RIGHT]) {
|
|
||||||
ball->moving = true;
|
|
||||||
|
|
||||||
if ((bouncer->pos.x + bouncer->width) > SCREEN_WIDTH == false) {
|
|
||||||
bouncer->pos.x += BOUNCER_SPEED; // increase the bouncer pos
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//updates the level
|
//updates the level
|
||||||
void level_update(Level* level, const Uint8* keys) {
|
void level_update(Level* level, const Uint8* keys) {
|
||||||
Bouncer* bouncer = &level->bouncer;
|
Bouncer* bouncer = &level->bouncer;
|
||||||
|
|||||||
Reference in New Issue
Block a user