#include <ncurses.h>
#include <cstring>
#include <cstdlib>
+#include <time.h>
int score;
int lives;
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;
};
};
//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;
}
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;};
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;
}
}
int main(){
+
+ //Check screen size 80x25 and exit if not big enough
+
+ //Initialize world
+
score = 0;
lives = 4;
gate.x = 18;
gate.y = 40;
gate.direction = 5;
- gate.face = 2;
+ gate.face = 4;
gate.speed = 0;
strcpy (gate.line0, " ^ ");
strcpy (gate.line1, "/|\\");
gatebeam1.x = 16;
gatebeam1.y = 40;
gatebeam1.direction = 5;
- gatebeam1.face = 2;
+ gatebeam1.face = 4;
gatebeam1.speed = 0;
strcpy (gatebeam1.line0, " ] ");
strcpy (gatebeam1.line1, " [ ");
gatebeam2.x = 14;
gatebeam2.y = 40;
gatebeam2.direction = 5;
- gatebeam2.face = 2;
+ gatebeam2.face = 4;
gatebeam2.speed = 0;
strcpy (gatebeam2.line0, " ] ");
strcpy (gatebeam2.line1, " [ ");
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;
//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);
// 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){