Added landers, shootable, collidable, game over logic.
authorlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Tue, 5 Dec 2006 14:38:47 +0000 (14:38 +0000)
committerlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Tue, 5 Dec 2006 14:38:47 +0000 (14:38 +0000)
git-svn-id: svn+ssh://svn/var/repos/curfender@562 bc5cbbab-a4ec-0310-bb52-ff3d296db539

CHANGELOG
main.cpp

index 76e7071..406ea82 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+Added landers, shootable, collidable, and game over logic.
 Deprecated pod_check() in favor of check_collision()
 Can shoot pods.
 Started bullet work
index 9b8afb7..c073460 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -184,13 +184,13 @@ game_object pod_init(game_object pod){
   return pod;
 }
 
-game_object pod_out(game_object pod){
-  pod.active=0;
-  pod.x = 0;
-  pod.y = 0;
-  pod.speed = 0;
-  pod.direction = 0;
-  return pod;
+game_object object_out(game_object object){
+  object.active=0;
+  object.x = 0;
+  object.y = 0;
+  object.speed = 0;
+  object.direction = 0;
+  return object;
 }
 
 game_object process_direction(game_object object, int input){
@@ -328,6 +328,7 @@ int main(){
   score = 0;
   lives = 4;
 
+  //player
   game_object player;
   player.number = 1;
   player.active = 1;
@@ -342,6 +343,7 @@ int main(){
   strcpy (player.line1, "<_==>");
   strcpy (player.radar, "=");
 
+  //gate
   game_object gate;
   gate.number = 10;
   gate.active = 1;
@@ -404,6 +406,7 @@ int main(){
   strcpy (gatebeam3.line3, " ] ");
   strcpy (gatebeam3.radar, "|");
 
+  //pods
   struct game_object pods[8] = { 
     { 2, 1, 18, rand()%620, 6, 0, 1, 0, 0 },
     { 3, 1, 18, rand()%620, 4, 0, 1, 0, 0 },
@@ -431,6 +434,7 @@ int main(){
     strcpy (pods[podloop].radar, "x");
   };
 
+  //bullets
   struct game_object bullets[4] = {
     { 40, 0, 0, 0, 5, 0, 0, 0, 0 },
     { 41, 0, 0, 0, 5, 0, 0, 0, 0 },
@@ -443,6 +447,18 @@ int main(){
     strcpy (bullets[bulletloop].line1, " - ");
   };
 
+  //landers
+  struct game_object landers[4] = {
+    { 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 },
+  };
+  
+  for(int landerloop = 0; landerloop<4; landerloop++){ 
+    strcpy (landers[landerloop].line0, "{=}");
+    strcpy (landers[landerloop].radar, "*");
+  };
 
   initscr();
 
@@ -481,6 +497,12 @@ int main(){
       };
     };
 
+    for(int landerloop = 0; landerloop<4; landerloop++){ 
+      if(landers[landerloop].active==1){ 
+       landers[landerloop] = process_motion(landers[landerloop], player);
+      };
+    };
+
     // Draw player object 1
     drawlocation = draw_object(player, drawlocation);
 
@@ -492,9 +514,14 @@ int main(){
     drawlocation = draw_object(gatebeam1, drawlocation);
     drawlocation = draw_object(gatebeam2, drawlocation);
     drawlocation = draw_object(gatebeam3, drawlocation);
-    // Draw enemies
+    // Draw enemies objects 60-64
+    for(int landerloop = 0; landerloop<4; landerloop++){ 
+      if(landers[landerloop].active==1){ 
+       drawlocation = draw_object(landers[landerloop], drawlocation);
+      };
+    };
     
-    // Draw shots
+    // Draw shots objects 40-44
     for(int bulletloop = 0; bulletloop<4; bulletloop++){ 
       if(bullets[bulletloop].active==1){ 
        drawlocation = draw_object(bullets[bulletloop], drawlocation);
@@ -508,6 +535,7 @@ int main(){
     radar_plot(gatebeam3, drawlocation);
     radar_plot(player, 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); };
     
     //debug
     //mvprintw(21,1,"Lastkey:%d", lastkey);
@@ -550,7 +578,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] = pod_out(pods[podloop]); }; };
+       for(int podloop = 0; podloop<8; podloop++){ if(pod_in==pods[podloop].number){ pods[podloop] = object_out(pods[podloop]); }; };
        
        //increment score
        score = score + 10;
@@ -590,16 +618,53 @@ int main(){
          if(pods[podloop].active==1){
            if(check_collision(bullets[bulletloop], pods[podloop])==1){
              //kill pod and bullet
-             pods[podloop] = pod_out(pods[podloop]);
+             pods[podloop] = object_out(pods[podloop]);
              bullets[bulletloop].vtime = 100;
              bullets[bulletloop] = age_bullet(bullets[bulletloop]);
            };
          };
        };
        //check each active enemy
+       for(int landerloop = 0; landerloop<4; landerloop++){
+         if(landers[landerloop].active==1){
+           if(check_collision(bullets[bulletloop], landers[landerloop])==1){
+             //kill lander and bullet
+             landers[landerloop] = object_out(landers[landerloop]);
+             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++){
+      if(landers[landerloop].active==1){
+       if(check_collision(player, landers[landerloop])==1){
+         //kill lander and player
+         landers[landerloop] = object_out(landers[landerloop]);
+         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);
+         };
+       };
+      };
+    };
+
     //check for 0 active pods, saved pods, level victory
     podcount = 0;
     for(int podloop = 0; podloop<8; podloop++){ podcount = podcount + pods[podloop].active; };