diff --git a/bin/System.Web.Helpers.dll b/bin/System.Web.Helpers.dll new file mode 100644 index 0000000..be23db7 Binary files /dev/null and b/bin/System.Web.Helpers.dll differ diff --git a/bin/bhi.exe b/bin/bhi.exe index a9e5451..0008cb1 100644 Binary files a/bin/bhi.exe and b/bin/bhi.exe differ diff --git a/breakout.c b/breakout.c index 46c1bae..09a6619 100644 --- a/breakout.c +++ b/breakout.c @@ -24,15 +24,26 @@ SDL_Rect * PADDLE_SourceRects; Uint8 * PADDLE_MoveLeftKeys, * PADDLE_MoveRightKeys; double BALL_Speed = 10.0f; int PADDLE_Speed = 10; +bool BREAKOUT_IsInit = false; +bool BALL_IsInit = false; +bool PADDLE_IsInit = false; void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height){ - printf("Initializing Game...\n"); - srand(time(NULL)); + if (!BREAKOUT_IsInit) { + printf("Initializing Game...\n"); + srand(time(NULL)); + BREAKOUT_BoxWidth = width; + BREAKOUT_BoxHeight = height; + BALL_Initialize(renderer); + PADDLE_Initialize(renderer); + printf("Game initialized!\n"); + BREAKOUT_IsInit = true; + } else printf("Game is already initialized!\n"); +} + +void BREAKOUT_ChangeSize(int width, int height){ BREAKOUT_BoxWidth = width; BREAKOUT_BoxHeight = height; - BALL_Initialize(renderer); - PADDLE_Initialize(renderer); - printf("Game initialized!\n"); } void BREAKOUT_Update(Uint8 * keystate){ @@ -46,21 +57,28 @@ void BREAKOUT_Draw(SDL_Renderer * renderer){ } void BREAKOUT_DEINITIALIZE(){ - printf("De-initializing Game...\n"); - SDL_DestroyTexture(BALL_Texture); - printf("Game de-initialized!\n"); + if (BREAKOUT_IsInit) { + printf("De-initializing Game...\n"); + SDL_DestroyTexture(BALL_Texture); + SDL_DestroyTexture(PADDLE_Texture); + printf("Game de-initialized!\n"); + BREAKOUT_IsInit = false; + } else printf("Game is already de-initialized!\n"); } void BALL_Initialize(SDL_Renderer * renderer){ - printf("Initializing Ball...\n"); - BALL_Texture = IMG_LoadTexture(renderer, "assets/images/ball.png"); - if (!BALL_Texture) printf("Ball texture failed to load!\n"); - BALL_SourceRects = (SDL_Rect *)malloc(1 * sizeof(SDL_Rect)); - if (!BALL_SourceRects) printf("FATAL! Memory allocation failed!\n"); - BALL_SourceRects[0] = (SDL_Rect) {.x = 0, .y = 0, .w = 512, .h = 512 }; - ball = BALL_CreateDefault(); - paddle = PADDLE_CreateDefault(); - printf("Ball initialized!\n"); + if (!BALL_IsInit) { + printf("Initializing Ball...\n"); + BALL_Texture = IMG_LoadTexture(renderer, "assets/images/ball.png"); + if (!BALL_Texture) printf("Ball texture failed to load!\n"); + BALL_SourceRects = (SDL_Rect *)malloc(1 * sizeof(SDL_Rect)); + if (!BALL_SourceRects) printf("FATAL! Memory allocation failed!\n"); + BALL_SourceRects[0] = (SDL_Rect) {.x = 0, .y = 0, .w = 512, .h = 512 }; + ball = BALL_CreateDefault(); + paddle = PADDLE_CreateDefault(); + printf("Ball initialized!\n"); + BALL_IsInit = true; + } else printf("Ball is already initialized!\n"); } Ball BALL_CreateDefault(){ @@ -149,32 +167,38 @@ void BALL_Update(Ball * obj, Paddle * paddle){ void BALL_DestroyObject(Ball * obj){ } void BALL_Deinitialize(){ - printf("De-initializing Ball...\n"); + if (BALL_IsInit) { + printf("De-initializing Ball...\n"); - printf("Ball de-initialized!\n"); + printf("Ball de-initialized!\n"); + BALL_IsInit = false; + } else printf("Ball is already de-initialized!\n"); } void PADDLE_Initialize(SDL_Renderer * renderer){ - printf("Initializing Paddle...\n"); - PADDLE_Texture = IMG_LoadTexture(renderer, "assets/images/paddle.png"); - if (!PADDLE_Texture) printf("Paddle texture failed to load!\n"); - PADDLE_SourceRects = (SDL_Rect *)malloc(1 * sizeof(SDL_Rect)); - if (!PADDLE_SourceRects) printf("FATAL! Memory allocation failed!\n"); - PADDLE_SourceRects[0] = (SDL_Rect) {.x = 0, .y = 0, .w = 512, .h = 512 }; - PADDLE_MoveLeftKeys = (Uint8 *)malloc(2 * sizeof(Uint8)); - if (!PADDLE_MoveLeftKeys) printf("FATAL! Memory allocation failed!\n"); - PADDLE_MoveRightKeys = (Uint8 *)malloc(2 * sizeof(Uint8)); - if (!PADDLE_MoveRightKeys) printf("FATAL! Memory allocation failed!\n"); - PADDLE_MoveLeftKeys[0] = 2; // Erster wert gibt größe des arrays an - PADDLE_MoveLeftKeys[1] = SDL_SCANCODE_LEFT; - PADDLE_MoveLeftKeys[2] = SDL_SCANCODE_A; - PADDLE_MoveRightKeys[0] = 2; - PADDLE_MoveRightKeys[1] = SDL_SCANCODE_RIGHT; - PADDLE_MoveRightKeys[2] = SDL_SCANCODE_D; - ball = BALL_CreateDefault(); - printf("Paddle initialized!\n"); -} + if (!PADDLE_IsInit) { + printf("Initializing Paddle...\n"); + PADDLE_Texture = IMG_LoadTexture(renderer, "assets/images/paddle.png"); + if (!PADDLE_Texture) printf("Paddle texture failed to load!\n"); + PADDLE_SourceRects = (SDL_Rect *)malloc(1 * sizeof(SDL_Rect)); + if (!PADDLE_SourceRects) printf("FATAL! Memory allocation failed!\n"); + PADDLE_SourceRects[0] = (SDL_Rect) {.x = 0, .y = 0, .w = 512, .h = 512 }; + PADDLE_MoveLeftKeys = (Uint8 *)malloc(2 * sizeof(Uint8)); + if (!PADDLE_MoveLeftKeys) printf("FATAL! Memory allocation failed!\n"); + PADDLE_MoveRightKeys = (Uint8 *)malloc(2 * sizeof(Uint8)); + if (!PADDLE_MoveRightKeys) printf("FATAL! Memory allocation failed!\n"); + PADDLE_MoveLeftKeys[0] = 2; // Erster wert gibt größe des arrays an + PADDLE_MoveLeftKeys[1] = SDL_SCANCODE_LEFT; + PADDLE_MoveLeftKeys[2] = SDL_SCANCODE_A; + PADDLE_MoveRightKeys[0] = 2; + PADDLE_MoveRightKeys[1] = SDL_SCANCODE_RIGHT; + PADDLE_MoveRightKeys[2] = SDL_SCANCODE_D; + ball = BALL_CreateDefault(); + printf("Paddle initialized!\n"); + PADDLE_IsInit = true; + } else printf("Paddle is already initialized!\n"); +} /* PADDLE_Initialize */ Paddle PADDLE_CreateDefault(){ int defaultpaddlewidth = 300; @@ -217,7 +241,10 @@ void PADDLE_Update(Paddle * obj, Uint8 * keystate){ void PADDLE_DestroyObject(Paddle * obj){ } void PADDLE_Deinitialize(){ - printf("De-initializing Ball...\n"); + if (PADDLE_IsInit) { + printf("De-initializing Paddle...\n"); - printf("Ball de-initialized!\n"); + printf("Paddle de-initialized!\n"); + PADDLE_IsInit = false; + } else printf("Paddle is already de-initialized!\n"); } diff --git a/breakout.h b/breakout.h index 176157f..82fec60 100644 --- a/breakout.h +++ b/breakout.h @@ -31,6 +31,7 @@ typedef struct blockStruct { // Prototypes void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height); +void BREAKOUT_ChangeSize(int width, int height); void BREAKOUT_Update(Uint8 * keystate); void BREAKOUT_Draw(SDL_Renderer * renderer); void BREAKOUT_DEINITIALIZE(); diff --git a/main.c b/main.c index 47ca155..e286a30 100644 --- a/main.c +++ b/main.c @@ -79,7 +79,7 @@ void mousePress(SDL_MouseButtonEvent b){ // Debug prop void keyPress(SDL_KeyboardEvent b){ // Debug prop printf("Key pressed: ID is %d\n", b.keysym.scancode); - if (b.keysym.scancode == SDL_SCANCODE_F11) { + if (b.keysym.scancode == SDL_SCANCODE_F11 || b.keysym.scancode == SDL_SCANCODE_5) { toggleFullscreen(); } } @@ -97,6 +97,7 @@ void windowChanged(SDL_WindowEvent b){ // Debug prop switch (b.event) { case SDL_WINDOWEVENT_SIZE_CHANGED: printf("Window was resized to (%d|%d)!\n", event.window.data1, event.window.data2); + BREAKOUT_ChangeSize(event.window.data1, event.window.data2); break; } }