diff --git a/.gitignore b/.gitignore index 37ec167..f8a2da4 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ sdl2-config *.psd *.exe !bhi.exe +.tags* diff --git a/Makefile b/Makefile index 880f1e9..2ae71aa 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -libs = -lmingw32 -lSDL2main -lSDL2 -lopengl32 +libs = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lSDL2_image -lSDL2_ttf includes = -I".\include" compiler = gcc warningLevel = -Wall diff --git a/breakout.c b/breakout.c index c872dff..47a7b3d 100644 --- a/breakout.c +++ b/breakout.c @@ -5,12 +5,34 @@ #include #include +#include "breakout.h" #include "vector.h" #ifndef __nullptr__ #define Nullptr(type) (type *)0 #endif // __nullptr__ -void BREAKOUT_INITIALIZE(){ +int BREAKOUT_BoxWidth, BREAKOUT_BoxHeight; +SDL_Texture * BALL_Texture; + +void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height){ + printf("Initializing Game...\n"); + BREAKOUT_BoxWidth = width; + BREAKOUT_BoxHeight = height; + BALL_Texture = IMG_LoadTexture(renderer, "assets/images/ball.png"); + if (!BALL_Texture) printf("Ball texture cannot be loaded!\n"); + printf("Game initialized!\n"); +} + +void BREAKOUT_GAMELOOP(Uint8 * keystate){ } + +void BALL_DRAW(Ball * ball){ +} + +void BREAKOUT_DEINITIALIZE(SDL_Renderer * renderer, int width, int height){ + printf("De-initializing Game...\n"); + SDL_DestroyTexture(BALL_Texture); + printf("Game de-initialized!\n"); +} diff --git a/breakout.h b/breakout.h index 6c82371..3884d21 100644 --- a/breakout.h +++ b/breakout.h @@ -26,7 +26,10 @@ typedef struct powerupStruct { // Maybe implement later // End Structs // Prototypes - +void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height); +void BREAKOUT_GAMELOOP(Uint8 * keystate); +void BALL_DRAW(Ball * ball); +void BREAKOUT_DEINITIALIZE(SDL_Renderer * renderer, int width, int height); // End Prototypes #endif // __breakout_h__ diff --git a/main.c b/main.c index c1a749b..e451d4e 100644 --- a/main.c +++ b/main.c @@ -7,6 +7,7 @@ #include #include +#include "breakout.h" #include "vector.h" #ifndef __nullptr__ @@ -31,10 +32,12 @@ SDL_Renderer * renderer; SDL_Event event; bool running = true, fullscreen = false; +Ball ball; + int main(int argc, char * args[]){ - system("bhi.exe"); + // system("bhi.exe"); INITIALIZE(); - while (running) { + while (running) { // Gameloop GAMELOOP(); DrawFrame(); while (SDL_PollEvent(&event)) { @@ -65,7 +68,7 @@ void GAMELOOP() { void mousePress(SDL_MouseButtonEvent b){ // Debug prop if (b.button == SDL_BUTTON_LEFT) { - printf("Left mouse pressed...\n"); + printf("Left mouse pressed at %d, %d\n", b.x, b.y); } else if (b.button == SDL_BUTTON_RIGHT) { printf("Right mouse pressed...\n"); } else { @@ -100,7 +103,10 @@ void windowChanged(SDL_WindowEvent b){ // Debug prop void DrawFrame(){ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); - // Draw Game here + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderClear(renderer); + // BALL_DRAW(); + SDL_RenderPresent(renderer); SDL_RenderPresent(renderer); } @@ -109,6 +115,9 @@ void INITIALIZE() { srand(time(NULL)); if (SDL_Init(SDL_INIT_EVERYTHING) != 0) printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); else printf("SDL was successfully initialized!\n"); + if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG) printf("IMG could not initialize! IMG_Error: %s\n", IMG_GetError()); + else printf("IMG was successfully initialized!\n"); + TTF_Init(); window = SDL_CreateWindow("BreakING", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL); SDL_SetWindowResizable(window, true); @@ -120,7 +129,8 @@ void INITIALIZE() { void QUIT(){ printf("De-initializing started...\n"); free(keystate); - // IMG_Quit(); + TTF_Quit(); + IMG_Quit(); printf("Quitting SDL_IMG finished!\n"); SDL_DestroyRenderer(renderer); printf("De-initializing renderer finished!\n");