Fullscreen now supported (absolute, not scaled)

This commit is contained in:
Michael Chen 2018-01-11 18:45:00 +01:00
parent b9cd095b1c
commit 77bd1ed996
5 changed files with 70 additions and 41 deletions

BIN
bin/System.Web.Helpers.dll Normal file

Binary file not shown.

Binary file not shown.

View File

@ -24,15 +24,26 @@ SDL_Rect * PADDLE_SourceRects;
Uint8 * PADDLE_MoveLeftKeys, * PADDLE_MoveRightKeys; Uint8 * PADDLE_MoveLeftKeys, * PADDLE_MoveRightKeys;
double BALL_Speed = 10.0f; double BALL_Speed = 10.0f;
int PADDLE_Speed = 10; 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){ void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height){
printf("Initializing Game...\n"); if (!BREAKOUT_IsInit) {
srand(time(NULL)); 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_BoxWidth = width;
BREAKOUT_BoxHeight = height; BREAKOUT_BoxHeight = height;
BALL_Initialize(renderer);
PADDLE_Initialize(renderer);
printf("Game initialized!\n");
} }
void BREAKOUT_Update(Uint8 * keystate){ void BREAKOUT_Update(Uint8 * keystate){
@ -46,21 +57,28 @@ void BREAKOUT_Draw(SDL_Renderer * renderer){
} }
void BREAKOUT_DEINITIALIZE(){ void BREAKOUT_DEINITIALIZE(){
printf("De-initializing Game...\n"); if (BREAKOUT_IsInit) {
SDL_DestroyTexture(BALL_Texture); printf("De-initializing Game...\n");
printf("Game de-initialized!\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){ void BALL_Initialize(SDL_Renderer * renderer){
printf("Initializing Ball...\n"); if (!BALL_IsInit) {
BALL_Texture = IMG_LoadTexture(renderer, "assets/images/ball.png"); printf("Initializing Ball...\n");
if (!BALL_Texture) printf("Ball texture failed to load!\n"); BALL_Texture = IMG_LoadTexture(renderer, "assets/images/ball.png");
BALL_SourceRects = (SDL_Rect *)malloc(1 * sizeof(SDL_Rect)); if (!BALL_Texture) printf("Ball texture failed to load!\n");
if (!BALL_SourceRects) printf("FATAL! Memory allocation failed!\n"); BALL_SourceRects = (SDL_Rect *)malloc(1 * sizeof(SDL_Rect));
BALL_SourceRects[0] = (SDL_Rect) {.x = 0, .y = 0, .w = 512, .h = 512 }; if (!BALL_SourceRects) printf("FATAL! Memory allocation failed!\n");
ball = BALL_CreateDefault(); BALL_SourceRects[0] = (SDL_Rect) {.x = 0, .y = 0, .w = 512, .h = 512 };
paddle = PADDLE_CreateDefault(); ball = BALL_CreateDefault();
printf("Ball initialized!\n"); paddle = PADDLE_CreateDefault();
printf("Ball initialized!\n");
BALL_IsInit = true;
} else printf("Ball is already initialized!\n");
} }
Ball BALL_CreateDefault(){ Ball BALL_CreateDefault(){
@ -149,32 +167,38 @@ void BALL_Update(Ball * obj, Paddle * paddle){
void BALL_DestroyObject(Ball * obj){ void BALL_DestroyObject(Ball * obj){
} }
void BALL_Deinitialize(){ 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){ void PADDLE_Initialize(SDL_Renderer * renderer){
printf("Initializing Paddle...\n"); if (!PADDLE_IsInit) {
PADDLE_Texture = IMG_LoadTexture(renderer, "assets/images/paddle.png"); printf("Initializing Paddle...\n");
if (!PADDLE_Texture) printf("Paddle texture failed to load!\n"); PADDLE_Texture = IMG_LoadTexture(renderer, "assets/images/paddle.png");
PADDLE_SourceRects = (SDL_Rect *)malloc(1 * sizeof(SDL_Rect)); if (!PADDLE_Texture) printf("Paddle texture failed to load!\n");
if (!PADDLE_SourceRects) printf("FATAL! Memory allocation failed!\n"); PADDLE_SourceRects = (SDL_Rect *)malloc(1 * sizeof(SDL_Rect));
PADDLE_SourceRects[0] = (SDL_Rect) {.x = 0, .y = 0, .w = 512, .h = 512 }; if (!PADDLE_SourceRects) printf("FATAL! Memory allocation failed!\n");
PADDLE_MoveLeftKeys = (Uint8 *)malloc(2 * sizeof(Uint8)); PADDLE_SourceRects[0] = (SDL_Rect) {.x = 0, .y = 0, .w = 512, .h = 512 };
if (!PADDLE_MoveLeftKeys) printf("FATAL! Memory allocation failed!\n"); PADDLE_MoveLeftKeys = (Uint8 *)malloc(2 * sizeof(Uint8));
PADDLE_MoveRightKeys = (Uint8 *)malloc(2 * sizeof(Uint8)); if (!PADDLE_MoveLeftKeys) printf("FATAL! Memory allocation failed!\n");
if (!PADDLE_MoveRightKeys) printf("FATAL! Memory allocation failed!\n"); PADDLE_MoveRightKeys = (Uint8 *)malloc(2 * sizeof(Uint8));
PADDLE_MoveLeftKeys[0] = 2; // Erster wert gibt größe des arrays an if (!PADDLE_MoveRightKeys) printf("FATAL! Memory allocation failed!\n");
PADDLE_MoveLeftKeys[1] = SDL_SCANCODE_LEFT; PADDLE_MoveLeftKeys[0] = 2; // Erster wert gibt größe des arrays an
PADDLE_MoveLeftKeys[2] = SDL_SCANCODE_A; PADDLE_MoveLeftKeys[1] = SDL_SCANCODE_LEFT;
PADDLE_MoveRightKeys[0] = 2; PADDLE_MoveLeftKeys[2] = SDL_SCANCODE_A;
PADDLE_MoveRightKeys[1] = SDL_SCANCODE_RIGHT; PADDLE_MoveRightKeys[0] = 2;
PADDLE_MoveRightKeys[2] = SDL_SCANCODE_D; PADDLE_MoveRightKeys[1] = SDL_SCANCODE_RIGHT;
ball = BALL_CreateDefault(); PADDLE_MoveRightKeys[2] = SDL_SCANCODE_D;
printf("Paddle initialized!\n"); ball = BALL_CreateDefault();
} printf("Paddle initialized!\n");
PADDLE_IsInit = true;
} else printf("Paddle is already initialized!\n");
} /* PADDLE_Initialize */
Paddle PADDLE_CreateDefault(){ Paddle PADDLE_CreateDefault(){
int defaultpaddlewidth = 300; int defaultpaddlewidth = 300;
@ -217,7 +241,10 @@ void PADDLE_Update(Paddle * obj, Uint8 * keystate){
void PADDLE_DestroyObject(Paddle * obj){ void PADDLE_DestroyObject(Paddle * obj){
} }
void PADDLE_Deinitialize(){ 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");
} }

View File

@ -31,6 +31,7 @@ typedef struct blockStruct {
// Prototypes // Prototypes
void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height); void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height);
void BREAKOUT_ChangeSize(int width, int height);
void BREAKOUT_Update(Uint8 * keystate); void BREAKOUT_Update(Uint8 * keystate);
void BREAKOUT_Draw(SDL_Renderer * renderer); void BREAKOUT_Draw(SDL_Renderer * renderer);
void BREAKOUT_DEINITIALIZE(); void BREAKOUT_DEINITIALIZE();

3
main.c
View File

@ -79,7 +79,7 @@ void mousePress(SDL_MouseButtonEvent b){ // Debug prop
void keyPress(SDL_KeyboardEvent b){ // Debug prop void keyPress(SDL_KeyboardEvent b){ // Debug prop
printf("Key pressed: ID is %d\n", b.keysym.scancode); 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(); toggleFullscreen();
} }
} }
@ -97,6 +97,7 @@ void windowChanged(SDL_WindowEvent b){ // Debug prop
switch (b.event) { switch (b.event) {
case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT_SIZE_CHANGED:
printf("Window was resized to (%d|%d)!\n", event.window.data1, event.window.data2); printf("Window was resized to (%d|%d)!\n", event.window.data1, event.window.data2);
BREAKOUT_ChangeSize(event.window.data1, event.window.data2);
break; break;
} }
} }