#use "testgamelib.ic" // "persistant" variables remain even if the power is turned off persistent int highi=0; persistent int highh=0; persistent int highm=0; persistent int highe=0; void main() { int cursrow, key, lives, k, timei, score, dif; float speed, secs, sleepa, sleepb, time; int objrows [] = {14,15,16,17,18,19,20,21,22,23,24,25}; int objcols [12]; char timechar []; // main menu display_clear(); place_char("Dodger v 2.0", 7, 0); place_char("By Evan F.", 8, 1); place_char("Select Difficulty:", 4, 2); place_char(">O<", 1, 4); cursrow = 4; place_char("Insane", 6, 4); place_char("Hard", 6, 5); place_char("Normal", 6, 6); place_char("Easy", 6, 7); place_char("High Scores:", 0,9); place_char("Insane:", 13, 9); place_int(highi, 20, 9); place_char("Hard:", 13, 10); place_int(highh, 18, 10); place_char("Normal:", 13, 11); place_int(highm, 20, 11); place_char("Easy:", 13, 12); place_int(highe, 18, 12); // cursor sequence while (1==1) { key = get_key(); if (key==1) break; if ((key==64) && (cursrow > 4)) { place_char(" ", 1, cursrow); cursrow = cursrow - 1; place_char(">O<", 1, cursrow); sleep(0.1); } if ((key==128) && (cursrow < 7)) { place_char(" ", 1, cursrow); cursrow = cursrow + 1; place_char(">O<", 1, cursrow); sleep(0.1); } } // set difficulty if (cursrow==4) { speed = 0.005; dif = 1; } if (cursrow==5) { speed = 0.025; dif = 2; } if (cursrow==6) { speed = 0.05; dif = 3; } if (cursrow==7) { speed = 0.1; dif = 4; } lives = 3; display_clear(); place_char("Ready...", 9, 6); sleep(0.5); display_clear(); place_char("Set...", 10, 6); sleep(0.5); display_clear(); // 13 obstacles for(k = 0; k < 13; k++) { place_char("|", 1, k); place_char("|", 26, k); } for(k = 0; k <11; k++) { objcols[k] = rand_int(2,25); } place_vert_char("Secs", 0 ,7); cursrow = 12; place_char(">O<", 12, 0); place_vert_char("Life Dodger", 27, 2); place_int(lives, 27, 0); secs = seconds(); while (lives!=0) { if (lives>1) place_int(lives, 27, 0); if (lives==1) place_char(" ", 27, 0); // update obstacles and reset if neccisary for (k = 0; k < 11; k++) { objrows[k] = objrows [k] - 1; if (objrows [k] == -1) { objrows [k] = 13; place_char (" ", objcols[k], 0); objcols [k] = rand_int(2,25); } } key = get_key(); // button input routines if (key!=0) { if (key==1) // pause the game { place_char("Paused", 13, 6); sleepa = seconds(); sleep(0.2); key = get_key(); while(key!=1) { key = get_key(); } while(key!=0) { key = get_key(); } sleepb = seconds(); place_char(" ", 13, 6); secs = secs + (sleepb - sleepa); } if (key==2) break; if ((key==32) && (cursrow != 2)) { place_char(" ", cursrow + 2, 0); cursrow = cursrow - 1; } if ((key==16) && (cursrow != 23)) { place_char(" ", cursrow, 0); cursrow = cursrow + 1; } } time = seconds(); time = time - secs; timei = ((int)(time)); time = ((float) (timei)); // placeing the elapsed time (not fun!) place_int((i_part(f_part(time/10000.0)*10.0)), 0, 0); place_int(((int) (f_part((float)((float)(i_part(time/100.0))/10.0))*10.0)), 0, 1); place_int(((int) (f_part((float)((float)(i_part(time/10.0))/10.0))*10.0)), 0 ,2); place_int(((int) (f_part(time / 10.0)*10.0)), 0, 3); // updating screen place_char(">O<", cursrow, 0); for (k = 0; k < 11; k++) { if (objrows[k] <= 13) { place_char("*", objcols[k], objrows[k]); if (objrows[k] < 13) { place_char(" ", objcols[k], objrows[k] +1); } } if ((objrows[k]==0) && ((objcols[k]== cursrow) || (objcols[k]==cursrow + 1) || (objcols[k]==cursrow + 2))) { place_char("xXx", cursrow, 0); lives = lives - 1; } } // used to set varying speed w/difficulty sleep(speed); } display_clear(); score = ((int) (seconds() - secs)); place_char("You lasted", 9, 0); place_int(score, 12, 2); place_char("seconds;", 10, 4); // if new high score, set it if((dif==1) && (score > highi)) { place_char("New High Score!!", 6, 12); highi=score; } if((dif==2) && (score > highh)) { place_char("New High Score!!", 6, 12); highh = score; } if((dif==3) && (score > highm)) { place_char("New High Score!!", 6, 12); highm = score; } if((dif==4) && (score > highe)) { place_char("New High Socre!!", 6, 12); highe = score; } // end program, must run again to play again place_char("Game Over", 9, 13); }