Initial pod work, changed vertical motion to +-
authorlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Mon, 27 Nov 2006 14:55:51 +0000 (14:55 +0000)
committerlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Mon, 27 Nov 2006 14:55:51 +0000 (14:55 +0000)
git-svn-id: svn+ssh://svn/var/repos/curfender@535 bc5cbbab-a4ec-0310-bb52-ff3d296db539

main.cpp

index 513710f..2eb8eb1 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,7 @@
 #include <ncurses.h>
 #include <cstring>
 #include <cstdlib>
+#include <time.h>
 
 int score;
 int lives;
@@ -13,20 +14,22 @@ struct game_object {
   int x; // x vert position
   int y; // y horiz position
   int direction; //direction, 10-key numbers 2-4-6-8 default to 5, stationary
-  int face; // facing 0 left or 1 right
+  int face; // facing 0 left or 1 right, 4 is two-line
   int speed; //speed
   char line0[6]; //object: left
-  char line1[6]; //object: left
+  char line1[6]; //object: right
+  char line2[6]; //object: alt1
+  char line3[6]; //object: alt2
 };
 
 game_object process_motion(game_object object){
 
-  if(object.direction==2){
-    object.x = object.x+object.speed;
-  };
-  if(object.direction==8){
-    object.x = object.x-object.speed;
-  };
+  //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;
   };
@@ -47,17 +50,27 @@ game_object process_motion(game_object object){
   };
 
   //wrap check
-  if(object.number==1){
-    if(object.y<=0){
-      object.y=object.y+560;
+  if(object.y<=0){
+    object.y=object.y+560;
+    if(object.number==1){
       drawlocation=drawlocation+560;
     };
-    if(object.y>=560){
-      object.y=object.y-560;
+  };
+  if(object.y>=560){
+    object.y=object.y-560;
+    if(object.number==1){
       drawlocation=drawlocation-560;
     };
   };
-
+  
+  if((object.number>=2)&&(object.number<=9)){
+    if((object.face>=0)&&(object.face<3)){
+      object.face++;
+    }else{
+      object.face=0;
+    };
+  };
+  
   return object;
 
 }
@@ -71,8 +84,16 @@ game_object process_direction(game_object object, int input){
   if(input==object.direction){
     object.speed++;
   } else {
-    object.direction = input;
-    object.speed = 1;
+    if((input==4)||(input==6)){
+      object.direction = input;
+      object.speed = 1;
+    };
+    if(input==2){
+      object.x++;
+    };
+    if(input==8){
+      object.x--;
+    };
   };
   if(input==4){object.face=0;};
   if(input==6){object.face=1;};
@@ -102,16 +123,18 @@ int draw_object(game_object object, int drawlocation){
   if(object.active==1){
     if(object.face==0){
       mvprintw(object.x,object.y-offset,"%s",object.line0);
-    };
-    if(object.face==1){
+    } else if(object.face==1){
       mvprintw(object.x,object.y-offset,"%s",object.line1);
-    };
-    if(object.face==2){
+    } 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;
 
 }
@@ -152,6 +175,11 @@ void draw_board(int location){
 }
 
 int main(){
+  
+  //Check screen size 80x25 and exit if not big enough
+
+  //Initialize world
   score = 0;
   lives = 4;
 
@@ -172,7 +200,7 @@ int main(){
   gate.x = 18;
   gate.y = 40;
   gate.direction = 5;
-  gate.face = 2;
+  gate.face = 4;
   gate.speed = 0;
   strcpy (gate.line0, " ^ ");
   strcpy (gate.line1, "/|\\");
@@ -183,7 +211,7 @@ int main(){
   gatebeam1.x = 16;
   gatebeam1.y = 40;
   gatebeam1.direction = 5;
-  gatebeam1.face = 2;
+  gatebeam1.face = 4;
   gatebeam1.speed = 0;
   strcpy (gatebeam1.line0, " ] ");
   strcpy (gatebeam1.line1, " [ ");
@@ -194,7 +222,7 @@ int main(){
   gatebeam2.x = 14;
   gatebeam2.y = 40;
   gatebeam2.direction = 5;
-  gatebeam2.face = 2;
+  gatebeam2.face = 4;
   gatebeam2.speed = 0;
   strcpy (gatebeam2.line0, " ] ");
   strcpy (gatebeam2.line1, " [ ");
@@ -205,17 +233,33 @@ int main(){
   gatebeam3.x = 12;
   gatebeam3.y = 40;
   gatebeam3.direction = 5;
-  gatebeam3.face = 2;
+  gatebeam3.face = 4;
   gatebeam3.speed = 0;
   strcpy (gatebeam3.line0, " ] ");
   strcpy (gatebeam3.line1, " [ ");
 
-  initscr();
+  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.direction = rand()%1;
+  if(pod2.direction==0){
+    pod2.direction = 4;
+  } else {
+    pod2.direction = 6;
+  };
+  pod2.face = 0;
+  pod2.speed = 1;
+  strcpy (pod2.line0, " X ");
+  strcpy (pod2.line1, " X ");
+  strcpy (pod2.line2, " + ");
+  strcpy (pod2.line3, " + ");
 
-  //Check screen size 80x25
+  initscr();
 
-  //Initialize world
   //main loop
 
   int loopvar = 0;
@@ -233,12 +277,16 @@ int main(){
 
     //process object motion
     player = process_motion(player);
+    pod2 = process_motion(pod2);
 
     // Draw player object 1
     drawlocation = draw_object(player, drawlocation);
 
     // Draw pods objects 2-9
-    score++;
+    drawlocation = draw_object(pod2, drawlocation);
+
+    //Debug
+    //mvprintw(21,1,"Pod face:%d", pod2.face);
     
     // Draw gate object 10
     drawlocation = draw_object(gate, drawlocation);
@@ -250,10 +298,7 @@ int main(){
     // Draw shots
     
     input = getch();
-    int perm = input;
-
-    printw("%d", perm);
-
+    
     if(input=='q'){loopvar=1;};
     //check for / process direction change
     if(input==66||input==68||input==67||input==65||input==69){