Code Cleaning, todos added
This commit is contained in:
parent
7cc0621aa5
commit
1b53c9f862
2
Makefile
2
Makefile
@ -1,3 +1,5 @@
|
||||
all:
|
||||
gcc -Wall -IC:\SDL2\x32\include *.c -LC:\SDL2\x32\lib -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lSDL2_image -lSDL2_ttf -o Asteroids.exe
|
||||
|
||||
run:
|
||||
Asteroids.exe
|
||||
|
100
main.c
100
main.c
@ -21,12 +21,12 @@ void QUIT();
|
||||
void GAMELOOP();
|
||||
void mousePress(SDL_MouseButtonEvent b);
|
||||
|
||||
const int width = 1600;
|
||||
const int width = 1600; // TODO: Fullscreen
|
||||
const int height = 900;
|
||||
const int totalAsteroidCount = 6;
|
||||
const int totalEnemyCount = 6;
|
||||
|
||||
Uint8 * keystate;
|
||||
Uint8 * keystate; // TODO: export all this into scenery and enemy waves
|
||||
SDL_Window * window;
|
||||
SDL_Renderer * renderer;
|
||||
SDL_Event event;
|
||||
@ -55,6 +55,9 @@ int main(int argc, char * args[]){
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) running = false;
|
||||
break;
|
||||
case SDL_MouseButtonEvent:
|
||||
mousePress(event.button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -62,34 +65,29 @@ int main(int argc, char * args[]){
|
||||
return 0;
|
||||
} /* main */
|
||||
|
||||
void QUIT(){
|
||||
printf("De-initializing started...\n");
|
||||
free(keystate);
|
||||
SDL_FreeSurface(messageSurface);
|
||||
SDL_DestroyTexture(messageTexture);
|
||||
SHIP_DestroyObject(&ship);
|
||||
void GAMELOOP() {
|
||||
keystate = SDL_GetKeyboardState(NULL); // Get key changes
|
||||
SHIP_Update(&ship, keystate, asteroids, &asteroidCount, enemies, &enemyCount);
|
||||
int i;
|
||||
for (i = 0; i < enemyCount; i++) {
|
||||
ENEMY_DestroyObject(&(enemies[i]));
|
||||
ENEMY_Update(&(enemies[i]), &ship, 1);
|
||||
}
|
||||
STARFIELD_Update(&starfield);
|
||||
if (!(ship.IsDead)) {
|
||||
for (i = 0; i < asteroidCount; i++) {
|
||||
ASTEROID_Update(&(asteroids[i]));
|
||||
}
|
||||
}
|
||||
} /* GAMELOOP */
|
||||
|
||||
void mousePress(SDL_MouseButtonEvent b){
|
||||
if (b.button == SDL_BUTTON_LEFT) {
|
||||
printf("Left mouse pressed...\n");
|
||||
} else if (b.button == SDL_BUTTON_RIGHT) {
|
||||
printf("Right mouse pressed...\n");
|
||||
} else {
|
||||
printf("Unknown mouse button pressed: %d\n", b.button);
|
||||
}
|
||||
free(enemies);
|
||||
STARFIELD_DestroyObject(&starfield);
|
||||
STARFIELD_Deinitialize();
|
||||
SHIP_Deinitialize();
|
||||
ENEMY_Deinitialize();
|
||||
ASTEROID_Deinitialize();
|
||||
TTF_CloseFont(Sans);
|
||||
TTF_Quit();
|
||||
free(asteroids);
|
||||
IMG_Quit();
|
||||
printf("Quitting SDL_IMG finished!\n");
|
||||
SDL_DestroyRenderer(renderer);
|
||||
printf("De-initializing renderer finished!\n");
|
||||
SDL_DestroyWindow(window);
|
||||
printf("De-initializing window finished!\n");
|
||||
SDL_Quit();
|
||||
printf("Quitting SDL finished!\n");
|
||||
printf("De-initializing finished!\n");
|
||||
}
|
||||
|
||||
void DrawFrame(){
|
||||
@ -148,28 +146,32 @@ void INITIALIZE() {
|
||||
}
|
||||
} /* INITIALIZE */
|
||||
|
||||
void GAMELOOP() {
|
||||
keystate = SDL_GetKeyboardState(NULL); // Get key changes
|
||||
SHIP_Update(&ship, keystate, asteroids, &asteroidCount, enemies, &enemyCount);
|
||||
void QUIT(){
|
||||
printf("De-initializing started...\n");
|
||||
free(keystate);
|
||||
SDL_FreeSurface(messageSurface);
|
||||
SDL_DestroyTexture(messageTexture);
|
||||
SHIP_DestroyObject(&ship);
|
||||
int i;
|
||||
for (i = 0; i < enemyCount; i++) {
|
||||
ENEMY_Update(&(enemies[i]), &ship, 1);
|
||||
}
|
||||
STARFIELD_Update(&starfield);
|
||||
if (!(ship.IsDead)) {
|
||||
for (i = 0; i < asteroidCount; i++) {
|
||||
ASTEROID_Update(&(asteroids[i]));
|
||||
}
|
||||
}
|
||||
} /* GAMELOOP */
|
||||
|
||||
void mousePress(SDL_MouseButtonEvent b){
|
||||
return;
|
||||
if (b.button == SDL_BUTTON_LEFT) {
|
||||
printf("Left mouse pressed...\n");
|
||||
} else if (b.button == SDL_BUTTON_RIGHT) {
|
||||
printf("Right mouse pressed...\n");
|
||||
} else {
|
||||
printf("Unknown mouse button pressed: %d\n", b.button);
|
||||
}
|
||||
ENEMY_DestroyObject(&(enemies[i]));
|
||||
}
|
||||
free(enemies);
|
||||
STARFIELD_DestroyObject(&starfield);
|
||||
STARFIELD_Deinitialize();
|
||||
SHIP_Deinitialize();
|
||||
ENEMY_Deinitialize();
|
||||
ASTEROID_Deinitialize();
|
||||
TTF_CloseFont(Sans);
|
||||
TTF_Quit();
|
||||
free(asteroids);
|
||||
IMG_Quit();
|
||||
printf("Quitting SDL_IMG finished!\n");
|
||||
SDL_DestroyRenderer(renderer);
|
||||
printf("De-initializing renderer finished!\n");
|
||||
SDL_DestroyWindow(window);
|
||||
printf("De-initializing window finished!\n");
|
||||
SDL_Quit();
|
||||
printf("Quitting SDL finished!\n");
|
||||
printf("De-initializing finished!\n");
|
||||
} /* QUIT */
|
||||
|
@ -53,16 +53,16 @@ Starfield STARFIELD_GetDefault(int count){
|
||||
}
|
||||
|
||||
void STARFIELD_Draw(Starfield * strf, SDL_Renderer * renderer){
|
||||
printf("Drawing starfield...\n");
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (strf->StarCount); i++) {
|
||||
STAR_Draw(&((strf->Stars)[i]), renderer);
|
||||
}
|
||||
printf("Starfield drawn!\n");
|
||||
}
|
||||
|
||||
void STARFIELD_Update(Starfield * strf){
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (strf->StarCount); i++) {
|
||||
STAR_Update(&((strf->Stars)[i]));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user