Landers shoot horizontally, can kill you and a carried pod.
authorlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Tue, 5 Dec 2006 15:57:49 +0000 (15:57 +0000)
committerlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Tue, 5 Dec 2006 15:57:49 +0000 (15:57 +0000)
git-svn-id: svn+ssh://svn/var/repos/curfender@563 bc5cbbab-a4ec-0310-bb52-ff3d296db539

CHANGELOG
main.cpp

index 406ea82..d883705 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+Landers shoot hozizontally, move.  Can kill you and a carried pod.
 Added landers, shootable, collidable, and game over logic.
 Deprecated pod_check() in favor of check_collision()
 Can shoot pods.
index c073460..a2dc27a 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -3,6 +3,8 @@
 #include <cstdlib>
 #include <time.h>
 
+const int landershotmax = 10;
+
 int score;
 int lives;
 int level;
@@ -316,6 +318,21 @@ void draw_board(){
   
 }
 
+int life_loss(int lives, int score){
+  if(lives>=1){
+    cbreak();
+    mvprintw(10,20,"Boom.  Press any key to continue.\n");
+    getch();
+    halfdelay(1);
+  } else {
+    cbreak();
+    mvprintw(10,20,"GAME OVER. Score:%d  Press any key to exit.\n", score);
+    getch();
+    endwin();
+    exit(0);
+  };
+}
+
 int main(){
   
   //Check screen size 80x25 and exit if not big enough
@@ -460,13 +477,30 @@ int main(){
     strcpy (landers[landerloop].radar, "*");
   };
 
+  struct game_object landershot[landershotmax] = {
+    { 80, 0, 0, 0, 5, 0, 0, 0, 0 },
+    { 81, 0, 0, 0, 5, 0, 0, 0, 0 },
+    { 82, 0, 0, 0, 5, 0, 0, 0, 0 },
+    { 83, 0, 0, 0, 5, 0, 0, 0, 0 },
+    { 84, 0, 0, 0, 5, 0, 0, 0, 0 },
+    { 85, 0, 0, 0, 5, 0, 0, 0, 0 },
+    { 86, 0, 0, 0, 5, 0, 0, 0, 0 },
+    { 87, 0, 0, 0, 5, 0, 0, 0, 0 },
+    { 88, 0, 0, 0, 5, 0, 0, 0, 0 },
+    { 89, 0, 0, 0, 5, 0, 0, 0, 0 }
+  };
+  
+  for(int landershotloop = 0; landershotloop<landershotmax; landershotloop++){ 
+    strcpy (landershot[landershotloop].line0, " . ");
+    strcpy (landershot[landershotloop].line1, " . ");
+  };
+
   initscr();
 
   //main loop
 
   int loopvar = 0;
   int input = 0;
-  int lastkey = 0; //debug
   int podcount = 0;
   int podsin = 0;
 
@@ -503,6 +537,13 @@ int main(){
       };
     };
 
+    for(int landershotloop = 0; landershotloop<landershotmax; landershotloop++){ 
+      if(landershot[landershotloop].active==1){ 
+       landershot[landershotloop] = process_motion(landershot[landershotloop], player);
+       landershot[landershotloop] = age_bullet(landershot[landershotloop]);
+      };
+    };
+
     // Draw player object 1
     drawlocation = draw_object(player, drawlocation);
 
@@ -514,20 +555,28 @@ int main(){
     drawlocation = draw_object(gatebeam1, drawlocation);
     drawlocation = draw_object(gatebeam2, drawlocation);
     drawlocation = draw_object(gatebeam3, drawlocation);
-    // Draw enemies objects 60-64
+
+    // Draw enemies objects 60-63
     for(int landerloop = 0; landerloop<4; landerloop++){ 
       if(landers[landerloop].active==1){ 
        drawlocation = draw_object(landers[landerloop], drawlocation);
       };
     };
     
-    // Draw shots objects 40-44
+    // Draw shots objects 40-43
     for(int bulletloop = 0; bulletloop<4; bulletloop++){ 
       if(bullets[bulletloop].active==1){ 
        drawlocation = draw_object(bullets[bulletloop], drawlocation);
       };
     };
     
+    // Draw enemy shots 80-83
+    for(int landershotloop = 0; landershotloop<landershotmax; landershotloop++){ 
+      if(landershot[landershotloop].active==1){ 
+       drawlocation = draw_object(landershot[landershotloop], drawlocation);
+      };
+    };
+
     //Radar plot 18x620 represented in 4x62
     radar_plot(gate, drawlocation);
     radar_plot(gatebeam1, drawlocation);
@@ -537,9 +586,6 @@ int main(){
     for(int podloop = 0; podloop<8; podloop++){ radar_plot(pods[podloop], drawlocation); };
     for(int landerloop = 0; landerloop<4; landerloop++){ radar_plot(landers[landerloop], drawlocation); };
     
-    //debug
-    //mvprintw(21,1,"Lastkey:%d", lastkey);
-
     //pod state
     mvprintw(21,1,"Out: %d In: %d", podcount, podsin);
 
@@ -607,9 +653,7 @@ int main(){
        };
       };
     };
-    
-    //lastkey = input; debug
-    //check bullets
+       
     //for each active bullet
     for(int bulletloop = 0; bulletloop<4; bulletloop++){ 
       if(bullets[bulletloop].active==1){ 
@@ -649,22 +693,70 @@ int main(){
          lives--;
          //add to score
          score = score + 20;
-         if(lives>=1){
-           cbreak();
-           mvprintw(10,20,"Boom.  Press any key to continue.\n");
-           getch();
-           halfdelay(1);
-         } else {
-           cbreak();
-           mvprintw(10,20,"GAME OVER. Score:%d  Press any key to exit.\n", score);
-           getch();
-           endwin();
-           exit(0);
+         life_loss(lives, score);
+         //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++){
+      if(landers[landerloop].active==1){
+       if(rand()%1000>200){
+         // lander shoot
+         for(int landershotloop = 0; landershotloop<landershotmax; landershotloop++){ 
+           if(landershot[landershotloop].active==0){ 
+             int multiplier = 1;
+             landershot[landershotloop].active=1;
+             //set direction
+             if(player.y<landers[landerloop].y){ landershot[landershotloop].direction = 4; multiplier = -1; };
+             if(player.y>=landers[landerloop].y){ landershot[landershotloop].direction = 6; };
+             landershot[landershotloop].speed = landers[landerloop].speed + 2;
+             landershot[landershotloop].x = landers[landerloop].x;
+             //set multipler based on direction
+             landershot[landershotloop].y = landers[landerloop].y + (landers[landerloop].speed * multiplier);
+             landershot[landershotloop].vtime = 1;
+             break;
+           };
+         };
+       };
+      };
+    };
+
+    //for each active lander shot
+    for(int landershotloop = 0; landershotloop<landershotmax; landershotloop++){ 
+      if(landershot[landershotloop].active==1){ 
+       if(check_collision(landershot[landershotloop], player)==1){
+         //kill landershot and player
+         lives--;
+         landershot[landershotloop].vtime = 100;
+         landershot[landershotloop] = age_bullet(landershot[landershotloop]);
+         life_loss(lives, score);
+         //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, "<_==>");
+             };
+           };
+         };
+       };
+      };
+    };
+    
     //check for 0 active pods, saved pods, level victory
     podcount = 0;
     for(int podloop = 0; podloop<8; podloop++){ podcount = podcount + pods[podloop].active; };