#include <cstring>
#include <cstdlib>
#include <time.h>
-#include <algorithm>
int score;
int lives;
int drawlocation = 0;
+int pod_in = 0;
struct game_object {
int number; //object number
char line1[6]; //object: right
char line2[6]; //object: alt1
char line3[6]; //object: alt2
+ char radar[1]; //radar symbol
};
-game_object process_motion(game_object object){
+void radar_plot(game_object object, int drawlocation){
- //if(object.direction==2){
- // object.x = object.x+object.speed;
- //};
- //if(object.direction==8){
- // 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.x>0&&object.y>0){
+ 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 offset; //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;
+
+ //add offsets;
- //bounds check
- if(object.x<=0){
- object.x=1;
- object.direction=5;
- object.speed=0;
- };
- if(object.x>=19){
- object.x=18;
- object.direction=5;
- object.speed=0;
+ line = line + x_offset;
+ row = row + y_offset;
+
+ //plot with symbol
+ mvprintw(line,row,"%s",object.radar);
};
+}
- //wrap check
- if(object.y<=0){
- object.y=object.y+560;
- if(object.number==1){
- drawlocation=drawlocation+560;
+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.direction==6){
+ object.y = object.y+object.speed;
};
- };
- if(object.y>=560){
- object.y=object.y-560;
- if(object.number==1){
- drawlocation=drawlocation-560;
+ if(object.direction==4){
+ object.y = object.y-object.speed;
};
- };
-
- if((object.number>=2)&&(object.number<=9)){
- if((object.face>=0)&&(object.face<3)){
- object.face++;
- }else{
- object.face=0;
+
+ //bounds check
+ if(object.x<=0){
+ object.x=1;
+ object.direction=5;
+ object.speed=0;
+ };
+ if(object.x>=19){
+ object.x=18;
+ object.direction=5;
+ object.speed=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;
+ };
};
+
};
-
return object;
}
+game_object pod_out(game_object pod){
+ pod.active=0;
+ pod.x = 0;
+ pod.y = 0;
+ pod.speed = 0;
+ pod.direction = 0;
+ return pod;
+}
+
+int pod_check(game_object pod, game_object player){
+ int pod_in = 0;
+ if((pod.x==player.x)&&(abs(player.y-pod.y)<player.speed)){
+ pod_in = pod.number;
+ };
+
+ return pod_in;
+}
+
game_object process_direction(game_object object, int input){
if(input==65){input=8;};
if(input==67){input=6;};
}
int draw_object(game_object object, int drawlocation){
- if(object.number==1){
- if((object.y-drawlocation<30) and (object.direction==4)){
- drawlocation=drawlocation-object.speed;
+ if(object.number!=pod_in){
+ if(object.number==1){
+ if((object.y-drawlocation<30) and (object.direction==4)){
+ drawlocation=drawlocation-object.speed;
+ };
+ if((object.y-drawlocation>45) and (object.direction==6)){
+ drawlocation=drawlocation+object.speed;
+ };
};
- if((object.y-drawlocation>45) and (object.direction==6)){
- drawlocation=drawlocation+object.speed;
+
+ int offset;
+
+ if((drawlocation>=540)&&(object.number!=1)){
+ offset = drawlocation-620;
+ } else {
+ offset = drawlocation;
};
- };
-
- int offset;
-
- if((drawlocation>=480)and(object.number!=1)){
- offset = drawlocation-560;
- } else {
- offset = drawlocation;
- };
-
- if(object.active==1){
- if(object.face==0){
- mvprintw(object.x,object.y-offset,"%s",object.line0);
- } else if(object.face==1){
- mvprintw(object.x,object.y-offset,"%s",object.line1);
- } else if(object.face==2){
- mvprintw(object.x,object.y-offset,"%s",object.line2);
- } else if(object.face==3){
- mvprintw(object.x,object.y-offset,"%s",object.line3);
- } else if(object.face==4){
- mvprintw(object.x,object.y-offset,"%s",object.line1);
- mvprintw(object.x-1,object.y-offset,"%s",object.line0);
+
+ if(object.active==1){
+ if(object.face==0){
+ mvprintw(object.x,object.y-offset,"%s",object.line0);
+ } else if(object.face==1){
+ mvprintw(object.x,object.y-offset,"%s",object.line1);
+ } else if(object.face==2){
+ mvprintw(object.x,object.y-offset,"%s",object.line2);
+ } else if(object.face==3){
+ mvprintw(object.x,object.y-offset,"%s",object.line3);
+ } else if(object.face==4){
+ mvprintw(object.x,object.y-offset,"%s",object.line1);
+ mvprintw(object.x-1,object.y-offset,"%s",object.line0);
+ };
};
+
};
-
return drawlocation;
}
//Initialize world
+ srand(time(NULL));
+
score = 0;
lives = 4;
player.speed = 0;
strcpy (player.line0, "<==_>");
strcpy (player.line1, "<_==>");
+ strcpy (player.radar, "=");
game_object gate;
gate.number = 10;
gate.speed = 0;
strcpy (gate.line0, " ^ ");
strcpy (gate.line1, "/|\\");
+ strcpy (gate.radar, "|");
game_object gatebeam1;
gatebeam1.number = 11;
gatebeam1.speed = 0;
strcpy (gatebeam1.line0, " ] ");
strcpy (gatebeam1.line1, " [ ");
+ strcpy (gatebeam1.radar, "|");
game_object gatebeam2;
gatebeam2.number = 11;
gatebeam2.speed = 0;
strcpy (gatebeam2.line0, " ] ");
strcpy (gatebeam2.line1, " [ ");
+ strcpy (gatebeam2.radar, "|");
game_object gatebeam3;
gatebeam3.number = 11;
gatebeam3.speed = 0;
strcpy (gatebeam3.line0, " ] ");
strcpy (gatebeam3.line1, " [ ");
+ strcpy (gatebeam3.radar, "|");
game_object pod2;
pod2.number = 2;
pod2.active = 1;
pod2.x = 18; //always start on ground
- srand(time(NULL));
- pod2.y = rand()%560; //anywhere along the surface
- srand(time(NULL));
+ pod2.y = rand()%620; //anywhere along the surface
pod2.direction = rand()%1000;
if(pod2.direction<500){
pod2.direction = 4;
};
pod2.face = 0;
pod2.speed = 1;
- strcpy (pod2.line0, " X ");
- strcpy (pod2.line1, " X ");
+ strcpy (pod2.line0, " x ");
+ strcpy (pod2.line1, " x ");
strcpy (pod2.line2, " + ");
strcpy (pod2.line3, " + ");
+ strcpy (pod2.radar, "x");
+
+ game_object pod3;
+ pod3.number = 3;
+ pod3.active = 1;
+ pod3.x = 18; //always start on ground
+ pod3.y = rand()%620; //anywhere along the surface
+ pod3.direction = rand()%1000;
+ if(pod3.direction<500){
+ pod3.direction = 4;
+ } else {
+ pod3.direction = 6;
+ };
+ pod3.face = 0;
+ pod3.speed = 1;
+ strcpy (pod3.line0, " x ");
+ strcpy (pod3.line1, " x ");
+ strcpy (pod3.line2, " + ");
+ strcpy (pod3.line3, " + ");
+ strcpy (pod3.radar, "x");
- game_object pods[1] = { pod2 };
+ game_object pods[2] = { { pod2 }, { pod3 } };
initscr();
int loopvar = 0;
int input = 0;
- int pod_in = 0;
+ int podloop = 0;
cbreak();
halfdelay(1);
draw_board(player.y);
//process object motion
- player = process_motion(player);
- pod2 = process_motion(pod2);
+ player = process_motion(player, player);
+ pod2 = process_motion(pod2, player);
+ pod3 = process_motion(pod3, player);
// Draw player object 1
drawlocation = draw_object(player, drawlocation);
// Draw pods objects 2-9
drawlocation = draw_object(pod2, drawlocation);
+ drawlocation = draw_object(pod3, drawlocation);
// Draw gate object 10
drawlocation = draw_object(gate, drawlocation);
// Draw shots
+ //Radar plot 18x620 represented in 4x62
+ radar_plot(gate, drawlocation);
+ radar_plot(gatebeam1, drawlocation);
+ radar_plot(gatebeam2, drawlocation);
+ radar_plot(gatebeam3, drawlocation);
+ radar_plot(pod2, drawlocation);
+ radar_plot(pod3, drawlocation);
+ radar_plot(player, drawlocation);
+
+ //debug
+ mvprintw(21,1,"y:%d drawloc:%d", player.y, drawlocation);
+
+ //get the cursor out of the way
+ mvprintw(23,79,"|");
+
input = getch();
if(input=='q'){loopvar=1;};
};
//check for / process pod pickup
- if(pod_in==0){
- for_each(pods[0], pods[0], //functionize from here to--
- if(pod_in==0){
- if(check_collision(pod)==1){ //declare me!
- pod_in=pod.number;
- };
- };
- ); // --here.
+ if((pod_in==0)&&(pod2.active==1)){pod_in = pod_check(pod2, player);};
+ if((pod_in==0)&&(pod3.active==1)){pod_in = pod_check(pod3, player);};
+ //for(podloop = 0; podloop == 1; podloop++){
+ // if((pod_in==0)&&(pods[podloop].active==1)){pod_in = pod_check(pods[podloop], player);};
+ //};
+ //if((pod_in==0)&&(pods[0].active==1)){pod_in = pod_check(pods[0], player);};
+ //if((pod_in==0)&&(pods[1].active==1)){pod_in = pod_check(pods[1], player);};
+ if(pod_in>0){
+ strcpy (player.line0, "<==x>");
+ strcpy (player.line1, "<x==>");
};
//if pod in hand, check for gate dropoff
if(pod_in>0){
- if((abs(player.y-gate.y)<player.speed)&&(player.x>12)){
+ if((abs(player.y-gate.y)<player.speed)&&(player.x>10)){
//set pod inactive
+ if(pod_in==2){pod2 = pod_out(pod2);};
+ if(pod_in==3){pod3 = pod_out(pod3);};
//increment score
+ score = score + 10;
pod_in = 0;
+ strcpy (player.line0, "<==_>");
+ strcpy (player.line1, "<_==>");
};
};
//check for / process player fire