From: Gwyn Ciesla Date: Thu, 4 Jan 2018 23:45:35 +0000 (-0600) Subject: struct to class X-Git-Tag: 1.14~11 X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=50879e596ef0a89fcbe93636e0490e9191d52b2a;p=curblaster.git struct to class Cleanup Refactor sound loading. --- diff --git a/game_object.h b/game_object.h index 87e6b4c..3357f29 100644 --- a/game_object.h +++ b/game_object.h @@ -1,20 +1,21 @@ -struct game_object { - int number; //object number - int active; //object active, 1 or 0 - int x; // x vert position - int y; // y horiz position - int direction; //direction, 10-key numbers 2-4-6-8 default to 5, stationary - int face; // facing 0 left or 1 right, 4 is two-line - int speed; //speed - int vspeed; //fall speed - int vtime; - int xtrail[10]; //x history - int ytrail[10]; //y history - int chase; //the pod a lander is targeting - int phase; //chase phase, also used to hold boss life - char line0[17]; //object: left - char line1[17]; //object: right - char line2[17]; //object: alt1 - char line3[17]; //object: alt2 - char radar[2]; //radar symbol +class game_object { + public: + int number; //object number + int active; //object active, 1 or 0 + int x; // x vert position + int y; // y horiz position + int direction; //direction, 10-key numbers 2-4-6-8 default to 5, stationary + int face; // facing 0 left or 1 right, 4 is two-line + int speed; //speed + int vspeed; //fall speed + int vtime; + int xtrail[10]; //x history + int ytrail[10]; //y history + int chase; //the pod a lander is targeting + int phase; //chase phase, also used to hold boss life + char line0[17]; //object: left + char line1[17]; //object: right + char line2[17]; //object: alt1 + char line3[17]; //object: alt2 + char radar[2]; //radar symbol }; \ No newline at end of file diff --git a/main.cpp b/main.cpp index 72ffc83..b0e62c2 100644 --- a/main.cpp +++ b/main.cpp @@ -26,6 +26,7 @@ along with this program. If not, see . #include #include #include +#include #include "SDL2/SDL.h" #include "SDL2/SDL_mixer.h" @@ -170,7 +171,7 @@ int main(int argc, char *argv[]){ strcpy (gatebeam3.radar, "|"); //pods - struct game_object pods[podmax] = { + game_object pods[podmax] = { { 2, 1, 18, rand()%620, 0, 0, 1, 0, 0 }, { 3, 1, 18, rand()%620, 0, 0, 1, 0, 0 }, { 4, 1, 18, rand()%620, 0, 0, 1, 0, 0 }, @@ -214,7 +215,7 @@ int main(int argc, char *argv[]){ }; //bullets - struct game_object bullets[bulletmax] = { + game_object bullets[bulletmax] = { { 40, 0, 0, 0, 5, 0, 0, 0, 0 }, { 41, 0, 0, 0, 5, 0, 0, 0, 0 }, { 42, 0, 0, 0, 5, 0, 0, 0, 0 }, @@ -233,7 +234,7 @@ int main(int argc, char *argv[]){ }; //landers - struct game_object landers[landermax] = { + game_object landers[landermax] = { { 60, 1, rand()%16, rand()%620, 0, 0, 1, 0, 0 }, { 61, 1, rand()%16, rand()%620, 0, 0, 1, 0, 0 }, { 62, 1, rand()%16, rand()%620, 0, 0, 1, 0, 0 }, @@ -262,7 +263,7 @@ int main(int argc, char *argv[]){ }; //lander shots - struct game_object landershot[landershotmax] = { + game_object landershot[landershotmax] = { { 80, 0, 0, 0, 5, 0, 0, 0, 0 }, { 81, 0, 0, 0, 5, 0, 0, 0, 0 }, { 82, 0, 0, 0, 5, 0, 0, 0, 0 }, @@ -281,7 +282,7 @@ int main(int argc, char *argv[]){ }; //crazies - struct game_object crazies[landermax] = { + game_object crazies[landermax] = { { 90, 0, 0, 0, 6, 0, 1, 0, 0 }, { 91, 0, 0, 0, 4, 0, 1, 0, 0 }, { 92, 0, 0, 0, 6, 0, 1, 0, 0 }, @@ -302,7 +303,7 @@ int main(int argc, char *argv[]){ }; //shield - struct game_object shields[12] = { + game_object shields[12] = { { 110, 1, 0, 0, 5, 0, 1, 0, 0 }, { 111, 1, 0, 0, 5, 0, 1, 0, 0 }, { 112, 1, 0, 0, 5, 0, 1, 0, 0 }, @@ -330,7 +331,7 @@ int main(int argc, char *argv[]){ strcpy (shields[10].line0, ")"); strcpy (shields[11].line0, "("); - struct game_object powerups[4] = { + game_object powerups[4] = { { 130, 0, 0, 0, 6, 0, 1, 0, 0 }, { 131, 0, 0, 0, 4, 0, 1, 0, 0 }, { 132, 0, 0, 0, 6, 0, 1, 0, 0 }, @@ -338,7 +339,7 @@ int main(int argc, char *argv[]){ }; //Reference loops 200-230 - struct game_object refs[31] = { + game_object refs[31] = { { 200, 1, 19, 0, 5, 0, 0, 0, 0 }, { 201, 1, 19, 20, 5, 0, 0, 0, 0 }, { 202, 1, 19, 40, 5, 0, 0, 0, 0 }, @@ -378,7 +379,7 @@ int main(int argc, char *argv[]){ }; //crawlers - struct game_object crawlers[crawlermax] = { + game_object crawlers[crawlermax] = { { 30, 1, 18, rand()%620, 0, 0, 1, 0, 0 }, { 31, 1, 18, rand()%620, 0, 0, 1, 0, 0 }, { 32, 0, 18, rand()%620, 0, 0, 1, 0, 0 }, @@ -398,7 +399,7 @@ int main(int argc, char *argv[]){ strcpy (crawlers[crawlerloop].radar, "^"); }; - struct game_object bosses[6] = { + game_object bosses[6] = { { 300, 0, 0, 0, 5, 4, 0, 0, 0 }, { 301, 0, 0, 0, 5, 4, 0, 0, 0 }, { 302, 0, 0, 0, 5, 4, 0, 0, 0 }, @@ -448,7 +449,7 @@ int main(int argc, char *argv[]){ strcpy (boomstuff.line1, "/"); //missiles - struct game_object missiles[missilemax] = { + game_object missiles[missilemax] = { { 50, 0, 0, 0, 5, 0, 0, 0, 0 }, { 51, 0, 0, 0, 5, 0, 0, 0, 0 }, { 52, 0, 0, 0, 5, 0, 0, 0, 0 } @@ -594,7 +595,7 @@ int main(int argc, char *argv[]){ char *env_tty; env_tty = getenv("SSH_TTY"); - + struct stat datatest; if(env_tty == NULL && sound == 1){ @@ -612,41 +613,28 @@ int main(int argc, char *argv[]){ exit(1); } - if(stat("data/boom.ogg", &datatest)==0){ - shotsound = Mix_LoadWAV("data/shot.ogg"); - boomsound = Mix_LoadWAV("data/boom.ogg"); - dropoffsound = Mix_LoadWAV("data/dropoff.ogg"); - pickupsound = Mix_LoadWAV("data/pickup.ogg"); - lasersound = Mix_LoadWAV("data/laser.ogg"); - warningsound = Mix_LoadWAV("data/warning.ogg"); - pupcreatesound = Mix_LoadWAV("data/pup-create.ogg"); - puptakesound = Mix_LoadWAV("data/pup-take.ogg"); - shieldupsound = Mix_LoadWAV("data/shieldup.ogg"); - shielddownsound = Mix_LoadWAV("data/shielddown.ogg"); - crazifysound = Mix_LoadWAV("data/crazify.ogg"); - enshotsound = Mix_LoadWAV("data/enshot.ogg"); - missilesound = Mix_LoadWAV("data/missile.ogg"); - levelendsound = Mix_LoadWAV("data/level_end.ogg"); - - title = Mix_LoadMUS("data/title_music.ogg"); + std::string path_prefix; + + if(stat("data/boom.ogg", &datatest)==0) { + path_prefix = ""; } else { - shotsound = Mix_LoadWAV("/usr/share/curblaster/data/shot.ogg"); - boomsound = Mix_LoadWAV("/usr/share/curblaster/data/boom.ogg"); - dropoffsound = Mix_LoadWAV("/usr/share/curblaster/data/dropoff.ogg"); - pickupsound = Mix_LoadWAV("/usr/share/curblaster/data/pickup.ogg"); - lasersound = Mix_LoadWAV("/usr/share/curblaster/data/laser.ogg"); - warningsound = Mix_LoadWAV("/usr/share/curblaster/data/warning.ogg"); - pupcreatesound = Mix_LoadWAV("/usr/share/curblaster/data/pup-create.ogg"); - puptakesound = Mix_LoadWAV("/usr/share/curblaster/data/pup-take.ogg"); - shieldupsound = Mix_LoadWAV("/usr/share/curblaster/data/shieldup.ogg"); - shielddownsound = Mix_LoadWAV("/usr/share/curblaster/data/shielddown.ogg"); - crazifysound = Mix_LoadWAV("/usr/share/curblaster/data/crazify.ogg"); - enshotsound = Mix_LoadWAV("/usr/share/curblaster/data/enshot.ogg"); - missilesound = Mix_LoadWAV("/usr/share/curblaster/data/missile.ogg"); - levelendsound = Mix_LoadWAV("/usr/share/curblaster/data/level_end.ogg"); - - title = Mix_LoadMUS("/usr/share/curblaster/data/title_music.ogg"); + path_prefix = "/usr/share/curblaster/"; } + shotsound = Mix_LoadWAV((path_prefix + "data/shot.ogg").c_str()); + boomsound = Mix_LoadWAV((path_prefix + "data/boom.ogg").c_str()); + dropoffsound = Mix_LoadWAV((path_prefix + "data/dropoff.ogg").c_str()); + pickupsound = Mix_LoadWAV((path_prefix + "data/pickup.ogg").c_str()); + lasersound = Mix_LoadWAV((path_prefix + "data/laser.ogg").c_str()); + warningsound = Mix_LoadWAV((path_prefix + "data/warning.ogg").c_str()); + pupcreatesound = Mix_LoadWAV((path_prefix + "data/pup-create.ogg").c_str()); + puptakesound = Mix_LoadWAV((path_prefix + "data/pup-take.ogg").c_str()); + shieldupsound = Mix_LoadWAV((path_prefix + "data/shieldup.ogg").c_str()); + shielddownsound = Mix_LoadWAV((path_prefix + "data/shielddown.ogg").c_str()); + crazifysound = Mix_LoadWAV((path_prefix + "data/crazify.ogg").c_str()); + enshotsound = Mix_LoadWAV((path_prefix + "data/enshot.ogg").c_str()); + missilesound = Mix_LoadWAV((path_prefix + "data/missile.ogg").c_str()); + levelendsound = Mix_LoadWAV((path_prefix + "data/level_end.ogg").c_str()); + title = Mix_LoadMUS((path_prefix + "data/title_music.ogg").c_str()); } else { sound = 0; }