Delete src/rewrite.c
This commit is contained in:
-111
@@ -1,111 +0,0 @@
|
|||||||
#include "tetris.h"
|
|
||||||
|
|
||||||
// initalize sdl
|
|
||||||
void sdlGameInit(GameInit *game){
|
|
||||||
|
|
||||||
// ensure sdl loads flags
|
|
||||||
if(!SDL_Init(SDL_FLAGS)){
|
|
||||||
safeError("error in sdl init\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// create window and check if it exists
|
|
||||||
game->window = SDL_CreateWindow(WindowTitle, width, height, 0);
|
|
||||||
if(!game->window){
|
|
||||||
safeError("error in creating window\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the renderer and check if it exits
|
|
||||||
game->renderer = SDL_CreateRenderer(game->window, NULL);
|
|
||||||
if(!game->renderer){
|
|
||||||
safeError("error in creating renderer\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// clean up and removal
|
|
||||||
void sdlGameFree(GameInit **gameInit){
|
|
||||||
|
|
||||||
// check to see if the pointer to gameinit exists
|
|
||||||
if(!*gameInit){
|
|
||||||
safeError("null pointer where value is expected\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the pointer for game from gameinit
|
|
||||||
GameInit *game = *gameInit;
|
|
||||||
|
|
||||||
// kill prosseses
|
|
||||||
if(game->window){
|
|
||||||
SDL_DestroyWindow(game->window);
|
|
||||||
game->window = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(game->renderer){
|
|
||||||
SDL_DestroyRenderer(game->renderer);
|
|
||||||
game->renderer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// quit the renderer and clean up pointers
|
|
||||||
SDL_Quit();
|
|
||||||
free(game);
|
|
||||||
game = NULL;
|
|
||||||
*gameInit = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create game context
|
|
||||||
void gameCreateContext(GameInit **gameInit){
|
|
||||||
|
|
||||||
*gameInit = calloc(1, sizeof(gameInit));
|
|
||||||
if(*gameInit == NULL){
|
|
||||||
safeError("failed to allocate pointer\n");
|
|
||||||
}
|
|
||||||
GameInit *game = *gameInit;
|
|
||||||
sdlGameInit(game);
|
|
||||||
|
|
||||||
game->isRunning = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// the code for drawing shit to the screen
|
|
||||||
void gameDrawContext(GameInit *game){
|
|
||||||
SDL_RenderClear(game->renderer);
|
|
||||||
SDL_RenderPresent(game->renderer);
|
|
||||||
SDL_Delay(16);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get events from the game
|
|
||||||
void gameEventCheck(GameInit *game){
|
|
||||||
while(SDL_PollEvent(&game->event)){
|
|
||||||
switch(game->event.type){
|
|
||||||
|
|
||||||
case SDL_EVENT_QUIT:
|
|
||||||
game->isRunning = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// game loop handle logic and frames
|
|
||||||
void gameLoop(GameInit *game){
|
|
||||||
while(game->isRunning){
|
|
||||||
|
|
||||||
gameEventCheck(game);
|
|
||||||
gameDrawContext(game);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// entry point and declerations
|
|
||||||
int main(void){
|
|
||||||
GameInit *gamePoint = NULL;
|
|
||||||
|
|
||||||
gameCreateContext(&gamePoint);
|
|
||||||
gameLoop(gamePoint);
|
|
||||||
|
|
||||||
sdlGameFree(&gamePoint);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user