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,8 +24,12 @@ 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){
if (!BREAKOUT_IsInit) {
printf("Initializing Game...\n"); printf("Initializing Game...\n");
srand(time(NULL)); srand(time(NULL));
BREAKOUT_BoxWidth = width; BREAKOUT_BoxWidth = width;
@ -33,6 +37,13 @@ void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height){
BALL_Initialize(renderer); BALL_Initialize(renderer);
PADDLE_Initialize(renderer); PADDLE_Initialize(renderer);
printf("Game initialized!\n"); 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;
} }
void BREAKOUT_Update(Uint8 * keystate){ void BREAKOUT_Update(Uint8 * keystate){
@ -46,12 +57,17 @@ void BREAKOUT_Draw(SDL_Renderer * renderer){
} }
void BREAKOUT_DEINITIALIZE(){ void BREAKOUT_DEINITIALIZE(){
if (BREAKOUT_IsInit) {
printf("De-initializing Game...\n"); printf("De-initializing Game...\n");
SDL_DestroyTexture(BALL_Texture); SDL_DestroyTexture(BALL_Texture);
SDL_DestroyTexture(PADDLE_Texture);
printf("Game de-initialized!\n"); 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){
if (!BALL_IsInit) {
printf("Initializing Ball...\n"); printf("Initializing Ball...\n");
BALL_Texture = IMG_LoadTexture(renderer, "assets/images/ball.png"); BALL_Texture = IMG_LoadTexture(renderer, "assets/images/ball.png");
if (!BALL_Texture) printf("Ball texture failed to load!\n"); if (!BALL_Texture) printf("Ball texture failed to load!\n");
@ -61,6 +77,8 @@ void BALL_Initialize(SDL_Renderer * renderer){
ball = BALL_CreateDefault(); ball = BALL_CreateDefault();
paddle = PADDLE_CreateDefault(); paddle = PADDLE_CreateDefault();
printf("Ball initialized!\n"); printf("Ball initialized!\n");
BALL_IsInit = true;
} else printf("Ball is already initialized!\n");
} }
Ball BALL_CreateDefault(){ Ball BALL_CreateDefault(){
@ -149,13 +167,17 @@ void BALL_Update(Ball * obj, Paddle * paddle){
void BALL_DestroyObject(Ball * obj){ void BALL_DestroyObject(Ball * obj){
} }
void BALL_Deinitialize(){ void BALL_Deinitialize(){
if (BALL_IsInit) {
printf("De-initializing Ball...\n"); 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){
if (!PADDLE_IsInit) {
printf("Initializing Paddle...\n"); printf("Initializing Paddle...\n");
PADDLE_Texture = IMG_LoadTexture(renderer, "assets/images/paddle.png"); PADDLE_Texture = IMG_LoadTexture(renderer, "assets/images/paddle.png");
if (!PADDLE_Texture) printf("Paddle texture failed to load!\n"); if (!PADDLE_Texture) printf("Paddle texture failed to load!\n");
@ -174,7 +196,9 @@ void PADDLE_Initialize(SDL_Renderer * renderer){
PADDLE_MoveRightKeys[2] = SDL_SCANCODE_D; PADDLE_MoveRightKeys[2] = SDL_SCANCODE_D;
ball = BALL_CreateDefault(); ball = BALL_CreateDefault();
printf("Paddle initialized!\n"); 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;
} }
} }