Set up const for major struct loops.
authorlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Thu, 7 Dec 2006 20:51:26 +0000 (20:51 +0000)
committerlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Thu, 7 Dec 2006 20:51:26 +0000 (20:51 +0000)
git-svn-id: svn+ssh://svn/var/repos/curfender@581 bc5cbbab-a4ec-0310-bb52-ff3d296db539

main.cpp

index 1e81b5d..76a70dd 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -3,6 +3,8 @@
 #include <cstdlib>
 #include <time.h>
 
+const int podmax = 8;
+const int bulletmax = 4;
 const int landershotmax = 10;
 const int landermax = 4;
 
@@ -468,7 +470,7 @@ game_object pod_chase(game_object lander, game_object pod){
     
     //match y, then direction and speed
     if(lander.chase>0&&lander.phase==1){
-      if(abs(lander.y-pod.y)<4){
+      if(abs(lander.y-pod.y)<3){
        lander.speed = 2;
       };
       if(lander.y==pod.y){
@@ -598,7 +600,7 @@ int main(){
   strcpy (gatebeam3.radar, "|");
 
   //pods
-  struct game_object pods[8] = { 
+  struct game_object pods[podmax] = { 
     { 2, 1, 18, rand()%620, 0, 0, 1, 0, 0 },
     { 3, 1, 18, rand()%620, 0, 0, 1, 0, 0 },
     { 4, 1, 18, rand()%620, 0, 0, 1, 0, 0 },
@@ -609,7 +611,7 @@ int main(){
     { 9, 1, 18, rand()%620, 0, 0, 1, 0, 0 }
  };
 
-  for(int podloop = 0; podloop<8; podloop=podloop+2){ 
+  for(int podloop = 0; podloop<podmax; podloop=podloop+2){ 
     if(rand()%1000>=500){
       pods[podloop].direction = 4;
     } else {
@@ -623,7 +625,7 @@ int main(){
     strcpy (pods[podloop].radar, "x");
   };
 
-  for(int podloop = 1; podloop<8; podloop=podloop+2){ 
+  for(int podloop = 1; podloop<podmax; podloop=podloop+2){ 
     strcpy (pods[podloop].line0, " + ");
     strcpy (pods[podloop].line1, " + ");
     strcpy (pods[podloop].line2, " x ");
@@ -632,14 +634,14 @@ int main(){
   };
 
   //bullets
-  struct game_object bullets[4] = {
+  struct game_object bullets[bulletmax] = {
     { 40, 0, 0, 0, 5, 0, 0, 0, 0 },
     { 41, 0, 0, 0, 5, 0, 0, 0, 0 },
     { 42, 0, 0, 0, 5, 0, 0, 0, 0 },
     { 43, 0, 0, 0, 5, 0, 0, 0, 0 }
   };
   
-  for(int bulletloop = 0; bulletloop<4; bulletloop++){ 
+  for(int bulletloop = 0; bulletloop<bulletmax; bulletloop++){ 
     strcpy (bullets[bulletloop].line0, " - ");
     strcpy (bullets[bulletloop].line1, " - ");
   };
@@ -720,13 +722,13 @@ int main(){
     //process object motion
     player = process_motion(player, player);
     
-    for(int podloop = 0; podloop<8; podloop++){ pods[podloop] = process_motion(pods[podloop], player); };
+    for(int podloop = 0; podloop<podmax; podloop++){ pods[podloop] = process_motion(pods[podloop], player); };
 
     gatebeam1 = process_motion(gatebeam1, player);
     gatebeam2 = process_motion(gatebeam2, player);
     gatebeam3 = process_motion(gatebeam3, player);
     
-    for(int bulletloop = 0; bulletloop<4; bulletloop++){ 
+    for(int bulletloop = 0; bulletloop<bulletmax; bulletloop++){ 
       if(bullets[bulletloop].active==1){ 
        bullets[bulletloop] = process_motion(bullets[bulletloop], player);
        bullets[bulletloop] = age_bullet(bullets[bulletloop]);
@@ -773,7 +775,7 @@ int main(){
     drawlocation = draw_object(player, drawlocation);
 
     // Draw pods objects 2-9    
-    for(int podloop = 0; podloop<8; podloop++){ drawlocation = draw_object(pods[podloop], drawlocation); };
+    for(int podloop = 0; podloop<podmax; podloop++){ drawlocation = draw_object(pods[podloop], drawlocation); };
 
     // Draw gate object 10
     drawlocation = draw_object(gate, drawlocation);
@@ -796,7 +798,7 @@ int main(){
     };
 
     // Draw shots objects 40-43
-    for(int bulletloop = 0; bulletloop<4; bulletloop++){ 
+    for(int bulletloop = 0; bulletloop<bulletmax; bulletloop++){ 
       if(bullets[bulletloop].active==1){ 
        drawlocation = draw_object(bullets[bulletloop], drawlocation);
       };
@@ -814,7 +816,7 @@ int main(){
     radar_plot(gatebeam1, drawlocation);
     radar_plot(gatebeam2, drawlocation);
     radar_plot(gatebeam3, drawlocation);
-    for(int podloop = 0; podloop<8; podloop++){ radar_plot(pods[podloop], drawlocation); };
+    for(int podloop = 0; podloop<podmax; podloop++){ radar_plot(pods[podloop], drawlocation); };
     for(int landerloop = 0; landerloop<landermax; landerloop++){ radar_plot(landers[landerloop], drawlocation); };
     for(int crazyloop = 0; crazyloop<landermax; crazyloop++){ radar_plot(crazies[crazyloop], drawlocation); };
     radar_plot(player, drawlocation);
@@ -861,7 +863,7 @@ int main(){
     };
 
     //check for / process pod pickup
-    for(int podloop = 0; podloop<8; podloop++){ 
+    for(int podloop = 0; podloop<podmax; podloop++){ 
       if((pod_in==0)&&(pods[podloop].active==1)&&(check_collision(pods[podloop], player)==1)){
        pod_in = pods[podloop].number;
       };
@@ -876,7 +878,7 @@ int main(){
     if(pod_in>0){
       if((abs(player.y-gate.y)<player.speed)&&(player.x>10)){
        //set pod inactive
-       for(int podloop = 0; podloop<8; podloop++){ if(pod_in==pods[podloop].number){ pods[podloop] = object_out(pods[podloop]); }; };
+       for(int podloop = 0; podloop<podmax; podloop++){ if(pod_in==pods[podloop].number){ pods[podloop] = object_out(pods[podloop]); }; };
        
        //increment score
        score = score + 10;
@@ -890,7 +892,7 @@ int main(){
     if(input=='z'){
       //we fired
       //get next inactive bullet, give it player's direction, speed, height, location +speed in direction, active, set vtime=1.
-      for(int bulletloop = 0; bulletloop<4; bulletloop++){ 
+      for(int bulletloop = 0; bulletloop<bulletmax; bulletloop++){ 
        if(bullets[bulletloop].active==0){ 
          bullets[bulletloop].active=1;
          if(player.face==0){ bullets[bulletloop].direction = 4; };
@@ -907,10 +909,10 @@ int main(){
     };
        
     //for each active bullet
-    for(int bulletloop = 0; bulletloop<4; bulletloop++){ 
+    for(int bulletloop = 0; bulletloop<bulletmax; bulletloop++){ 
       if(bullets[bulletloop].active==1){ 
        //check each active pod
-       for(int podloop = 0; podloop<8; podloop++){
+       for(int podloop = 0; podloop<podmax; podloop++){
          if(pods[podloop].active==1){
            if(check_collision(bullets[bulletloop], pods[podloop])==1){
              //kill pod and bullet
@@ -963,7 +965,7 @@ int main(){
          drawlocation = player.y-20;
          //kill any carried pods
          if(pod_in>0){
-           for(int podloop = 0; podloop<8; podloop++){ 
+           for(int podloop = 0; podloop<podmax; podloop++){ 
              if(pods[podloop].number==pod_in){
                pods[podloop] = object_out(pods[podloop]);
                pod_in = 0;
@@ -990,7 +992,7 @@ int main(){
          drawlocation = player.y-20;
          //kill any carried pods
          if(pod_in>0){
-           for(int podloop = 0; podloop<8; podloop++){ 
+           for(int podloop = 0; podloop<podmax; podloop++){ 
              if(pods[podloop].number==pod_in){
                pods[podloop] = object_out(pods[podloop]);
                pod_in = 0;
@@ -1082,7 +1084,7 @@ int main(){
          drawlocation = player.y-20;
          //kill any carried pods
          if(pod_in>0){
-           for(int podloop = 0; podloop<8; podloop++){ 
+           for(int podloop = 0; podloop<podmax; podloop++){ 
              if(pods[podloop].number==pod_in){
                pods[podloop] = object_out(pods[podloop]);
                pod_in = 0;
@@ -1103,15 +1105,15 @@ int main(){
        //if(rand()%10000<=10){
        if(rand()%1000<=10){
          //choose the closest pod
-         for(int podloop = 0; podloop<8; podloop++){
+         for(int podloop = 0; podloop<podmax; podloop++){
            if(landers[landerloop].chase==0&&pods[podloop].chase==0&&pods[podloop].active==1){
              landers[landerloop].chase = pods[podloop].number;
              pods[podloop].chase = landers[landerloop].number;
            };
          };
          //alert player  print >>>> or <<<< at mid height, flash.  set a value, have a function do it in the draw area.
-         //travel to it at speed 4
-         landers[landerloop].speed = 4;
+         //travel to it at speed 3
+         landers[landerloop].speed = 3;
          if(player.y<landers[landerloop].y){ landers[landerloop].direction = 6; alertright = 20;};
          if(player.y>=landers[landerloop].y){ landers[landerloop].direction = 4; alertleft = 20;};
          landers[landerloop].phase = 1;
@@ -1123,7 +1125,7 @@ int main(){
 
     //check for 0 active pods, saved pods, level victory
     podcount = 0;
-    for(int podloop = 0; podloop<8; podloop++){ podcount = podcount + pods[podloop].active; };
+    for(int podloop = 0; podloop<podmax; podloop++){ podcount = podcount + pods[podloop].active; };
     if(podcount<=0){
       //do the level victory once all landers are dead  
       landercount = 0;
@@ -1147,7 +1149,7 @@ int main(){
          //Advance level
          level++;
          //Reactivate pods if not zombied
-         for(int podloop = 0; podloop<8; podloop++){ pods[podloop] = pod_init(pods[podloop]); };
+         for(int podloop = 0; podloop<podmax; podloop++){ pods[podloop] = pod_init(pods[podloop]); };
          podsin = 0;
          //regen landers
          for(int landerloop = 0; landerloop<landermax; landerloop++){