Added brick reneration + Bouncer speed

This commit is contained in:
Quinn
2024-08-14 12:22:48 +02:00
parent fc7e956f58
commit ac15858e7c
5 changed files with 88 additions and 21 deletions

View File

@@ -4,6 +4,7 @@
#include <SDL2/SDL.h>
#include "vector2.h"
#include "constants.h"
#include "renderer.h"
//prepares the level to be in a playable state
void level_init(Level* level) {
@@ -13,25 +14,49 @@ void level_init(Level* level) {
level->ball.pos.x = (SCREEN_WIDTH / 2) - (BALL_SIZE_DEFAULT / 2);
level->ball.pos.y = (SCREEN_HEIGHT / 2) - (BALL_SIZE_DEFAULT / 2);
level->ball.size = BALL_SIZE_DEFAULT;
level->ball.direction = (Vector2){ 0, BALL_SPEED};
level->ball.direction = (Vector2){ 0, BALL_SPEED };
// initialize bouncer
level->bouncer.pos.x = (SCREEN_WIDTH / 2) - (BOUNCER_WIDTH_DEFAULT / 2);
level->bouncer.pos.y = SCREEN_HEIGHT - (BOUNCER_HEIGHT * 2);
level->bouncer.width = BOUNCER_WIDTH_DEFAULT;
// initialize bricks
// define the colours of the brick rows
const Colour colours[BRICK_COLUMNS] = {
{0x5B, 0xCE, 0xFA, 0xFF},
{0xF5, 0xA9, 0xB8, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
{0xF5, 0xA9, 0xB8, 0xFF},
{0x5B, 0xCE, 0xFA, 0xFF}
};
int brick_width = BRICK_WIDTH + BRICK_PADDING;
int brick_height = BRICK_HEIGHT + (BRICK_PADDING / 2);
float level_padding_left = ((float)SCREEN_WIDTH - ((SCREEN_WIDTH / brick_width) * brick_width)) / 2.0F; //for centering
// store bricks in the level
for (int x = 0; x < BRICK_COLUMNS; x++) {
for (int y = 0; y < BRICK_ROWS; y++) {
Brick* brick = &level->bricks[x][y];
brick->colour = colours[y];
brick->pos.x = (x * brick_width) + level_padding_left;
brick->pos.y = (y * brick_height) + BRICK_PADDING_TOP;
}
}
}
//updates the level
void level_update(Level* level, bool* keys) {
struct Bouncer* bouncer = &level->bouncer;
struct Ball* ball = &level->ball;
Bouncer* bouncer = &level->bouncer;
Ball* ball = &level->ball;
// if move bouncer LEFT
if (keys[SDLK_a]) {
ball->moving = true;
if (bouncer->pos.x < 0 == false) {
bouncer->pos.x -= 0.5F;
bouncer->pos.x -= BOUNCER_SPEED;
}
}
@@ -40,7 +65,7 @@ void level_update(Level* level, bool* keys) {
ball->moving = true;
if ((bouncer->pos.x + bouncer->width) > SCREEN_WIDTH == false) {
bouncer->pos.x += 0.5F; // increase the bouncer pos
bouncer->pos.x += BOUNCER_SPEED; // increase the bouncer pos
}
}