Pods may crazy at all pod death, needs testing.
authorlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Wed, 6 Dec 2006 20:48:41 +0000 (20:48 +0000)
committerlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Wed, 6 Dec 2006 20:48:41 +0000 (20:48 +0000)
git-svn-id: svn+ssh://svn/var/repos/curfender@572 bc5cbbab-a4ec-0310-bb52-ff3d296db539

main.cpp

index e005319..5183ec2 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -4,6 +4,7 @@
 #include <time.h>
 
 const int landershotmax = 10;
+const int landermax = 4;
 
 int score;
 int lives;
@@ -107,8 +108,8 @@ void radar_plot(game_object object, int drawlocation){
 
 game_object object_out(game_object object){
   object.active=0;
-  object.x = 0;
-  object.y = 0;
+  object.x = -1;
+  object.y = -1;
   object.speed = 0;
   object.direction = 0;
   return object;
@@ -240,6 +241,28 @@ game_object lander_init(game_object lander){
   return lander;
 }
 
+game_object encrazify(game_object lander, game_object crazy){
+  
+  int pause = 0;
+  while(pause!=' '){
+    cbreak();
+    mvprintw(10,20,"Crazy?\n");
+    pause = getch();
+  };
+  halfdelay(1);
+
+  crazy.active=1;
+  crazy.x = lander.x;
+  crazy.y = lander.y;  
+  crazy.face = lander.face;
+  crazy.vspeed = lander.vspeed;
+  crazy.vtime = lander.vtime;
+  crazy.direction = lander.direction;
+  crazy.speed = lander.speed;
+
+  return crazy;
+}
+
 game_object process_direction(game_object object, int input){
   if(input==65){input=8;};
   if(input==67){input=6;};
@@ -530,14 +553,14 @@ int main(){
   };
 
   //landers
-  struct game_object landers[4] = {
+  struct game_object landers[landermax] = {
     { 60, 1, rand()%16, rand()%620, 6, 0, 1, 0, 0 },
     { 61, 1, rand()%16, rand()%620, 4, 0, 1, 0, 0 },
     { 62, 1, rand()%16, rand()%620, 6, 0, 1, 0, 0 },
-    { 63, 1, rand()%16, rand()%620, 4, 0, 1, 0, 0 },
+    { 63, 1, rand()%16, rand()%620, 4, 0, 1, 0, 0 }
   };
   
-  for(int landerloop = 0; landerloop<4; landerloop++){ 
+  for(int landerloop = 0; landerloop<landermax; landerloop++){ 
     strcpy (landers[landerloop].line0, "{=}");
     strcpy (landers[landerloop].radar, "*");
   };
@@ -560,6 +583,19 @@ int main(){
     strcpy (landershot[landershotloop].line1, " . ");
   };
 
+//crazies
+  struct game_object crazies[landermax] = {
+    { 90, 0, 0, 0, 6, 0, 1, 0, 0 },
+    { 91, 0, 0, 0, 4, 0, 1, 0, 0 },
+    { 92, 0, 0, 0, 6, 0, 1, 0, 0 },
+    { 93, 0, 0, 0, 4, 0, 1, 0, 0 }
+  };
+  
+  for(int crazyloop = 0; crazyloop<landermax; crazyloop++){ 
+    strcpy (crazies[crazyloop].line0, "}!{");
+    strcpy (crazies[crazyloop].radar, "!");
+  };
+
   initscr();
 
   //main loop
@@ -595,12 +631,18 @@ int main(){
       };
     };
 
-    for(int landerloop = 0; landerloop<4; landerloop++){ 
+    for(int landerloop = 0; landerloop<landermax; landerloop++){ 
       if(landers[landerloop].active==1){ 
        landers[landerloop] = process_motion(landers[landerloop], player);
       };
     };
 
+    for(int crazyloop = 0; crazyloop<landermax; crazyloop++){ 
+      if(crazies[crazyloop].active==1){ 
+       crazies[crazyloop] = process_motion(crazies[crazyloop], player);
+      };
+    };
+
     for(int landershotloop = 0; landershotloop<landershotmax; landershotloop++){ 
       if(landershot[landershotloop].active==1){ 
        landershot[landershotloop] = process_motion(landershot[landershotloop], player);
@@ -620,13 +662,20 @@ int main(){
     drawlocation = draw_object(gatebeam2, drawlocation);
     drawlocation = draw_object(gatebeam3, drawlocation);
 
-    // Draw enemies objects 60-63
-    for(int landerloop = 0; landerloop<4; landerloop++){ 
+    // Draw landers objects 60-63
+    for(int landerloop = 0; landerloop<landermax; landerloop++){ 
       if(landers[landerloop].active==1){ 
        drawlocation = draw_object(landers[landerloop], drawlocation);
       };
     };
     
+    // Draw crazies objects 90-93
+    for(int crazyloop = 0; crazyloop<landermax; crazyloop++){ 
+      if(crazies[crazyloop].active==1){ 
+       drawlocation = draw_object(crazies[crazyloop], drawlocation);
+      };
+    };
+
     // Draw shots objects 40-43
     for(int bulletloop = 0; bulletloop<4; bulletloop++){ 
       if(bullets[bulletloop].active==1){ 
@@ -647,7 +696,8 @@ int main(){
     radar_plot(gatebeam2, drawlocation);
     radar_plot(gatebeam3, drawlocation);
     for(int podloop = 0; podloop<8; podloop++){ radar_plot(pods[podloop], drawlocation); };
-    for(int landerloop = 0; landerloop<4; landerloop++){ radar_plot(landers[landerloop], 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);
 
     //pod state
@@ -735,8 +785,8 @@ int main(){
            };
          };
        };
-       //check each active enemy
-       for(int landerloop = 0; landerloop<4; landerloop++){
+       //check each active lander
+       for(int landerloop = 0; landerloop<landermax; landerloop++){
          if(landers[landerloop].active==1){
            if(check_collision(bullets[bulletloop], landers[landerloop])==1){
              //kill lander and bullet
@@ -748,11 +798,24 @@ int main(){
            };
          };
        };
+       //check each active crazy
+       for(int crazyloop = 0; crazyloop<landermax; crazyloop++){
+         if(crazies[crazyloop].active==1){
+           if(check_collision(bullets[bulletloop], crazies[crazyloop])==1){
+             //kill crazy and bullet
+             crazies[crazyloop] = object_out(crazies[crazyloop]);
+             bullets[bulletloop].vtime = 100;
+             bullets[bulletloop] = age_bullet(bullets[bulletloop]);
+             //add to score
+             score = score + 20;
+           };
+         };
+       };
       };
     };
     
     //watch for lander/player collisions
-    for(int landerloop = 0; landerloop<4; landerloop++){
+    for(int landerloop = 0; landerloop<landermax; landerloop++){
       if(landers[landerloop].active==1){
        if(check_collision(player, landers[landerloop])==1){
          //kill lander and player
@@ -778,8 +841,35 @@ int main(){
       };
     };
 
+    //watch for crazy/player collisions
+    for(int crazyloop = 0; crazyloop<landermax; crazyloop++){
+      if(crazies[crazyloop].active==1){
+       if(check_collision(player, crazies[crazyloop])==1){
+         //kill crazy and player
+         crazies[crazyloop] = object_out(crazies[crazyloop]);
+         lives--;
+         //add to score
+         score = score + 20;
+         life_loss(lives, score);
+         player = player_init(player);
+         drawlocation = player.y-20;
+         //kill any carried pods
+         if(pod_in>0){
+           for(int podloop = 0; podloop<8; podloop=podloop+2){ 
+             if(pods[podloop].number==pod_in){
+               pods[podloop] = object_out(pods[podloop]);
+               pod_in = 0;
+               strcpy (player.line0, "<==_>");
+               strcpy (player.line1, "<_==>");
+             };
+           };
+         };
+       };
+      };
+    };
+
     // Lander shots
-    for(int landerloop = 0; landerloop<4; landerloop++){
+    for(int landerloop = 0; landerloop<landermax; landerloop++){
       if(landers[landerloop].active==1){
        if(rand()%1000>200){
          // lander shoot
@@ -869,19 +959,25 @@ int main(){
        for(int podloop = 0; podloop<8; podloop++){ pods[podloop] = pod_init(pods[podloop]); };
        podsin = 0;
        //regen landers
-       for(int landerloop = 0; landerloop<4; landerloop++){ 
+       for(int landerloop = 0; landerloop<landermax; landerloop++){ 
          if(landers[landerloop].active==0){
            landers[landerloop] = lander_init(landers[landerloop]);
          };
        };
       } else {
        //crazy the landers
+       for(int landerloop = 0; landerloop<landermax; landerloop++){ 
+         if(landers[landerloop].active==1){
+           crazies[landerloop] = encrazify(landers[landerloop], crazies[landerloop]);
+           landers[landerloop] = object_out(landers[landerloop]);
+         };
+       };
        //do the level victory once all crazies are dead
       };
     };
-    
+      
   }; //end main loop
-  
+
   endwin();
   
   return 0;