#include <cstdlib>
#include <time.h>
+const int landershotmax = 10;
+
int score;
int lives;
int level;
}
+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
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;
};
};
+ 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);
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);
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);
};
};
};
-
- //lastkey = input; debug
- //check bullets
+
//for each active bullet
for(int bulletloop = 0; bulletloop<4; bulletloop++){
if(bullets[bulletloop].active==1){
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; };