Click Events, added Image and Text libraries (included), working prototype

This commit is contained in:
Michael Chen 2018-01-10 15:37:55 +01:00
parent 89a745882e
commit ff3c1a5333
5 changed files with 44 additions and 8 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ sdl2-config
*.psd *.psd
*.exe *.exe
!bhi.exe !bhi.exe
.tags*

View File

@ -1,4 +1,4 @@
libs = -lmingw32 -lSDL2main -lSDL2 -lopengl32 libs = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lSDL2_image -lSDL2_ttf
includes = -I".\include" includes = -I".\include"
compiler = gcc compiler = gcc
warningLevel = -Wall warningLevel = -Wall

View File

@ -5,12 +5,34 @@
#include <SDL2/SDL_image.h> #include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h> #include <SDL2/SDL_ttf.h>
#include "breakout.h"
#include "vector.h" #include "vector.h"
#ifndef __nullptr__ #ifndef __nullptr__
#define Nullptr(type) (type *)0 #define Nullptr(type) (type *)0
#endif // __nullptr__ #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");
}

View File

@ -26,7 +26,10 @@ typedef struct powerupStruct { // Maybe implement later
// End Structs // End Structs
// Prototypes // 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 // End Prototypes
#endif // __breakout_h__ #endif // __breakout_h__

20
main.c
View File

@ -7,6 +7,7 @@
#include <SDL2/SDL_image.h> #include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h> #include <SDL2/SDL_ttf.h>
#include "breakout.h"
#include "vector.h" #include "vector.h"
#ifndef __nullptr__ #ifndef __nullptr__
@ -31,10 +32,12 @@ SDL_Renderer * renderer;
SDL_Event event; SDL_Event event;
bool running = true, fullscreen = false; bool running = true, fullscreen = false;
Ball ball;
int main(int argc, char * args[]){ int main(int argc, char * args[]){
system("bhi.exe"); // system("bhi.exe");
INITIALIZE(); INITIALIZE();
while (running) { while (running) { // Gameloop
GAMELOOP(); GAMELOOP();
DrawFrame(); DrawFrame();
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
@ -65,7 +68,7 @@ void GAMELOOP() {
void mousePress(SDL_MouseButtonEvent b){ // Debug prop void mousePress(SDL_MouseButtonEvent b){ // Debug prop
if (b.button == SDL_BUTTON_LEFT) { 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) { } else if (b.button == SDL_BUTTON_RIGHT) {
printf("Right mouse pressed...\n"); printf("Right mouse pressed...\n");
} else { } else {
@ -100,7 +103,10 @@ void windowChanged(SDL_WindowEvent b){ // Debug prop
void DrawFrame(){ void DrawFrame(){
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); 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); SDL_RenderPresent(renderer);
} }
@ -109,6 +115,9 @@ void INITIALIZE() {
srand(time(NULL)); srand(time(NULL));
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); 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"); 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); window = SDL_CreateWindow("BreakING", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
SDL_SetWindowResizable(window, true); SDL_SetWindowResizable(window, true);
@ -120,7 +129,8 @@ void INITIALIZE() {
void QUIT(){ void QUIT(){
printf("De-initializing started...\n"); printf("De-initializing started...\n");
free(keystate); free(keystate);
// IMG_Quit(); TTF_Quit();
IMG_Quit();
printf("Quitting SDL_IMG finished!\n"); printf("Quitting SDL_IMG finished!\n");
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
printf("De-initializing renderer finished!\n"); printf("De-initializing renderer finished!\n");