Code Cleaning, todos added
This commit is contained in:
parent
7cc0621aa5
commit
1b53c9f862
2
Makefile
2
Makefile
@ -1,3 +1,5 @@
|
|||||||
all:
|
all:
|
||||||
gcc -Wall -IC:\SDL2\x32\include *.c -LC:\SDL2\x32\lib -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lSDL2_image -lSDL2_ttf -o Asteroids.exe
|
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
|
Asteroids.exe
|
||||||
|
100
main.c
100
main.c
@ -21,12 +21,12 @@ void QUIT();
|
|||||||
void GAMELOOP();
|
void GAMELOOP();
|
||||||
void mousePress(SDL_MouseButtonEvent b);
|
void mousePress(SDL_MouseButtonEvent b);
|
||||||
|
|
||||||
const int width = 1600;
|
const int width = 1600; // TODO: Fullscreen
|
||||||
const int height = 900;
|
const int height = 900;
|
||||||
const int totalAsteroidCount = 6;
|
const int totalAsteroidCount = 6;
|
||||||
const int totalEnemyCount = 6;
|
const int totalEnemyCount = 6;
|
||||||
|
|
||||||
Uint8 * keystate;
|
Uint8 * keystate; // TODO: export all this into scenery and enemy waves
|
||||||
SDL_Window * window;
|
SDL_Window * window;
|
||||||
SDL_Renderer * renderer;
|
SDL_Renderer * renderer;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
@ -55,6 +55,9 @@ int main(int argc, char * args[]){
|
|||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) running = false;
|
if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) running = false;
|
||||||
break;
|
break;
|
||||||
|
case SDL_MouseButtonEvent:
|
||||||
|
mousePress(event.button);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,34 +65,29 @@ int main(int argc, char * args[]){
|
|||||||
return 0;
|
return 0;
|
||||||
} /* main */
|
} /* main */
|
||||||
|
|
||||||
void QUIT(){
|
void GAMELOOP() {
|
||||||
printf("De-initializing started...\n");
|
keystate = SDL_GetKeyboardState(NULL); // Get key changes
|
||||||
free(keystate);
|
SHIP_Update(&ship, keystate, asteroids, &asteroidCount, enemies, &enemyCount);
|
||||||
SDL_FreeSurface(messageSurface);
|
|
||||||
SDL_DestroyTexture(messageTexture);
|
|
||||||
SHIP_DestroyObject(&ship);
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < enemyCount; 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(){
|
void DrawFrame(){
|
||||||
@ -148,28 +146,32 @@ void INITIALIZE() {
|
|||||||
}
|
}
|
||||||
} /* INITIALIZE */
|
} /* INITIALIZE */
|
||||||
|
|
||||||
void GAMELOOP() {
|
void QUIT(){
|
||||||
keystate = SDL_GetKeyboardState(NULL); // Get key changes
|
printf("De-initializing started...\n");
|
||||||
SHIP_Update(&ship, keystate, asteroids, &asteroidCount, enemies, &enemyCount);
|
free(keystate);
|
||||||
|
SDL_FreeSurface(messageSurface);
|
||||||
|
SDL_DestroyTexture(messageTexture);
|
||||||
|
SHIP_DestroyObject(&ship);
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < enemyCount; i++) {
|
for (i = 0; i < enemyCount; i++) {
|
||||||
ENEMY_Update(&(enemies[i]), &ship, 1);
|
ENEMY_DestroyObject(&(enemies[i]));
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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){
|
void STARFIELD_Draw(Starfield * strf, SDL_Renderer * renderer){
|
||||||
printf("Drawing starfield...\n");
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < (strf->StarCount); i++) {
|
for (i = 0; i < (strf->StarCount); i++) {
|
||||||
STAR_Draw(&((strf->Stars)[i]), renderer);
|
STAR_Draw(&((strf->Stars)[i]), renderer);
|
||||||
}
|
}
|
||||||
printf("Starfield drawn!\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void STARFIELD_Update(Starfield * strf){
|
void STARFIELD_Update(Starfield * strf){
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < (strf->StarCount); i++) {
|
for (i = 0; i < (strf->StarCount); i++) {
|
||||||
STAR_Update(&((strf->Stars)[i]));
|
STAR_Update(&((strf->Stars)[i]));
|
||||||
}
|
}
|
||||||
|
1
vector.c
1
vector.c
@ -20,6 +20,7 @@ double vectorMagnitude(Vector v){
|
|||||||
|
|
||||||
double vectorRotation(Vector v){
|
double vectorRotation(Vector v){
|
||||||
double da = atan2(v.x, -v.y) / degreeToRadians;
|
double da = atan2(v.x, -v.y) / degreeToRadians;
|
||||||
|
|
||||||
if (da < 0.0f) return (da + 360.0f);
|
if (da < 0.0f) return (da + 360.0f);
|
||||||
else return da;
|
else return da;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user