diff --git a/src/constants.h b/src/constants.h index b35c090..86cae3c 100644 --- a/src/constants.h +++ b/src/constants.h @@ -1,20 +1,20 @@ #pragma once -#define SCREEN_WIDTH 960 +#define SCREEN_WIDTH 960 #define SCREEN_HEIGHT 640 -#define BOUNCER_HEIGHT 5 +#define BOUNCER_HEIGHT 5 #define BOUNCER_WIDTH_DEFAULT 75 -#define BOUNCER_SPEED 10.0F +#define BOUNCER_SPEED 10.0F #define BALL_SIZE_DEFAULT 10 -#define BALL_SPEED 5.0F +#define BALL_SPEED 5.0F -#define BRICK_WIDTH 30 -#define BRICK_HEIGHT 15 -#define BRICK_PADDING 2 +#define BRICK_WIDTH 30 +#define BRICK_HEIGHT 15 +#define BRICK_PADDING 2 #define BRICK_PADDING_TOP 30 -#define BRICK_ROWS 5 -#define BRICK_COLUMNS (int)(SCREEN_WIDTH / (BRICK_WIDTH + BRICK_PADDING)) +#define BRICK_ROWS 5 +#define BRICK_COLUMNS (int)(SCREEN_WIDTH / (BRICK_WIDTH + BRICK_PADDING)) #define PI 3.14159265358979323846F // pi was being fucky! :D diff --git a/src/errors.c b/src/errors.c index fa7d860..b2dcd75 100644 --- a/src/errors.c +++ b/src/errors.c @@ -1,8 +1,9 @@ #include "errors.h" -#include +#include #include #include +#include #define MAX_STR_LEN 128 diff --git a/src/errors.h b/src/errors.h index 2ad27d4..9413072 100644 --- a/src/errors.h +++ b/src/errors.h @@ -1,6 +1,7 @@ #pragma once +#include -typedef unsigned char ErrorCode; +typedef uint8_t ErrorCode; enum { SUCCESS = 0, FAILURE = -1, diff --git a/src/game/level.c b/src/game/level.c index d968a42..cae0f4a 100644 --- a/src/game/level.c +++ b/src/game/level.c @@ -1,11 +1,14 @@ #include "level.h" -#include +#include +#include #include +#include #include "../constants.h" #include "../main.h" -#include "../window/renderer.h" +#include "../window/audio.h" +#include "../window/colour.h" #include "vector2.h" @@ -49,7 +52,7 @@ void level_init(Level* level) { } // updates the player's "bouncer" -static void update_player(Bouncer* bouncer, Ball* ball, const Uint8* keys) { +static void update_player(Bouncer* bouncer, Ball* ball, const uint8_t* keys) { // if move bouncer LEFT if (keys[SDL_SCANCODE_A] || keys[SDL_SCANCODE_LEFT]) { if (((bouncer->pos.x) < 0) == false) { @@ -150,7 +153,7 @@ static void update_ball(Level* level, Ball* ball, Bouncer* bouncer) { } // updates the level -void level_update(Level* level, const Uint8* keys) { +void level_update(Level* level, const uint8_t* keys) { Bouncer* bouncer = &level->bouncer; Ball* ball = &level->ball; diff --git a/src/game/level.h b/src/game/level.h index 2fdb71b..c04f422 100644 --- a/src/game/level.h +++ b/src/game/level.h @@ -1,22 +1,22 @@ #pragma once -#include #include +#include #include "../constants.h" -#include "../window/colour.h" #include "../window/audio.h" +#include "../window/colour.h" #include "vector2.h" typedef struct { Vector2 pos; Vector2 direction; - unsigned size; + uint32_t size; bool moving; } Ball; typedef struct { Vector2 pos; - unsigned width; + uint32_t width; } Bouncer; typedef struct { @@ -35,4 +35,4 @@ typedef struct { void level_init(Level* level); -void level_update(Level* level, const Uint8* keys); +void level_update(Level* level, const uint8_t* keys); diff --git a/src/main.c b/src/main.c index ea0e337..2528f74 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,16 @@ #include "main.h" -#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include +#include #include #include "errors.h" @@ -74,6 +82,8 @@ void stop(void) { // entry point of the application int main(int argc, char** argv) { + (void)argc; + (void)argv; init(); #if __EMSCRIPTEN__ diff --git a/src/window/audio.c b/src/window/audio.c index 985142d..303bc7d 100644 --- a/src/window/audio.c +++ b/src/window/audio.c @@ -1,6 +1,11 @@ #include "audio.h" -#include +#include +#include +#include +#include +#include +#include #include "../errors.h" @@ -13,19 +18,19 @@ typedef struct { } AudioCallbackData; // audio callback from SDL_AudioSpec; called when the audio device needs more data -static void audio_mixer(void* userdata, Uint8* stream, int len) { +static void audio_mixer(void* userdata, uint8_t* stream, int32_t len) { memset(stream, 0, len); // clear the playing audio AudioDevice* device = userdata; // get the callback data AudioData* audio = device->playing_audio; - for (int i = 0; i < MAX_SOUNDS; i++) { + for (int32_t i = 0; i < MAX_SOUNDS; i++) { // skip if the audio doesn't conain any further data if (audio[i].length <= 0) { continue; } // get the length of which we shall be mixing - Uint32 mix_length = SDL_min(audio[i].length, len); + uint32_t mix_length = SDL_min(audio[i].length, len); // mix the audio with the stream SDL_MixAudioFormat(stream, audio[i].buffer, device->format, mix_length, SDL_MIX_MAXVOLUME); @@ -35,14 +40,15 @@ static void audio_mixer(void* userdata, Uint8* stream, int len) { } // converts the audio to the format of the audio device -static void convert_audio(const AudioDevice* audio_device, const SDL_AudioSpec wav_spec, Uint8** wav_buffer, Uint32* wav_length) { +static void convert_audio(const AudioDevice* audio_device, const SDL_AudioSpec wav_spec, uint8_t** wav_buffer, uint32_t* wav_length) { // build the audio converter with the audio given SDL_AudioCVT cvt = {0}; SDL_BuildAudioCVT(&cvt, wav_spec.format, wav_spec.channels, wav_spec.freq, audio_device->format, audio_device->channels, audio_device->freq); - cvt.len = (*wav_length) * wav_spec.channels; // the buffer length - cvt.buf = (Uint8*)SDL_malloc(cvt.len * cvt.len_mult); // allocate size for the new buffer - memcpy(cvt.buf, *wav_buffer, *wav_length); // copy wav data to cvt buffer; + // suddenly becomes signed + cvt.len = (*wav_length) * wav_spec.channels; // the buffer length + cvt.buf = (uint8_t*)SDL_malloc(cvt.len * cvt.len_mult); // allocate size for the new buffer + memcpy(cvt.buf, *wav_buffer, *wav_length); // copy wav data to cvt buffer; // convert SDL_ConvertAudio(&cvt); @@ -61,12 +67,13 @@ AudioData audio_load_wav(const AudioDevice* audio_device, const char* file_path) SDL_LoadWAV(file_path, &wav_spec, &audio.buffer, &audio.length); convert_audio(audio_device, wav_spec, &audio.buffer, &audio.length); + audio.mixed_amount = audio.length; return audio; } // initializes the audio device -AudioDevice* audio_device_init(const int freq, const SDL_AudioFormat format, const Uint8 channels, const Uint16 samples) { +AudioDevice* audio_device_init(const int32_t freq, const SDL_AudioFormat format, const uint8_t channels, const uint16_t samples) { // allocate memory for the audio device AudioDevice* audio_device = malloc(sizeof(AudioDevice)); @@ -99,7 +106,7 @@ AudioDevice* audio_device_init(const int freq, const SDL_AudioFormat format, con void audio_play(const AudioDevice* audio_device, const AudioData audio) { AudioData* playing_audio = audio_device->playing_audio; - for (int i = 0; i < MAX_SOUNDS; i++) { + for (int32_t i = 0; i < MAX_SOUNDS; i++) { // overrite audio that has been deallocated if (playing_audio[i].length <= 0) { // override the audio diff --git a/src/window/audio.h b/src/window/audio.h index 3a03b7b..215bf35 100644 --- a/src/window/audio.h +++ b/src/window/audio.h @@ -1,20 +1,23 @@ #pragma once -#include + +#include +#include typedef struct { - Uint32 length; - Uint8* buffer; + uint32_t length; + uint32_t mixed_amount; + uint8_t* buffer; } AudioData; typedef struct { SDL_AudioDeviceID id; - int freq; + int32_t freq; SDL_AudioFormat format; - Uint8 channels; + uint8_t channels; AudioData* playing_audio; } AudioDevice; AudioData audio_load_wav(const AudioDevice* audio_device, const char* file_path); -AudioDevice* audio_device_init(const int freq, const SDL_AudioFormat format, const Uint8 channels, const Uint16 samples); +AudioDevice* audio_device_init(const int freq, const SDL_AudioFormat format, const uint8_t channels, const uint16_t samples); void audio_play(const AudioDevice* audio_device, const AudioData audio); diff --git a/src/window/colour.h b/src/window/colour.h index 756bec9..2e47924 100644 --- a/src/window/colour.h +++ b/src/window/colour.h @@ -1,9 +1,12 @@ +#pragma once +#include + typedef union { unsigned packed; struct { - unsigned char a; - unsigned char b; - unsigned char g; - unsigned char r; + uint8_t a; + uint8_t b; + uint8_t g; + uint8_t r; }; } Colour; diff --git a/src/window/renderer.c b/src/window/renderer.c index 22deee6..75769a1 100644 --- a/src/window/renderer.c +++ b/src/window/renderer.c @@ -1,12 +1,18 @@ #include "renderer.h" -#include +#include +#include +#include +#include +#include #include #include "../constants.h" #include "../errors.h" #include "../game/level.h" + + // initializes the window and renderer int renderer_init(SDL_Window** window, SDL_Renderer** renderer) { // init the window diff --git a/src/window/renderer.h b/src/window/renderer.h index 8368eed..7c29722 100644 --- a/src/window/renderer.h +++ b/src/window/renderer.h @@ -1,6 +1,7 @@ #pragma once -#include +#include +#include #include "../game/level.h"