From 4115a5656a20590dcb26df8ef24217de7d098d25 Mon Sep 17 00:00:00 2001 From: limb Date: Wed, 3 Jun 2009 17:53:16 +0000 Subject: [PATCH] Modularized all functions and the game_opject structure. git-svn-id: svn+ssh://svn/var/repos/curfender@819 bc5cbbab-a4ec-0310-bb52-ff3d296db539 --- CHANGELOG | 1 + Makefile | 26 +- age_bullet.cpp | 16 ++ age_bullet.h | 1 + check_collision.cpp | 21 ++ check_collision.h | 1 + draw.cpp | 93 +++++++ draw.h | 2 + game_object.h | 20 ++ gravitize.cpp | 13 + gravitize.h | 1 + init.cpp | 76 ++++++ init.h | 5 + main.cpp | 742 ++------------------------------------------------ mishaps.cpp | 112 ++++++++ mishaps.h | 3 + motion.cpp | 296 ++++++++++++++++++++ motion.h | 5 + object_out.cpp | 12 + object_out.h | 1 + play_sound_effect.cpp | 7 + play_sound_effect.h | 1 + powerup.cpp | 49 ++++ powerup.h | 2 + radar_plot.cpp | 52 ++++ radar_plot.h | 1 + 26 files changed, 836 insertions(+), 723 deletions(-) create mode 100644 age_bullet.cpp create mode 100644 age_bullet.h create mode 100644 check_collision.cpp create mode 100644 check_collision.h create mode 100644 draw.cpp create mode 100644 draw.h create mode 100644 game_object.h create mode 100644 gravitize.cpp create mode 100644 gravitize.h create mode 100644 init.cpp create mode 100644 init.h create mode 100644 mishaps.cpp create mode 100644 mishaps.h create mode 100644 motion.cpp create mode 100644 motion.h create mode 100644 object_out.cpp create mode 100644 object_out.h create mode 100644 play_sound_effect.cpp create mode 100644 play_sound_effect.h create mode 100644 powerup.cpp create mode 100644 powerup.h create mode 100644 radar_plot.cpp create mode 100644 radar_plot.h diff --git a/CHANGELOG b/CHANGELOG index 8be8ff7..2e835de 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +Limited number of lives and smartbombs. Boss difficulty scales upward. Merged saucer boss into unified boss system. All objects save bullets explode now, still nonkilling. diff --git a/Makefile b/Makefile index fa4509b..038f894 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,32 @@ CXX = g++ INST = /usr/local/bin -main: main.o - $(CXX) -o curfender main.o -lncurses -lSDL_mixer +main: main.o check_collision.o age_bullet.o gravitize.o radar_plot.o object_out.o motion.o init.o draw.o powerup.o play_sound_effect.o mishaps.o + $(CXX) -o curfender main.o check_collision.o age_bullet.o gravitize.o radar_plot.o object_out.o motion.o init.o draw.o powerup.o play_sound_effect.o mishaps.o -lncurses -lSDL_mixer main.o: main.cpp $(CXX) -g -c main.cpp +check_collision.o: check_collision.cpp check_collision.h + $(CXX) -g -c check_collision.cpp +age_bullet.o: age_bullet.cpp age_bullet.h + $(CXX) -g -c age_bullet.cpp +gravitize.o: gravitize.cpp gravitize.h + $(CXX) -g -c gravitize.cpp +radar_plot.o: radar_plot.cpp radar_plot.h + $(CXX) -g -c radar_plot.cpp +object_out.o: object_out.cpp object_out.h + $(CXX) -g -c object_out.cpp +motion.o: motion.cpp motion.h + $(CXX) -g -c motion.cpp +init.o: init.cpp init.h + $(CXX) -g -c init.cpp +draw.o: draw.cpp draw.h + $(CXX) -g -c draw.cpp +powerup.o: powerup.cpp powerup.h + $(CXX) -g -c powerup.cpp +play_sound_effect.o: play_sound_effect.cpp play_sound_effect.h + $(CXX) -g -c play_sound_effect.cpp +mishaps.o: mishaps.cpp mishaps.h + $(CXX) -g -c mishaps.cpp install: cp curfender $(INST) remove: diff --git a/age_bullet.cpp b/age_bullet.cpp new file mode 100644 index 0000000..0225ff7 --- /dev/null +++ b/age_bullet.cpp @@ -0,0 +1,16 @@ +#include "game_object.h" + +game_object age_bullet(game_object object){ + if(object.vtime>=80){ + object.active = 0; + object.x = 0; + object.y = 0; + object.speed = 0; + object.direction = 0; + object.vtime = 0; + } else { + object.vtime++; + }; + + return object; +}; \ No newline at end of file diff --git a/age_bullet.h b/age_bullet.h new file mode 100644 index 0000000..7880c5f --- /dev/null +++ b/age_bullet.h @@ -0,0 +1 @@ +game_object age_bullet(game_object); \ No newline at end of file diff --git a/check_collision.cpp b/check_collision.cpp new file mode 100644 index 0000000..809c2da --- /dev/null +++ b/check_collision.cpp @@ -0,0 +1,21 @@ +#include + +#include "game_object.h" + +int check_collision(game_object object1, game_object object2){ + int collided = 0; + int spacing = 2; + int vspacing = 0; + if((object1.number>=100&&object1.number<=111)||(object2.number>=100&&object2.number<=111)){ + spacing = 4; + vspacing = 2; + }; + + if(abs(object1.x-object2.x)<=vspacing){ + if(abs(object1.y-object2.y)<=spacing){ + collided=1; + }; + }; + + return collided; +}; \ No newline at end of file diff --git a/check_collision.h b/check_collision.h new file mode 100644 index 0000000..b367f1d --- /dev/null +++ b/check_collision.h @@ -0,0 +1 @@ +int check_collision(game_object, game_object); \ No newline at end of file diff --git a/draw.cpp b/draw.cpp new file mode 100644 index 0000000..c51f6c9 --- /dev/null +++ b/draw.cpp @@ -0,0 +1,93 @@ +#include +#include + +#include "game_object.h" + +int draw_object(game_object object, int drawlocation){ + extern int pod_in; + + if(object.number!=pod_in){ + if(object.number==1){ + if((object.y-drawlocation<35) and (object.direction==4)){ + drawlocation=drawlocation-object.speed; + }; + if((object.y-drawlocation>40) and (object.direction==6)){ + drawlocation=drawlocation+object.speed; + }; + }; + + int offset = 0; + + offset = object.y-drawlocation; + + if(drawlocation>=540&&object.y<620-drawlocation&&object.number!=1){ + offset = 620-drawlocation+object.y; //right of player wrap correction + }; + + if(drawlocation<0&&object.y>=540&&object.number!=1){ + offset = abs(drawlocation)-abs(620-object.y); //left of player wrap correction + }; + + if((object.active==1&&object.x>=1&&object.x<=18&&offset>=0&&offset<=79)||((object.number>=200&&object.number<=230)&&(offset>=0&&offset<=79))){ + if(object.face==0){ + mvprintw(object.x,offset,"%s",object.line0); + } else if(object.face==1){ + mvprintw(object.x,offset,"%s",object.line1); + } else if(object.face==2){ + mvprintw(object.x,offset,"%s",object.line2); + } else if(object.face==3){ + mvprintw(object.x,offset,"%s",object.line3); + } else if(object.face==4){ + mvprintw(object.x,offset,"%s",object.line1); + mvprintw(object.x-1,offset,"%s",object.line0); + } else if(object.face==5){ + mvprintw(object.x,offset,"%s",object.line1); + mvprintw(object.x-1,offset,"%s",object.line0); + } else if(object.face==6){ + mvprintw(object.x,offset,"%s",object.line3); + mvprintw(object.x-1,offset,"%s",object.line2); + }; + }; + + }; + return drawlocation; + +} + +void draw_board(){ + + extern int score, lives, level, shieldsleft; + + // mvprintw(row,col,string,vars) + //top + mvprintw(0,0,"--------------------------------------------------------------------------------\n"); + //bottom + mvprintw(19,0,"--------------------------------------------------------------------------------\n"); + //left side of map + mvprintw(20,16,"|"); + mvprintw(21,16,"|"); + mvprintw(22,16,"|"); + mvprintw(23,16,"|"); + //right side of map + mvprintw(20,79,"|"); + mvprintw(21,79,"|"); + mvprintw(22,79,"|"); + mvprintw(23,79,"|"); + //visible box on map 33, 43 + mvprintw(20,42,"/"); + mvprintw(20,51,"\\"); + mvprintw(23,42,"\\"); + mvprintw(23,51,"/"); + //Score + mvprintw(23,1,"Score:%8d",score); + //Lives + mvprintw(20,1,"Lv:"); + int count = lives; + for(int x=4;count>0;x=x+3){ + mvprintw(20,x,"<=>"); + count--; + }; + //Level + mvprintw(22,1,"Lvl:%3d", level); + mvprintw(22,9,"S:%3d", shieldsleft); +} diff --git a/draw.h b/draw.h new file mode 100644 index 0000000..0cc47a9 --- /dev/null +++ b/draw.h @@ -0,0 +1,2 @@ +int draw_object(game_object, int); +void draw_board(); diff --git a/game_object.h b/game_object.h new file mode 100644 index 0000000..13fc819 --- /dev/null +++ b/game_object.h @@ -0,0 +1,20 @@ +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[1]; //radar symbol +}; \ No newline at end of file diff --git a/gravitize.cpp b/gravitize.cpp new file mode 100644 index 0000000..012a830 --- /dev/null +++ b/gravitize.cpp @@ -0,0 +1,13 @@ +#include "game_object.h" + +game_object gravitize(game_object object){ + + if(object.vspeed<4&&object.vspeed>0&&object.vtime%4==0){ + object.vspeed = object.vspeed + 1; + }; + + object.x = object.x + object.vspeed; + object.vtime++; + + return object; +} \ No newline at end of file diff --git a/gravitize.h b/gravitize.h new file mode 100644 index 0000000..fc40b8b --- /dev/null +++ b/gravitize.h @@ -0,0 +1 @@ +game_object gravitize(game_object); \ No newline at end of file diff --git a/init.cpp b/init.cpp new file mode 100644 index 0000000..dd2e781 --- /dev/null +++ b/init.cpp @@ -0,0 +1,76 @@ +#include + +#include "game_object.h" + +game_object pod_init(game_object pod){ + pod.active=1; + pod.x = 18; //always start on ground + pod.y = rand()%620; //anywhere along the surface + pod.direction = rand()%1000; + if(pod.direction<500){ + pod.direction = 4; + } else { + pod.direction = 6; + }; + pod.speed = 1; + + return pod; +} + +game_object lander_init(game_object lander){ + lander.active=1; + lander.x = rand()%17; + lander.y = rand()%600+20; + lander.direction = rand()%1000; + if(lander.direction<500){ + lander.direction = 4; + } else { + lander.direction = 6; + }; + lander.speed = 1; + + return lander; +} + +game_object crawler_init(game_object crawler){ + crawler.active=1; + crawler.x = 18; + crawler.y = rand()%600+20; + crawler.direction = rand()%1000; + if(crawler.direction<500){ + crawler.direction = 4; + } else { + crawler.direction = 6; + }; + crawler.speed = 1; + + return crawler; +} + +game_object boss_init(game_object boss, int level){ + boss.active=1; + boss.x = rand()%17; + boss.y = rand()%600+20; + boss.direction = rand()%1000; + if(boss.direction<500){ + boss.direction = 4; + } else { + boss.direction = 6; + }; + boss.speed = 1; + boss.phase = level * 5; + + return boss; +} + +game_object player_init(game_object player){ + player.x = 18; + player.y = rand()%600+20; + player.direction = 5; + player.face = 1; + player.speed = 0; + player.vspeed = 0; + player.vtime = 0; + + return player; +} diff --git a/init.h b/init.h new file mode 100644 index 0000000..4873021 --- /dev/null +++ b/init.h @@ -0,0 +1,5 @@ +game_object pod_init(game_object); +game_object lander_init(game_object); +game_object crawler_init(game_object); +game_object boss_init(game_object, int); +game_object player_init(game_object); diff --git a/main.cpp b/main.cpp index 72be101..a0061af 100644 --- a/main.cpp +++ b/main.cpp @@ -29,6 +29,20 @@ along with this program. If not, see . #include "SDL/SDL.h" #include "SDL/SDL_mixer.h" +#include "game_object.h" +#include "check_collision.h" +#include "age_bullet.h" +#include "gravitize.h" +#include "radar_plot.h" +#include "object_out.h" +#include "motion.h" +#include "init.h" +#include "draw.h" +#include "powerup.h" +#include "play_sound_effect.h" +#include "mishaps.h" + + const int podmax = 8; const int bulletmax = 10; const int landershotmax = 10; @@ -47,724 +61,6 @@ int shieldsleft = 400; int tripshot = 0; int laser = 0; int sound = 1; -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[1]; //radar symbol -}; - -int check_collision(game_object object1, game_object object2){ - int collided = 0; - int spacing = 2; - int vspacing = 0; - if((object1.number>=100&&object1.number<=111)||(object2.number>=100&&object2.number<=111)){ - spacing = 4; - vspacing = 2; - }; - - if(abs(object1.x-object2.x)<=vspacing){ - if(abs(object1.y-object2.y)<=spacing){ - collided=1; - }; - }; - - return collided; -}; - -game_object age_bullet(game_object object){ - if(object.vtime>=80){ - object.active = 0; - object.x = 0; - object.y = 0; - object.speed = 0; - object.direction = 0; - object.vtime = 0; - } else { - object.vtime++; - }; - - return object; -}; - -game_object gravitize(game_object object){ - - if(object.vspeed<4&&object.vspeed>0&&object.vtime%4==0){ - object.vspeed = object.vspeed + 1; - }; - - object.x = object.x + object.vspeed; - object.vtime++; - - return object; -} - -void radar_plot(game_object object, int drawlocation){ - - if(object.x>0&&object.y>0&&object.active==1){ - int line = 0; //vert plot pos - int row = 0; //horiz plot pos - int x_offset = 19; //offset for height - int y_offset = 17; //offset for display - - int dl_radar; //main offset - - //set line based on height rules - if(object.x>=1&&object.x<=3){ - line = 1; - } else if(object.x>=4&&object.x<=9){ - line = 2; - } else if(object.x>=10&&object.x<=15){ - line = 3; - } else if(object.x>=16&&object.x<=18){ - line = 4; - } else {line = 0;}; - - //set longitude based on location - div_t quotrem; - quotrem = div(object.y, 10); - row = quotrem.quot; - - //take in radar draw location - div_t dl_quotrem; - dl_quotrem = div(drawlocation, 10); - dl_radar = dl_quotrem.quot; - - //correct to wrap radar - - row = row-dl_radar+25; - - if(row>62){row = row-62;}; - if(row<0){row = row+62;}; - - //add offsets; - - line = line + x_offset; - row = row + y_offset; - - //plot with symbol - mvprintw(line,row,"%s",object.radar); - }; -} - -game_object object_out(game_object object){ - object.active=0; - object.x = -1; - object.y = -1; - object.speed = 0; - object.direction = 0; - object.chase = -1; - object.phase = 0; - return object; -} - -game_object boss_motion(game_object object, game_object player){ - if(player.ytrail[7]object.x){ object.direction = 1; }; - }; - if(player.ytrail[7]>=object.y){ - if(player.xtrail[7]object.x){ object.direction = 3; }; - }; - - return object; -} - -game_object crazy_motion(game_object object, game_object player){ - if(player.ytrail[9]object.x){ object.direction = 1; }; - }; - if(player.ytrail[9]>=object.y){ - if(player.xtrail[9]object.x){ object.direction = 3; }; - }; - - return object; -} - -game_object process_motion(game_object object, game_object player){ - if((object.number>=2)&&(object.number<=9)&&(object.number==pod_in)){ - object.direction=player.direction; - object.speed=player.speed; - object.x=player.x; - object.y=player.y; - } else if(object.number>=100&&object.number<=111){ - object.direction = player.direction; - object.speed = player.speed; - if(object.number==100){ - object.x = player.x-1; - object.y = player.y+1; - }; - if(object.number==101){ - object.x = player.x-1; - object.y = player.y+2; - }; - if(object.number==102){ - object.x = player.x-1; - object.y = player.y+3; - }; - if(object.number==103){ - object.x = player.x+1; - object.y = player.y+1; - }; - if(object.number==104){ - object.x = player.x+1; - object.y = player.y+2; - }; - if(object.number==105){ - object.x = player.x+1; - object.y = player.y+3; - }; - if(object.number==106){ - object.x = player.x-1; - object.y = player.y; - }; - if(object.number==107){ - object.x = player.x+1; - object.y = player.y+4; - }; - if(object.number==108){ - object.x = player.x-1; - object.y = player.y+4; - }; - if(object.number==109){ - object.x = player.x+1; - object.y = player.y; - }; - if(object.number==110){ - object.x = player.x; - object.y = player.y+5; - }; - if(object.number==111){ - object.x = player.x; - object.y = player.y-1; - }; - } else { - if(object.number==1){ - object.xtrail[9]=object.xtrail[8]; - object.xtrail[8]=object.xtrail[7]; - object.xtrail[7]=object.xtrail[6]; - object.xtrail[6]=object.xtrail[5]; - object.xtrail[5]=object.xtrail[4]; - object.xtrail[4]=object.xtrail[3]; - object.xtrail[3]=object.xtrail[2]; - object.xtrail[2]=object.xtrail[1]; - object.xtrail[1]=object.xtrail[0]; - object.xtrail[0]=object.x; - object.ytrail[9]=object.ytrail[8]; - object.ytrail[8]=object.ytrail[7]; - object.ytrail[7]=object.ytrail[6]; - object.ytrail[6]=object.ytrail[5]; - object.ytrail[5]=object.ytrail[4]; - object.ytrail[4]=object.ytrail[3]; - object.ytrail[3]=object.ytrail[2]; - object.ytrail[2]=object.ytrail[1]; - object.ytrail[1]=object.ytrail[0]; - object.ytrail[0]=object.y; - }; - - if(object.direction==9){ - object.y = object.y+object.speed; - object.x = object.x-object.speed; - }; - if(object.direction==8){ - object.x = object.x-object.speed; - }; - if(object.direction==7){ - object.y = object.y-object.speed; - object.x = object.x-object.speed; - }; - if(object.direction==6){ - object.y = object.y+object.speed; - }; - if(object.direction==4){ - object.y = object.y-object.speed; - }; - if(object.direction==3){ - object.y = object.y+object.speed; - object.x = object.x+object.speed; - }; - if(object.direction==2){ - object.x = object.x+object.speed; - }; - if(object.direction==1){ - object.y = object.y-object.speed; - object.x = object.x+object.speed; - }; - - object = gravitize(object); - - //bounds check - if(object.x<=0){ - if(object.number>=80&&object.number<=89){ - object_out(object); - } else { - object.x=1; - object.direction=5; - }; - }; - - if(object.x>=19){ - if(object.number>=80&&object.number<=89){ - object_out(object); - } else { - object.x=18; - object.direction=5; - object.vspeed=0; - object.vtime=0; - }; - }; - - //wrap check - if(object.y<=0){ - object.y=object.y+620; - if(object.number==1){ - drawlocation=drawlocation+620; - }; - }; - if(object.y>=620){ - object.y=object.y-620; - if(object.number==1){ - drawlocation=drawlocation-620; - }; - }; - - if((object.number>=2)&&(object.number<=9)){ - if((object.face>=0)&&(object.face<3)){ - object.face++; - }else{ - object.face=0; - }; - }; - - if((object.number>=11)&&(object.number<=13)){ - if((object.face>=5)&&(object.face<6)){ - object.face++; - }else{ - object.face=5; - }; - }; - - }; - return object; - -} - -game_object pod_init(game_object pod){ - pod.active=1; - pod.x = 18; //always start on ground - pod.y = rand()%620; //anywhere along the surface - pod.direction = rand()%1000; - if(pod.direction<500){ - pod.direction = 4; - } else { - pod.direction = 6; - }; - pod.speed = 1; - - return pod; -} - -game_object lander_init(game_object lander){ - lander.active=1; - lander.x = rand()%17; - lander.y = rand()%600+20; - lander.direction = rand()%1000; - if(lander.direction<500){ - lander.direction = 4; - } else { - lander.direction = 6; - }; - lander.speed = 1; - - return lander; -} - -game_object crawler_init(game_object crawler){ - crawler.active=1; - crawler.x = 18; - crawler.y = rand()%600+20; - crawler.direction = rand()%1000; - if(crawler.direction<500){ - crawler.direction = 4; - } else { - crawler.direction = 6; - }; - crawler.speed = 1; - - return crawler; -} - -game_object boss_init(game_object boss, int level){ - boss.active=1; - boss.x = rand()%17; - boss.y = rand()%600+20; - boss.direction = rand()%1000; - if(boss.direction<500){ - boss.direction = 4; - } else { - boss.direction = 6; - }; - boss.speed = 1; - boss.phase = level * 5; - - return boss; -} - - - -game_object process_direction(game_object object, int input){ - if(input==65){input=8;}; - if(input==67){input=6;}; - if(input==68){input=4;}; - if(input==66){input=2;}; - if(input==69){input=5;}; - if(input==object.direction){ - object.speed++; - } else { - - if(input==4||input==6||input==1||input==7||input==3||input==9){ - if(object.direction!=input){ - object.speed = 0; - } else { - object.speed = 1; - }; - object.direction = input; - - }; - if(input==2){ - object.x++; - if(object.vspeed<4&&object.vspeed>0){ - object.vspeed++; - }; - }; - if(input==8){ - object.x--; - if(object.vspeed>0){ - object.vspeed--; - object.vtime=0; - }; - }; - }; - - if(input==4||input==1||input==7){object.face=0;}; - if(input==6||input==3||input==9){object.face=1;}; - if(object.speed>4){object.speed=4;}; - return object; - -} - -int draw_object(game_object object, int drawlocation){ - if(object.number!=pod_in){ - if(object.number==1){ - if((object.y-drawlocation<35) and (object.direction==4)){ - drawlocation=drawlocation-object.speed; - }; - if((object.y-drawlocation>40) and (object.direction==6)){ - drawlocation=drawlocation+object.speed; - }; - }; - - int offset = 0; - - offset = object.y-drawlocation; - - if(drawlocation>=540&&object.y<620-drawlocation&&object.number!=1){ - offset = 620-drawlocation+object.y; //right of player wrap correction - }; - - if(drawlocation<0&&object.y>=540&&object.number!=1){ - offset = abs(drawlocation)-abs(620-object.y); //left of player wrap correction - }; - - if((object.active==1&&object.x>=1&&object.x<=18&&offset>=0&&offset<=79)||((object.number>=200&&object.number<=230)&&(offset>=0&&offset<=79))){ - if(object.face==0){ - mvprintw(object.x,offset,"%s",object.line0); - } else if(object.face==1){ - mvprintw(object.x,offset,"%s",object.line1); - } else if(object.face==2){ - mvprintw(object.x,offset,"%s",object.line2); - } else if(object.face==3){ - mvprintw(object.x,offset,"%s",object.line3); - } else if(object.face==4){ - mvprintw(object.x,offset,"%s",object.line1); - mvprintw(object.x-1,offset,"%s",object.line0); - } else if(object.face==5){ - mvprintw(object.x,offset,"%s",object.line1); - mvprintw(object.x-1,offset,"%s",object.line0); - } else if(object.face==6){ - mvprintw(object.x,offset,"%s",object.line3); - mvprintw(object.x-1,offset,"%s",object.line2); - }; - }; - - }; - return drawlocation; - -} - -void draw_board(){ - // mvprintw(row,col,string,vars) - //top - mvprintw(0,0,"--------------------------------------------------------------------------------\n"); - //bottom - mvprintw(19,0,"--------------------------------------------------------------------------------\n"); - //left side of map - mvprintw(20,16,"|"); - mvprintw(21,16,"|"); - mvprintw(22,16,"|"); - mvprintw(23,16,"|"); - //right side of map - mvprintw(20,79,"|"); - mvprintw(21,79,"|"); - mvprintw(22,79,"|"); - mvprintw(23,79,"|"); - //visible box on map 33, 43 - mvprintw(20,42,"/"); - mvprintw(20,51,"\\"); - mvprintw(23,42,"\\"); - mvprintw(23,51,"/"); - //Score - mvprintw(23,1,"Score:%8d",score); - //Lives - mvprintw(20,1,"Lv:"); - int count = lives; - for(int x=4;count>0;x=x+3){ - mvprintw(20,x,"<=>"); - count--; - }; - //Level - mvprintw(22,1,"Lvl:%3d", level); - mvprintw(22,9,"S:%3d", shieldsleft); -} - -int play_sound_effect(Mix_Chunk *chunk){ - int channel = Mix_PlayChannel(-1, chunk, 0); - return channel; -}; - -game_object encrazify(game_object lander, game_object crazy, Mix_Chunk *sound, int channel){ - channel = play_sound_effect(sound); - crazy.active=1; - crazy.x = lander.x; - crazy.y = lander.y; - crazy.face = lander.face; - crazy.vspeed = 0; - crazy.vtime = lander.vtime; - crazy.direction = lander.direction; - crazy.speed = 1; - - return crazy; -} - -void boom_object(game_object boomstuff, game_object object, Mix_Chunk *sound, int channel){ - int deathcycle=1; - int loop=1; - boomstuff.active=1; - channel = play_sound_effect(sound); - while(deathcycle<=7){ - for(int boomx=object.x-10;boomx<=object.x+10;boomx++){ - for(int boomy=object.y-10;boomy<=object.y+10;boomy++){ - if(sqrt((abs(object.y-boomy)*abs(object.y-boomy))+(abs(object.x-boomx)*abs(object.x-boomx)))<=deathcycle){ - if(rand()%1000>900){ - boomstuff.x = boomx; - boomstuff.y = boomy; - if(rand()%1000>500){ - boomstuff.face = 0; - } else { - boomstuff.face = 1; - }; - for(int iterations=0;iterations<=loop;iterations++){ - drawlocation = draw_object(boomstuff, drawlocation); - }; - //get the cursor out of the way - mvprintw(23,79,"-"); - refresh(); - }; - }; - }; - }; - deathcycle++; - }; - if(object.number!=1){ - usleep(50000); - }; -} - -int life_loss(int lives, int score){ - if(lives>=1){ - pause_game = 0; - while(pause_game!=' '){ - cbreak(); - mvprintw(10,20,"Boom. Press SPACE to continue.\n"); - pause_game = getch(); - }; - halfdelay(1); - } else { - pause_game = 0; - - //record score if high - - int hscore = 0; - char filename[250]; - char outstring[50]; - strcpy (filename, "/.curfender_scores"); - char home[250]; - strcpy(home, getenv("HOME")); - - strncat(home, filename, 20); - - FILE *scorefile = fopen(home, "r"); - char workchara[6]; - fgets(workchara, 6, scorefile); - hscore = atoi(workchara); - fclose(scorefile); - - if(score>hscore){ - FILE *writescorefile = fopen(home, "w"); - sprintf(outstring, "%d", score); - fputs(outstring, writescorefile); - fclose(writescorefile); - }; - - while(pause_game!=' '){ - cbreak(); - mvprintw(10,20,"GAME OVER. Score:%d Press SPACE to exit.\n", score); - if(score>hscore){ - mvprintw(11,20,"High Score: %s", outstring); - }; - pause_game = getch(); - }; - endwin(); - exit(0); - }; -} - -game_object powerup_init(game_object powerup, game_object object){ - //Call immediately before an object_out - powerup.active = 1; - powerup.x = object.x; - powerup.y = object.y; - if(rand()%1000>=500){ - powerup.direction = 4; - } else { - powerup.direction = 6; - }; - powerup.speed = 1; - - int fodder = rand()%1000; - - if(fodder>=800){ - strcpy (powerup.line0, "T"); - }; - if(fodder>=600&&fodder<800){ - strcpy (powerup.line0, "S"); - }; - if(fodder>=400&&fodder<600){ - strcpy (powerup.line0, "L"); - }; - if(fodder>=200&&fodder<400){ - strcpy (powerup.line0, "B"); - }; - if(fodder<200){ - strcpy (powerup.line0, "Z"); - }; - - return powerup; -}; - -void determine_powerup(game_object powerups[], game_object object, int odds){ - if(rand()%1000>odds){ - for(int puploop = 0; puploop<4; puploop++){ - if(powerups[puploop].active==0){ - powerups[puploop] = powerup_init(powerups[puploop], object); - break; - }; - }; - }; - -}; - -game_object player_init(game_object player){ - player.x = 18; - player.y = rand()%600+20; - player.direction = 5; - player.face = 1; - player.speed = 0; - player.vspeed = 0; - player.vtime = 0; - - return player; -} - -game_object pod_chase(game_object lander, game_object pod){ - - if(pod.active==0){ - lander.chase=-1; - lander.phase=0; - lander.speed=1; - //strcpy(lander.radar, "*"); //debug - } else { - - //match y, then direction and speed - if(lander.chase>=0&&lander.phase==1){ - if(abs(lander.y-pod.y)<3){ - lander.speed = 2; - }; - if(lander.y==pod.y){ - lander.direction = pod.direction; - lander.speed = pod.speed; - lander.phase = 2; - }; - }; - - if(lander.chase>=0&&lander.phase==2){ - //decend to pod's x-1 - if(lander.x<=pod.x-1){ - lander.x++; - }; - if(lander.x>pod.x-1){ - lander.phase = 3; - lander.vtime = 0; - lander.speed = 0; - lander.direction = 5; - }; - }; - - if(lander.chase>=0&&lander.phase==3){ - //ascend at speed 1 keep pod at x+1 - if(lander.vtime==0){ - lander.x--; - }; - if(lander.x<=1){ - //at x=1, destroy pod, deallocate lander, allocate crazy at same location. - lander.phase = 4; //set pod to 'kill' - }; - }; - - }; - return lander; -} int main(int argc, char *argv[]){ @@ -1146,7 +442,7 @@ int main(int argc, char *argv[]){ int bosscount = 0; int alertleft = 0; int alertright = 0; - int smartbombs = 4; + int smartbombs = 2; int shieldup = 0; int drawlaser = 0; @@ -1630,10 +926,14 @@ int main(int argc, char *argv[]){ shieldsleft = shieldsleft + 100; }; if(strncmp(powerups[puploop].line0, "L", 1)==0){ - lives++; + if(lives<4){ + lives++; + }; }; if(strncmp(powerups[puploop].line0, "B", 1)==0){ - smartbombs++; + if(smartbombs<6){ + smartbombs++; + }; }; if(strncmp(powerups[puploop].line0, "Z", 1)==0){ laser = laser + 100; diff --git a/mishaps.cpp b/mishaps.cpp new file mode 100644 index 0000000..e230a76 --- /dev/null +++ b/mishaps.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include "SDL/SDL.h" +#include "SDL/SDL_mixer.h" + +#include "game_object.h" +#include "draw.h" +#include "play_sound_effect.h" + +game_object encrazify(game_object lander, game_object crazy, Mix_Chunk *sound, int channel){ + channel = play_sound_effect(sound); + crazy.active=1; + crazy.x = lander.x; + crazy.y = lander.y; + crazy.face = lander.face; + crazy.vspeed = 0; + crazy.vtime = lander.vtime; + crazy.direction = lander.direction; + crazy.speed = 1; + + return crazy; +} + +void boom_object(game_object boomstuff, game_object object, Mix_Chunk *sound, int channel){ + + extern int drawlocation; + + int deathcycle=1; + int loop=1; + boomstuff.active=1; + channel = play_sound_effect(sound); + while(deathcycle<=7){ + for(int boomx=object.x-10;boomx<=object.x+10;boomx++){ + for(int boomy=object.y-10;boomy<=object.y+10;boomy++){ + if(sqrt((abs(object.y-boomy)*abs(object.y-boomy))+(abs(object.x-boomx)*abs(object.x-boomx)))<=deathcycle){ + if(rand()%1000>900){ + boomstuff.x = boomx; + boomstuff.y = boomy; + if(rand()%1000>500){ + boomstuff.face = 0; + } else { + boomstuff.face = 1; + }; + for(int iterations=0;iterations<=loop;iterations++){ + drawlocation = draw_object(boomstuff, drawlocation); + }; + //get the cursor out of the way + mvprintw(23,79,"-"); + refresh(); + }; + }; + }; + }; + deathcycle++; + }; + if(object.number!=1){ + usleep(50000); + }; +} + +int life_loss(int lives, int score){ + + extern int pause_game; + + if(lives>=1){ + pause_game = 0; + while(pause_game!=' '){ + cbreak(); + mvprintw(10,20,"Boom. Press SPACE to continue.\n"); + pause_game = getch(); + }; + halfdelay(1); + } else { + pause_game = 0; + + //record score if high + + int hscore = 0; + char filename[250]; + char outstring[50]; + strcpy (filename, "/.curfender_scores"); + char home[250]; + strcpy(home, getenv("HOME")); + + strncat(home, filename, 20); + + FILE *scorefile = fopen(home, "r"); + char workchara[6]; + fgets(workchara, 6, scorefile); + hscore = atoi(workchara); + fclose(scorefile); + + if(score>hscore){ + FILE *writescorefile = fopen(home, "w"); + sprintf(outstring, "%d", score); + fputs(outstring, writescorefile); + fclose(writescorefile); + }; + + while(pause_game!=' '){ + cbreak(); + mvprintw(10,20,"GAME OVER. Score:%d Press SPACE to exit.\n", score); + if(score>hscore){ + mvprintw(11,20,"High Score: %s", outstring); + }; + pause_game = getch(); + }; + endwin(); + exit(0); + }; +} diff --git a/mishaps.h b/mishaps.h new file mode 100644 index 0000000..1537a3e --- /dev/null +++ b/mishaps.h @@ -0,0 +1,3 @@ +game_object encrazify(game_object, game_object, Mix_Chunk*, int); +void boom_object(game_object, game_object, Mix_Chunk*, int); +int life_loss(int, int); \ No newline at end of file diff --git a/motion.cpp b/motion.cpp new file mode 100644 index 0000000..5a3bb74 --- /dev/null +++ b/motion.cpp @@ -0,0 +1,296 @@ +#include + +#include "game_object.h" +#include "gravitize.h" +#include "object_out.h" + +game_object boss_motion(game_object object, game_object player){ + if(player.ytrail[7]object.x){ object.direction = 1; }; + }; + if(player.ytrail[7]>=object.y){ + if(player.xtrail[7]object.x){ object.direction = 3; }; + }; + + return object; +} + +game_object crazy_motion(game_object object, game_object player){ + if(player.ytrail[9]object.x){ object.direction = 1; }; + }; + if(player.ytrail[9]>=object.y){ + if(player.xtrail[9]object.x){ object.direction = 3; }; + }; + + return object; +} + +game_object process_motion(game_object object, game_object player){ + + extern int pod_in, drawlocation; + + if((object.number>=2)&&(object.number<=9)&&(object.number==pod_in)){ + object.direction=player.direction; + object.speed=player.speed; + object.x=player.x; + object.y=player.y; + } else if(object.number>=100&&object.number<=111){ + object.direction = player.direction; + object.speed = player.speed; + if(object.number==100){ + object.x = player.x-1; + object.y = player.y+1; + }; + if(object.number==101){ + object.x = player.x-1; + object.y = player.y+2; + }; + if(object.number==102){ + object.x = player.x-1; + object.y = player.y+3; + }; + if(object.number==103){ + object.x = player.x+1; + object.y = player.y+1; + }; + if(object.number==104){ + object.x = player.x+1; + object.y = player.y+2; + }; + if(object.number==105){ + object.x = player.x+1; + object.y = player.y+3; + }; + if(object.number==106){ + object.x = player.x-1; + object.y = player.y; + }; + if(object.number==107){ + object.x = player.x+1; + object.y = player.y+4; + }; + if(object.number==108){ + object.x = player.x-1; + object.y = player.y+4; + }; + if(object.number==109){ + object.x = player.x+1; + object.y = player.y; + }; + if(object.number==110){ + object.x = player.x; + object.y = player.y+5; + }; + if(object.number==111){ + object.x = player.x; + object.y = player.y-1; + }; + } else { + if(object.number==1){ + object.xtrail[9]=object.xtrail[8]; + object.xtrail[8]=object.xtrail[7]; + object.xtrail[7]=object.xtrail[6]; + object.xtrail[6]=object.xtrail[5]; + object.xtrail[5]=object.xtrail[4]; + object.xtrail[4]=object.xtrail[3]; + object.xtrail[3]=object.xtrail[2]; + object.xtrail[2]=object.xtrail[1]; + object.xtrail[1]=object.xtrail[0]; + object.xtrail[0]=object.x; + object.ytrail[9]=object.ytrail[8]; + object.ytrail[8]=object.ytrail[7]; + object.ytrail[7]=object.ytrail[6]; + object.ytrail[6]=object.ytrail[5]; + object.ytrail[5]=object.ytrail[4]; + object.ytrail[4]=object.ytrail[3]; + object.ytrail[3]=object.ytrail[2]; + object.ytrail[2]=object.ytrail[1]; + object.ytrail[1]=object.ytrail[0]; + object.ytrail[0]=object.y; + }; + + if(object.direction==9){ + object.y = object.y+object.speed; + object.x = object.x-object.speed; + }; + if(object.direction==8){ + object.x = object.x-object.speed; + }; + if(object.direction==7){ + object.y = object.y-object.speed; + object.x = object.x-object.speed; + }; + if(object.direction==6){ + object.y = object.y+object.speed; + }; + if(object.direction==4){ + object.y = object.y-object.speed; + }; + if(object.direction==3){ + object.y = object.y+object.speed; + object.x = object.x+object.speed; + }; + if(object.direction==2){ + object.x = object.x+object.speed; + }; + if(object.direction==1){ + object.y = object.y-object.speed; + object.x = object.x+object.speed; + }; + + object = gravitize(object); + + //bounds check + if(object.x<=0){ + if(object.number>=80&&object.number<=89){ + object_out(object); + } else { + object.x=1; + object.direction=5; + }; + }; + + if(object.x>=19){ + if(object.number>=80&&object.number<=89){ + object_out(object); + } else { + object.x=18; + object.direction=5; + object.vspeed=0; + object.vtime=0; + }; + }; + + //wrap check + if(object.y<=0){ + object.y=object.y+620; + if(object.number==1){ + drawlocation=drawlocation+620; + }; + }; + if(object.y>=620){ + object.y=object.y-620; + if(object.number==1){ + drawlocation=drawlocation-620; + }; + }; + + if((object.number>=2)&&(object.number<=9)){ + if((object.face>=0)&&(object.face<3)){ + object.face++; + }else{ + object.face=0; + }; + }; + + if((object.number>=11)&&(object.number<=13)){ + if((object.face>=5)&&(object.face<6)){ + object.face++; + }else{ + object.face=5; + }; + }; + + }; + return object; + +} + +game_object process_direction(game_object object, int input){ + if(input==65){input=8;}; + if(input==67){input=6;}; + if(input==68){input=4;}; + if(input==66){input=2;}; + if(input==69){input=5;}; + if(input==object.direction){ + object.speed++; + } else { + + if(input==4||input==6||input==1||input==7||input==3||input==9){ + if(object.direction!=input){ + object.speed = 0; + } else { + object.speed = 1; + }; + object.direction = input; + + }; + if(input==2){ + object.x++; + if(object.vspeed<4&&object.vspeed>0){ + object.vspeed++; + }; + }; + if(input==8){ + object.x--; + if(object.vspeed>0){ + object.vspeed--; + object.vtime=0; + }; + }; + }; + + if(input==4||input==1||input==7){object.face=0;}; + if(input==6||input==3||input==9){object.face=1;}; + if(object.speed>4){object.speed=4;}; + return object; + +} + +game_object pod_chase(game_object lander, game_object pod){ + + if(pod.active==0){ + lander.chase=-1; + lander.phase=0; + lander.speed=1; + //strcpy(lander.radar, "*"); //debug + } else { + + //match y, then direction and speed + if(lander.chase>=0&&lander.phase==1){ + if(abs(lander.y-pod.y)<3){ + lander.speed = 2; + }; + if(lander.y==pod.y){ + lander.direction = pod.direction; + lander.speed = pod.speed; + lander.phase = 2; + }; + }; + + if(lander.chase>=0&&lander.phase==2){ + //decend to pod's x-1 + if(lander.x<=pod.x-1){ + lander.x++; + }; + if(lander.x>pod.x-1){ + lander.phase = 3; + lander.vtime = 0; + lander.speed = 0; + lander.direction = 5; + }; + }; + + if(lander.chase>=0&&lander.phase==3){ + //ascend at speed 1 keep pod at x+1 + if(lander.vtime==0){ + lander.x--; + }; + if(lander.x<=1){ + //at x=1, destroy pod, deallocate lander, allocate crazy at same location. + lander.phase = 4; //set pod to 'kill' + }; + }; + + }; + return lander; +} diff --git a/motion.h b/motion.h new file mode 100644 index 0000000..e58935a --- /dev/null +++ b/motion.h @@ -0,0 +1,5 @@ +game_object boss_motion(game_object, game_object); +game_object crazy_motion(game_object, game_object); +game_object process_motion(game_object, game_object); +game_object process_direction(game_object, int); +game_object pod_chase(game_object, game_object); diff --git a/object_out.cpp b/object_out.cpp new file mode 100644 index 0000000..a2d765f --- /dev/null +++ b/object_out.cpp @@ -0,0 +1,12 @@ +#include "game_object.h" + +game_object object_out(game_object object){ + object.active=0; + object.x = -1; + object.y = -1; + object.speed = 0; + object.direction = 0; + object.chase = -1; + object.phase = 0; + return object; +} \ No newline at end of file diff --git a/object_out.h b/object_out.h new file mode 100644 index 0000000..e180aa9 --- /dev/null +++ b/object_out.h @@ -0,0 +1 @@ +game_object object_out(game_object); \ No newline at end of file diff --git a/play_sound_effect.cpp b/play_sound_effect.cpp new file mode 100644 index 0000000..dfdb52c --- /dev/null +++ b/play_sound_effect.cpp @@ -0,0 +1,7 @@ +#include "SDL/SDL.h" +#include "SDL/SDL_mixer.h" + +int play_sound_effect(Mix_Chunk *chunk){ + int channel = Mix_PlayChannel(-1, chunk, 0); + return channel; +}; \ No newline at end of file diff --git a/play_sound_effect.h b/play_sound_effect.h new file mode 100644 index 0000000..b21ebc3 --- /dev/null +++ b/play_sound_effect.h @@ -0,0 +1 @@ +int play_sound_effect(Mix_Chunk*); diff --git a/powerup.cpp b/powerup.cpp new file mode 100644 index 0000000..0a8b8cc --- /dev/null +++ b/powerup.cpp @@ -0,0 +1,49 @@ +#include +#include + +#include "game_object.h" + +game_object powerup_init(game_object powerup, game_object object){ + //Call immediately before an object_out + powerup.active = 1; + powerup.x = object.x; + powerup.y = object.y; + if(rand()%1000>=500){ + powerup.direction = 4; + } else { + powerup.direction = 6; + }; + powerup.speed = 1; + + int fodder = rand()%1000; + + if(fodder>=800){ + strcpy (powerup.line0, "T"); + }; + if(fodder>=600&&fodder<800){ + strcpy (powerup.line0, "S"); + }; + if(fodder>=400&&fodder<600){ + strcpy (powerup.line0, "L"); + }; + if(fodder>=200&&fodder<400){ + strcpy (powerup.line0, "B"); + }; + if(fodder<200){ + strcpy (powerup.line0, "Z"); + }; + + return powerup; +}; + +void determine_powerup(game_object powerups[], game_object object, int odds){ + if(rand()%1000>odds){ + for(int puploop = 0; puploop<4; puploop++){ + if(powerups[puploop].active==0){ + powerups[puploop] = powerup_init(powerups[puploop], object); + break; + }; + }; + }; + +}; diff --git a/powerup.h b/powerup.h new file mode 100644 index 0000000..e5ee65a --- /dev/null +++ b/powerup.h @@ -0,0 +1,2 @@ +game_object powerup_init(game_object, game_object); +void determine_powerup(game_object[], game_object, int); diff --git a/radar_plot.cpp b/radar_plot.cpp new file mode 100644 index 0000000..92095e9 --- /dev/null +++ b/radar_plot.cpp @@ -0,0 +1,52 @@ +#include +#include + +#include "game_object.h" + +void radar_plot(game_object object, int drawlocation){ + + if(object.x>0&&object.y>0&&object.active==1){ + int line = 0; //vert plot pos + int row = 0; //horiz plot pos + int x_offset = 19; //offset for height + int y_offset = 17; //offset for display + + int dl_radar; //main offset + + //set line based on height rules + if(object.x>=1&&object.x<=3){ + line = 1; + } else if(object.x>=4&&object.x<=9){ + line = 2; + } else if(object.x>=10&&object.x<=15){ + line = 3; + } else if(object.x>=16&&object.x<=18){ + line = 4; + } else {line = 0;}; + + //set longitude based on location + div_t quotrem; + quotrem = div(object.y, 10); + row = quotrem.quot; + + //take in radar draw location + div_t dl_quotrem; + dl_quotrem = div(drawlocation, 10); + dl_radar = dl_quotrem.quot; + + //correct to wrap radar + + row = row-dl_radar+25; + + if(row>62){row = row-62;}; + if(row<0){row = row+62;}; + + //add offsets; + + line = line + x_offset; + row = row + y_offset; + + //plot with symbol + mvprintw(line,row,"%s",object.radar); + }; +} \ No newline at end of file diff --git a/radar_plot.h b/radar_plot.h new file mode 100644 index 0000000..7bd869e --- /dev/null +++ b/radar_plot.h @@ -0,0 +1 @@ +void radar_plot(game_object, int); \ No newline at end of file -- 2.9.0