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){
score = 0;
lives = 4;
+ //player
game_object player;
player.number = 1;
player.active = 1;
strcpy (player.line1, "<_==>");
strcpy (player.radar, "=");
+ //gate
game_object gate;
gate.number = 10;
gate.active = 1;
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 },
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 },
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();
};
};
+ 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);
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);
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);
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;
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; };