Added second pod, radar.
authorlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Tue, 28 Nov 2006 19:11:43 +0000 (19:11 +0000)
committerlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Tue, 28 Nov 2006 19:11:43 +0000 (19:11 +0000)
Radar still fixed, needs to move.  Maybe.

git-svn-id: svn+ssh://svn/var/repos/curfender@543 bc5cbbab-a4ec-0310-bb52-ff3d296db539

layout.txt
main.cpp

index b551acc..eace67e 100644 (file)
@@ -1,20 +1,20 @@
 12345678901234567890123456789012345678901234567890123456789012345678901234567890
 2
 3
-4      {=}
-5      
+4\     {=}
+5/     
 6
 7
 8
 9
-0
-1
+0\
+1/
 2                    [
 3                    ]
 4                    [
 5                    ]
-6                    [
-7                    ]                                 
+6\                   [
+7/                   ]                                 
 8                    ^                        <_==>    <x==>  -  -  -  
 9                   /|\            x + x +     
 0-------------------------------------------------------------------------------
index d460e96..3d2b10d 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -2,12 +2,12 @@
 #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
@@ -21,61 +21,118 @@ struct game_object {
   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;};
@@ -104,38 +161,40 @@ game_object process_direction(game_object object, int input){
 }
 
 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;
 
 }
@@ -181,6 +240,8 @@ int main(){
 
   //Initialize world
  
+  srand(time(NULL));
+
   score = 0;
   lives = 4;
 
@@ -194,6 +255,7 @@ int main(){
   player.speed = 0;
   strcpy (player.line0, "<==_>");
   strcpy (player.line1, "<_==>");
+  strcpy (player.radar, "=");
 
   game_object gate;
   gate.number = 10;
@@ -205,6 +267,7 @@ int main(){
   gate.speed = 0;
   strcpy (gate.line0, " ^ ");
   strcpy (gate.line1, "/|\\");
+  strcpy (gate.radar, "|");
  
   game_object gatebeam1;
   gatebeam1.number = 11;
@@ -216,6 +279,7 @@ int main(){
   gatebeam1.speed = 0;
   strcpy (gatebeam1.line0, " ] ");
   strcpy (gatebeam1.line1, " [ ");
+  strcpy (gatebeam1.radar, "|");
 
   game_object gatebeam2;
   gatebeam2.number = 11;
@@ -227,6 +291,7 @@ int main(){
   gatebeam2.speed = 0;
   strcpy (gatebeam2.line0, " ] ");
   strcpy (gatebeam2.line1, " [ ");
+  strcpy (gatebeam2.radar, "|");
 
   game_object gatebeam3;
   gatebeam3.number = 11;
@@ -238,14 +303,13 @@ int main(){
   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;
@@ -254,12 +318,32 @@ int main(){
   };
   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();
 
@@ -267,7 +351,7 @@ int main(){
 
   int loopvar = 0;
   int input = 0;
-  int pod_in = 0;
+  int podloop = 0;
 
   cbreak();
   halfdelay(1);
@@ -280,14 +364,16 @@ int main(){
     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);
@@ -298,6 +384,21 @@ int main(){
     
     // 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;};
@@ -307,22 +408,29 @@ int main(){
     };
 
     //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