+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.
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:
--- /dev/null
+#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
--- /dev/null
+game_object age_bullet(game_object);
\ No newline at end of file
--- /dev/null
+#include <cstdlib>
+
+#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
--- /dev/null
+int check_collision(game_object, game_object);
\ No newline at end of file
--- /dev/null
+#include <ncurses.h>
+#include <cstdlib>
+
+#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);
+}
--- /dev/null
+int draw_object(game_object, int);
+void draw_board();
--- /dev/null
+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
--- /dev/null
+#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
--- /dev/null
+game_object gravitize(game_object);
\ No newline at end of file
--- /dev/null
+#include <cstdlib>
+
+#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;
+}
--- /dev/null
+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);
#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;
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.y){
- if(player.xtrail[7]<object.x){ object.direction = 7; };
- if(player.xtrail[7]==object.x){ object.direction = 4; };
- if(player.xtrail[7]>object.x){ object.direction = 1; };
- };
- if(player.ytrail[7]>=object.y){
- if(player.xtrail[7]<object.x){ object.direction = 9; };
- if(player.xtrail[7]==object.x){ object.direction = 6; };
- 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.y){
- if(player.xtrail[9]<object.x){ object.direction = 7; };
- if(player.xtrail[9]==object.x){ object.direction = 4; };
- if(player.xtrail[9]>object.x){ object.direction = 1; };
- };
- if(player.ytrail[9]>=object.y){
- if(player.xtrail[9]<object.x){ object.direction = 9; };
- if(player.xtrail[9]==object.x){ object.direction = 6; };
- 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[]){
int bosscount = 0;
int alertleft = 0;
int alertright = 0;
- int smartbombs = 4;
+ int smartbombs = 2;
int shieldup = 0;
int drawlaser = 0;
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;
--- /dev/null
+#include <ncurses.h>
+#include <math.h>
+#include <unistd.h>
+#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);
+ };
+}
--- /dev/null
+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
--- /dev/null
+#include <cstdlib>
+
+#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.y){
+ if(player.xtrail[7]<object.x){ object.direction = 7; };
+ if(player.xtrail[7]==object.x){ object.direction = 4; };
+ if(player.xtrail[7]>object.x){ object.direction = 1; };
+ };
+ if(player.ytrail[7]>=object.y){
+ if(player.xtrail[7]<object.x){ object.direction = 9; };
+ if(player.xtrail[7]==object.x){ object.direction = 6; };
+ 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.y){
+ if(player.xtrail[9]<object.x){ object.direction = 7; };
+ if(player.xtrail[9]==object.x){ object.direction = 4; };
+ if(player.xtrail[9]>object.x){ object.direction = 1; };
+ };
+ if(player.ytrail[9]>=object.y){
+ if(player.xtrail[9]<object.x){ object.direction = 9; };
+ if(player.xtrail[9]==object.x){ object.direction = 6; };
+ 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;
+}
--- /dev/null
+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);
--- /dev/null
+#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
--- /dev/null
+game_object object_out(game_object);
\ No newline at end of file
--- /dev/null
+#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
--- /dev/null
+int play_sound_effect(Mix_Chunk*);
--- /dev/null
+#include <cstdlib>
+#include <string.h>
+
+#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;
+ };
+ };
+ };
+
+};
--- /dev/null
+game_object powerup_init(game_object, game_object);
+void determine_powerup(game_object[], game_object, int);
--- /dev/null
+#include <ncurses.h>
+#include <cstdlib>
+
+#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
--- /dev/null
+void radar_plot(game_object, int);
\ No newline at end of file