Robin Milward Cooney 200849894
Dependencies: N5110 SDFileSystem gameCharacters mbed
main.cpp
- Committer:
- robinmc
- Date:
- 2016-05-04
- Revision:
- 2:158d57cdbf1e
- Parent:
- 1:046e66f1ca76
- Child:
- 3:4b254b4bd6d4
File content as of revision 2:158d57cdbf1e:
/* ELEC2645 Game - Shooty shooty bang bang (priliminary name) Week 19 - initial version, basic testing of sensor and display (c) Robni Milward Cooney Uniersity of Leeds, 06/03/16 */ /** */ #include "mbed.h" #include "N5110.h" #include "math.h" #include "stdint.h" #include "tone.h" #include "SDFileSystem.h" #include "gameCharacters.h" #define joystickTolerance 0.05f N5110 lcd(PTE26,PTA0,PTC4,PTD0,PTD2,PTD1,PTC3); //declare LCD BusOut led(PTC8,PTC9,PTC0,PTC7,PTC5); //declare Bus output for LED bar SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS DigitalOut red_led(LED_RED); DigitalOut green_led(LED_GREEN); DigitalIn swJoy(PTB18); //define potentiomiter switch AnalogIn xPot(PTB2); //define x axis analoge in (this is the pot that corresponds to horizontal movement of the joystick) AnalogIn yPot(PTB3); //define y axis analoge in (this is the pot that corresponds to vertical movement of the joystick) DigitalIn b_A(PTE24); //define additional first button DigitalIn b_B(PTE25); //define additional second button PwmOut PWM(PTC11); InterruptIn press_b_A(PTE24); //declare the push button A as an interrupt InterruptIn press_b_B(PTE25); //declare the push button B as an interrupt Ticker Ticker_Menu; Ticker Ticker_Game; Ticker Ticker_ds; Ticker Ticker_music; Timeout tOut; FILE *Highscores; FILE *Progress; int i; //loop counter int run=0; int loop=0; int difficulty=2; int recks_movement=2; int fall=37; int g_jump=36; int jumpUp; int accel=0; int bullet=9; int bullet_height; int menu_select; int score=0; int highscore; int kill_score; int shield_score; int shield_counter=0; int h_movement=0; int ammo=24; int rat_movement=95; int hound_hMovement=98; int hound_vMovement=40; int hound_jump=0; int bear_movement=100; int bird_hMovement=95; int bird_vMovement=20; int cactus_movement=110; int t_rex_movement=120; int chasm_movement=85; int fire_ball_hMovement=t_rex_movement-6; int fire_ball_vMovement=25; int heart_movement=90; int ammo_movement=100; int speed_boost_movement=130; int menuState=0; //initial state for the menu fsm int jump_flag=0; int shoot_flag=0; int shield_flag=0; int print_rat_flag=0; int print_hound_flag=0; int hound_jump_flag=0; int print_bear_flag=0; int print_bird_flag=0; int print_heart_flag=0; int print_ammo_flag=0; int print_speed_boost_flag=0; int print_cactus_flag=0; int print_t_rex_flag=0; int print_chasm_flag=0; int print_fire_ball_flag=0; int lose_lives_delay_flag=0; int story_mode_flag=0; int lives_delay_loop=0; //number of times the lose_lives_delay_flag if statement has iterated int fire_on_screen=0; int story_progress=1; int g_story_mode_win=0; double lives=4; int bear_lives=0; int t_rex_lives=0; int random_num; int g_music_count=1; int g_top_scores[6]; float brightness=0.5; volatile int g_Ticker_Menu_flag=0; volatile int g_Ticker_Game_flag=0; volatile int g_Ticker_Music_flag=0; volatile int g_Ticker_ds_flag=0; volatile int g_press_b_A_flag=0; volatile int g_press_b_B_flag=0; void initialize_values() { b_A.mode(PullDown); b_B.mode(PullDown); swJoy.mode(PullDown); red_led = 1; green_led=1; i=0; //loop counter loop=0; recks_movement=2; fall=37; g_jump=36; accel=0; bullet=9; h_movement=0; ammo=24; rat_movement=85; hound_hMovement=90; hound_vMovement=40; hound_jump=0; bear_movement=100; bird_hMovement=95; bird_vMovement=20; cactus_movement=110; t_rex_movement=120; chasm_movement=85; fire_ball_hMovement=t_rex_movement-6; fire_ball_vMovement=25; heart_movement=90; ammo_movement=100; menuState=0; //initial state for the menu fsm jump_flag=0; shoot_flag=0; shield_flag=0; shield_counter=0; print_rat_flag=0; print_hound_flag=0; hound_jump_flag=0; print_bear_flag=0; print_bird_flag=0; print_heart_flag=0; print_ammo_flag=0; print_speed_boost_flag=0; print_cactus_flag=0; print_t_rex_flag=0; print_chasm_flag=0; print_fire_ball_flag=0; lose_lives_delay_flag=0; lives_delay_loop=0; lives=4; bear_lives=0; score=0; kill_score=0; shield_score=0; fire_on_screen=0; } void ticker_wait(int t) { for (int q=0; q<=t; q++) { if (g_Ticker_ds_flag) { g_Ticker_ds_flag=0; q++; } sleep(); } } void readSD_progress() { Progress=fopen("/sd/Progress.txt", "r"); if (Progress!=NULL) { green_led=0; fscanf(Progress,"%d, ",&story_progress); fclose(Progress); ticker_wait(5); green_led=1; } else { red_led=0; ticker_wait(5); red_led=1; } } void writeSD_progress() { Progress=fopen("/sd/Progress.txt", "w"); if (Progress!=NULL) { green_led=0; fprintf(Progress,"%d, ",story_progress); fclose(Progress); ticker_wait(5); green_led=1; } else { red_led=0; ticker_wait(5); red_led=1; } } void readSD_and_print_top_score() { Highscores=fopen("/sd/Highscores.txt", "r"); if (Highscores!=NULL) { green_led=0; ticker_wait(3); green_led=1; for (int j=0; j<=5; j++) { fscanf(Highscores,"%d, ",&g_top_scores[j]); } lcd.printString("Highscores:",0,0); for (int j=1; j<=5; j++) { char buffer[14]; int temp = sprintf(buffer,"%d",g_top_scores[j]); lcd.printString(buffer,12,j); } fclose(Highscores); } else { red_led=0; ticker_wait(3); red_led=1; lcd.printString("NO HIGHSCORES",3,2); lcd.printString("SET YET!!",18,3); } } void writeSD() { Highscores=fopen("/sd/Highscores.txt", "w"); if (Highscores!=NULL) { green_led=0; ticker_wait(3); green_led=1; for (int j=0; j<=5; j++) { fprintf(Highscores,"%d, ",g_top_scores[j]); } fclose(Highscores); } else { red_led=0; ticker_wait(3); red_led=1; } } void delete_file(char filename[]) { lcd.printString("Deleting file",0,1); ticker_wait(5); FILE *fp = fopen(filename, "r"); // try and open file if (fp != NULL) { // if it does open... fclose(fp); // close it remove(filename); // and then delete lcd.printString("Done!",0,5); ticker_wait(10); } // if we can't open it, it doesn't exist and so we can't delete it lcd.refresh(); } void Delete_Highscores() { lcd.clear(); while (1) { if (g_Ticker_Menu_flag) { g_Ticker_Menu_flag=0; lcd.printString("Delete all",0,2); lcd.printString("high scores?",0,3); if (b_A==1) { lcd.clear(); while (1) { if (g_Ticker_Menu_flag) { g_Ticker_Menu_flag=0; lcd.printString("Are you sure?",0,1); if (b_A==1) { lcd.clear(); delete_file("/sd/Highscores.txt"); return; } else if (b_B==1) { return; } } lcd.refresh(); sleep(); } } else if (b_B==1) { return; } } lcd.refresh(); sleep(); } } void sort_top_scores() { g_top_scores[5]=score; int temp; for (int j=0; j<=5; j++) { for (int n=1; n<=5; n++) { if (g_top_scores[j]>g_top_scores[n]) { temp = g_top_scores[j]; g_top_scores[j] = g_top_scores[n]; g_top_scores[n] = temp; } } } } void music_tOut(); void play_music() { tOut.attach(&music_tOut, (song1[0]/2)); PWM.period (1.0/1000); PWM.write(0.0); if (song1[g_music_count]!=0) { PWM.period(1/(song1[g_music_count])); PWM.write(0.5); } if (g_music_count<(sizeof(song1)/sizeof(song1[1]))) { g_music_count++; } else { g_music_count=1; } } void generate_random_number() { time_t seconds = time(NULL); srand(seconds); random_num=rand()%10000; } void led_bar() //code to test led bar { led=pow(2,lives)-1; if (lives>5) { lives=5; } } void ground() //funtion to print the ground { for (int x = 0; x<=84 ; x++) { lcd.setPixel(x,47); } } void print_heart() { for(int c=0; c<=4; c++) { //4 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=4; r++) { if (g_heart[r][c]==0) { if (lcd.getPixel(c+heart_movement,r+35)!=0) { lcd.setPixel(c+heart_movement,r+35); } else { lcd.clearPixel(c+heart_movement,r+35); } } else if (g_heart[r][c]==1) { lcd.setPixel(c+heart_movement,r+35); } } } } void print_ammo_pickUp() { for(int c=0; c<=6; c++) { //6 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=7; r++) { if (g_ammo_pickUp[r][c]==0) { if (lcd.getPixel(c+ammo_movement,r+35)!=0) { lcd.setPixel(c+ammo_movement,r+35); } else { lcd.clearPixel(c+ammo_movement,r+35); } } else if (g_ammo_pickUp[r][c]==1) { lcd.setPixel(c+ammo_movement,r+35); } } } } void print_speed_boost() { for (int c=0; c<=13; c++) { for (int r=0; r<=6; r++) { if (g_speed_boost[r][c]==0) { if (lcd.getPixel(c+speed_boost_movement,r+38)!=0) { lcd.setPixel(c+speed_boost_movement,r+38); } else { lcd.clearPixel(c+speed_boost_movement,r+38); } } else if (g_speed_boost[r][c]==1) { lcd.setPixel(c+speed_boost_movement,r+38); } } } } void print_recks_still_gun() { for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_recks_still_gun[r][c]==0) { if (lcd.getPixel(c+3,r+37)!=0) { lcd.setPixel(c+3,r+37); } else { lcd.clearPixel(c+3,r+37); } } else if (g_recks_still_gun[r][c]==1) { lcd.setPixel(c+3,r+37); } } } } void print_recks_moving_gun() { for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_recks_moving_gun[r][c]==0) { if (lcd.getPixel(c+3,r+37)!=0) { lcd.setPixel(c+3,r+37); } else { lcd.clearPixel(c+3,r+37); } } else if (g_recks_moving_gun[r][c]==1) { lcd.setPixel(c+3,r+37); } } } } void print_recks_crouch_gun() { for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_recks_crouch_gun[r][c]==0) { if (lcd.getPixel(c+3,r+37)!=0) { lcd.setPixel(c+3,r+37); } else { lcd.clearPixel(c+3,r+37); } } else if (g_recks_crouch_gun[r][c]==1) { lcd.setPixel(c+3,r+37); } } } } void print_recks_shield() { for(int c=0; c<=14; c++) { for(int r=0; r<=14; r++) { if (g_recks_shield[r][c]==0) { if (lcd.getPixel(c,r+33)!=0) { lcd.setPixel(c,r+33); } else { lcd.clearPixel(c,r+33); } } else if (g_recks_shield[r][c]==1) { lcd.setPixel(c,r+33); } } } } void print_recks_jump_gun() { for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_recks_jump_gun[r][c]==0) { if (lcd.getPixel(c+3,r+g_jump)!=0) { lcd.setPixel(c+3,r+g_jump); } else { lcd.clearPixel(c+3,r+g_jump); } } else if (g_recks_jump_gun[r][c]==1) { lcd.setPixel(c+3,r+g_jump); } } } } void print_recks_falling() { for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_recks_still_gun[r][c]==0) { if (lcd.getPixel(c+3,r+fall)!=0) { lcd.setPixel(c+3,r+fall); } else { lcd.clearPixel(c+3,r+fall); } } else if (g_recks_still_gun[r][c]==1) { lcd.setPixel(c+3,r+fall); } } } } void falling_animation() { while (fall<60) { if (g_Ticker_Menu_flag) { g_Ticker_Menu_flag=0; print_recks_falling(); fall+=3; } lcd.refresh(); sleep(); lcd.clear(); } } void print_mob_rat_p1() //funtion to print the still bear on the LCD { for(int c=0; c<=7; c++) { // 7 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=2; r++) { if (g_mob_rat_p1[r][c]==0) { if (lcd.getPixel(c+rat_movement,r+44)!=0) { lcd.setPixel(c+rat_movement,r+44); } else { lcd.clearPixel(c+rat_movement,r+44); } } else if (g_mob_rat_p1[r][c]==1) { lcd.setPixel(c+rat_movement,r+44); } } } } void print_mob_rat_p2() //funtion to print the still bear on the LCD { for(int c=0; c<=7; c++) { // 7 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=2; r++) { if (g_mob_rat_p2[r][c]==0) { if (lcd.getPixel(c+rat_movement,r+44)!=0) { lcd.setPixel(c+rat_movement,r+44); } else { lcd.clearPixel(c+rat_movement,r+44); } } else if (g_mob_rat_p2[r][c]==1) { lcd.setPixel(c+rat_movement,r+44); } } } } void print_mob_hound_p1() //funtion to print the still hound on the LCD { for(int c=0; c<=12; c++) { // 12 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=7; r++) { if (g_mob_hound_p1[r][c]==0) { if (lcd.getPixel(c+hound_hMovement,r+hound_vMovement)!=0) { lcd.setPixel(c+hound_hMovement,r+hound_vMovement); } else { lcd.clearPixel(c+hound_hMovement,r+hound_vMovement); } } else if (g_mob_hound_p1[r][c]==1) { lcd.setPixel(c+hound_hMovement,r+hound_vMovement); } } } } void print_mob_hound_p2() //funtion to print the moving hound on the LCD { for(int c=0; c<=12; c++) { // 12 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=7; r++) { if (g_mob_hound_p2[r][c]==0) { if (lcd.getPixel(c+hound_hMovement,r+hound_vMovement)!=0) { lcd.setPixel(c+hound_hMovement,r+hound_vMovement); } else { lcd.clearPixel(c+hound_hMovement,r+hound_vMovement); } } else if (g_mob_hound_p2[r][c]==1) { lcd.setPixel(c+hound_hMovement,r+hound_vMovement); } } } } void print_mob_hound_dead() //funtion to print the moving hound on the LCD { for(int c=0; c<=12; c++) { // 12 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=7; r++) { if (g_mob_hound_dead[r][c]==0) { if (lcd.getPixel(c+hound_hMovement,r+hound_vMovement)!=0) { lcd.setPixel(c+hound_hMovement,r+hound_vMovement); } else { lcd.clearPixel(c+hound_hMovement,r+hound_vMovement); } } else if (g_mob_hound_dead[r][c]==1) { lcd.setPixel(c+hound_hMovement,r+hound_vMovement); } } } } void print_mob_bear_p1() //funtion to print the still bear on the LCD { for(int c=0; c<=18; c++) { //18 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_mob_bear_p1[r][c]==0) { if (lcd.getPixel(c+bear_movement,r+37)!=0) { lcd.setPixel(c+bear_movement,r+37); } else { lcd.clearPixel(c+bear_movement,r+37); } } else if (g_mob_bear_p1[r][c]==1) { lcd.setPixel(c+bear_movement,r+37); } } } } void print_mob_bear_p2() //funtion to print the moving bear on the LCD { for(int c=0; c<=18; c++) { //18 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_mob_bear_p2[r][c]==0) { if (lcd.getPixel(c+bear_movement,r+37)!=0) { lcd.setPixel(c+bear_movement,r+37); } else { lcd.clearPixel(c+bear_movement,r+37); } } else if (g_mob_bear_p2[r][c]==1) { lcd.setPixel(c+bear_movement,r+37); } } } } void print_mob_bear_dead() //funtion to print the bead bear on the LCD { for(int c=0; c<=18; c++) { //18 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_mob_bear_dead[r][c]==0) { if (lcd.getPixel(c+bear_movement,r+37)!=0) { lcd.setPixel(c+bear_movement,r+37); } else { lcd.clearPixel(c+bear_movement,r+37); } } else if (g_mob_bear_dead[r][c]==1) { lcd.setPixel(c+bear_movement,r+37); } } } } void print_mob_bird_p1() //funtion to print the moving bird on the LCD { for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_mob_bird_p1[r][c]==0) { if (lcd.getPixel(c+bird_hMovement,r+bird_vMovement)!=0) { lcd.setPixel(c+bird_hMovement,r+bird_vMovement); } else { lcd.clearPixel(c+bird_hMovement,r+bird_vMovement); } } else if (g_mob_bird_p1[r][c]==1) { lcd.setPixel(c+bird_hMovement,r+bird_vMovement); } } } } void print_mob_bird_p2() //funtion to print the moving bird on the LCD { for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_mob_bird_p2[r][c]==0) { if (lcd.getPixel(c+bird_hMovement,r+bird_vMovement)!=0) { lcd.setPixel(c+bird_hMovement,r+bird_vMovement); } else { lcd.clearPixel(c+bird_hMovement,r+bird_vMovement); } } else if (g_mob_bird_p2[r][c]==1) { lcd.setPixel(c+bird_hMovement,r+bird_vMovement); } } } } void print_mob_bird_dead() //funtion to print the moving bird on the LCD { for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=9; r++) { if (g_mob_bird_dead[r][c]==0) { lcd.clearPixel(c+bird_hMovement,r+bird_vMovement); } else if (g_mob_bird_dead[r][c]==1) { lcd.setPixel(c+bird_hMovement,r+bird_vMovement); } } } } void print_cactus() //funtion to print the moving bird on the LCD { for(int c=0; c<=4; c++) { //4 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=11; r++) { if (cactus[r][c]==0) { if (lcd.getPixel(c+cactus_movement,r+35)!=0) { lcd.setPixel(c+cactus_movement,r+35); } else { lcd.clearPixel(c+cactus_movement,r+35); } } else if (cactus[r][c]==1) { lcd.setPixel(c+cactus_movement,r+35); } } } } void print_t_rex() { for(int c=0; c<=24; c++) { //24 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=27; r++) { if (g_t_rex[r][c]==0) { if (lcd.getPixel(c+t_rex_movement,r+19)!=0) { lcd.setPixel(c+t_rex_movement,r+19); } else { lcd.clearPixel(c+t_rex_movement,r+19); } } else if (g_t_rex[r][c]==1) { lcd.setPixel(c+t_rex_movement,r+19); } } } } void print_chasm() { for(int x=0; x<=16; x++) { lcd.setPixel(x+chasm_movement,46); } } void print_t_rex_moving() { for(int c=0; c<=24; c++) { //24 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=27; r++) { if (g_t_rex_moving[r][c]==0) { if (lcd.getPixel(c+t_rex_movement,r+19)!=0) { lcd.setPixel(c+t_rex_movement,r+19); } else { lcd.clearPixel(c+t_rex_movement,r+19); } } else if (g_t_rex_moving[r][c]==1) { lcd.setPixel(c+t_rex_movement,r+19); } } } } void print_t_rex_attack() { for(int c=0; c<=24; c++) { //24 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=27; r++) { if (g_t_rex_attack[r][c]==0) { if (lcd.getPixel(c+t_rex_movement,r+19)!=0) { lcd.setPixel(c+t_rex_movement,r+19); } else { lcd.clearPixel(c+t_rex_movement,r+19); } } else if (g_t_rex_attack[r][c]==1) { lcd.setPixel(c+t_rex_movement,r+19); } } } } void print_fire_ball_p1() { for(int c=0; c<=8; c++) { //24 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=8; r++) { if (g_fire_ball_p1[r][c]==0) { if (lcd.getPixel(c+fire_ball_hMovement,r+fire_ball_vMovement)!=0) { lcd.setPixel(c+fire_ball_hMovement,r+fire_ball_vMovement); } else { lcd.clearPixel(c+fire_ball_hMovement,r+fire_ball_vMovement); } } else if (g_fire_ball_p1[r][c]==1) { lcd.setPixel(c+fire_ball_hMovement,r+fire_ball_vMovement); } } } } void print_fire_ball_p2() { for(int c=0; c<=8; c++) { //24 beacause the loop stats from 0 but the array size from 1 for(int r=0; r<=8; r++) { if (g_fire_ball_p2[r][c]==0) { if (lcd.getPixel(c+fire_ball_hMovement,r+fire_ball_vMovement)!=0) { lcd.setPixel(c+fire_ball_hMovement,r+fire_ball_vMovement); } else { lcd.clearPixel(c+fire_ball_hMovement,r+fire_ball_vMovement); } } else if (g_fire_ball_p2[r][c]==1) { lcd.setPixel(c+fire_ball_hMovement,r+fire_ball_vMovement); } } } } void print_clouds() { uint8_t clouds_movement=h_movement; //8 bit unsigned interger for(int c=clouds_movement; c<=clouds_movement+83; c++) { for(int r=0; r<=2; r++) { if (g_clouds[r][c]==0) { lcd.clearPixel(c-clouds_movement,r+6); } else if (g_clouds[r][c]==1) { lcd.setPixel(c-clouds_movement,r+6); } } } } void print_locks() { int sp=8*story_progress; for(int c=0; c<=3; c++) { //24 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=5; r++) { for (int n=1; n<=33; n+=8) { if (g_padlock_p1[r][c]==0) { lcd.clearPixel(c+8,r+n); } else if (g_padlock_p1[r][c]==1) { lcd.setPixel(c+8,r+n); } } } } for(int c=0; c<=3; c++) { //24 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=5; r++) { for (int n=1; n<=sp; n+=8) { if (g_padlock_p2[r][c]==0) { lcd.clearPixel(c+8,r+n); } else if (g_padlock_p2[r][c]==1) { lcd.setPixel(c+8,r+n); } } } } } void shoot() { lcd.setPixel(bullet,g_jump+4); lcd.setPixel(bullet+1,g_jump+4); } void print_score(); void print_ammo(); void intro() { } void Ticker_Menu_isr() { g_Ticker_Menu_flag=1; } void Ticker_Game_isr() { g_Ticker_Game_flag=1; } void Ticker_ds_isr() { g_Ticker_ds_flag=1; } void music_tOut() { PWM.write(0.0); } void press_b_A_isr() { g_press_b_A_flag=1; } void press_b_B_isr() { g_press_b_B_flag=1; } enum joystickDirection { //emunm type for every neccessary direction of the joystick CENTRE, //when the joystick isn't moved DOWN, UP, LEFT, RIGHT, }; typedef struct JoyStick Joystick; //struct for Joystick struct JoyStick { float x; // current x value float x0; // 'centred' x value float y; // current y value float y0; // 'centred' y value int swJoy; // button state (assume pull-down used, so 1 = pressed, 0 = unpressed) joystickDirection direction; // current direction }; // create struct variable Joystick joystick; // read default positions of the joystick to calibrate later readings void calibrateJoystick() { swJoy.mode(PullDown); // must not move during calibration joystick.x0 = xPot; // initial positions in the range 0.0 to 1.0 (0.5 if centred exactly) joystick.y0 = yPot; } void updateJoystick() { // read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred) joystick.x = xPot - joystick.x0; joystick.y = yPot - joystick.y0; // read button state joystick.swJoy = swJoy; // calculate direction depending on x,y values // tolerance allows a little lee-way in case joystick not exactly in the stated direction if ( fabs(joystick.y) < joystickTolerance && fabs(joystick.x) < joystickTolerance) { joystick.direction = CENTRE; } else if ( joystick.y > joystickTolerance && fabs(joystick.x) < joystickTolerance) { joystick.direction = UP; } else if ( joystick.y < joystickTolerance && fabs(joystick.x) < joystickTolerance) { joystick.direction = DOWN; } else if ( joystick.x > joystickTolerance && fabs(joystick.y) < joystickTolerance) { joystick.direction = LEFT; } else if ( joystick.x < joystickTolerance && fabs(joystick.y) < joystickTolerance) { joystick.direction = RIGHT; } } struct menuState { int menu_select; // output value int nextState[5]; // array of next states 6 to account for all of the joystick states }; typedef const struct menuState STyp; STyp fsm_main_menu[5] = { {0,{0,1,4,0,0}}, {8,{1,2,0,1,1}}, {16,{2,3,1,2,2}}, {24,{3,4,2,3,3}}, {32,{4,0,3,4,4}} }; STyp fsm_settings_menu[5] = { {0,{0,1,2,0,0}}, {8,{1,2,0,1,1}}, {16,{2,3,1,2,2}}, {24,{3,0,2,3,3}}, {32,{4,4,4,4,4}} }; void main_menu(); void Game(); void Story_Mode(); void Tutorial(); void Chapter1(); void Chapter2(); void Chapter3(); void Chapter4(); void Minigame(); void Settings(); void Brightness(); void Difficulty(); void set_difficulty(); void Leaderboard(); void guns(); void Credits(); int Game_over(); void Pause(); int main() //main function, currently used to test different functions { initialize_values(); lcd.init(); Ticker_Menu.attach(&Ticker_Menu_isr,0.2); Ticker_Game.attach(&Ticker_Game_isr,0.1); Ticker_ds.attach(&Ticker_ds_isr,0.1); press_b_A.fall(&press_b_A_isr); press_b_A.mode(PullDown); press_b_B.fall(&press_b_B_isr); press_b_B.mode(PullDown); calibrateJoystick(); main_menu(); } // ----------------------------------------------------------------------------------------------------------------------------------------- void main_menu() { menuState=0; while(1) { g_press_b_A_flag=0; g_press_b_A_flag=0; if (g_Ticker_Menu_flag) { g_Ticker_Menu_flag=0; updateJoystick(); lcd.setBrightness(brightness); menu_select = fsm_main_menu[menuState].menu_select; // set ouput depending on current state menuState = fsm_main_menu[menuState].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 lcd.clear(); lcd.printString("Story mode",13,0); lcd.printString("Minigame",18,1); lcd.printString("Settings",18,2); lcd.printString("Leaderboard",9,3); lcd.printString("Credits",21,4); for (int i=0; i<85; i++) { //go through every pixel on the x axis for (int j=menu_select; j<(menu_select+8); j++) { // go through relevant pixels on the y axis if (lcd.getPixel(i,j)== 0) { //if the pixel is on trun it off lcd.setPixel(i,j); } else { lcd.clearPixel(i,j); //if the pixel is off turn it on } } } lcd.refresh(); if (b_A & menu_select==0) { Story_Mode(); } else if (b_A & menu_select==8) { Game(); } else if (b_A & menu_select==16) { Settings(); } else if (b_A & menu_select==24) { Leaderboard(); red_led=1; green_led=1; } else if (b_A & menu_select==32) { Credits(); } if (joystick.direction==LEFT&swJoy==1&b_B==1) { story_progress=5; writeSD_progress(); green_led=0; ticker_wait(5); green_led=1; } } sleep(); } } void Minigame() { ticker_wait(5); while (1) { if (g_Ticker_Game_flag) { g_Ticker_Game_flag=0; lcd.clear(); updateJoystick(); Game(); } i++; lcd.refresh(); sleep(); } } void Story_Mode() { menuState=0; story_mode_flag=1; led=0; readSD_progress(); while(1) { if (g_Ticker_Menu_flag) { g_Ticker_Menu_flag=0; updateJoystick(); lcd.setBrightness(brightness); menu_select = fsm_main_menu[menuState].menu_select; // set ouput depending on current state menuState = fsm_main_menu[menuState].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 lcd.clear(); print_locks(); lcd.printString("Tutorial",20,0); lcd.printString("Chapter 1",20,1); lcd.printString("Chapter 2",20,2); lcd.printString("Chapter 3",20,3); lcd.printString("Chapter 4",20,4); for (int i=0; i<85; i++) { //go through every pixel on the x axis for (int j=menu_select; j<(menu_select+8); j++) { // go through relevant pixels on the y axis if (lcd.getPixel(i,j)== 0) { //if the pixel is on trun it off lcd.setPixel(i,j); } else { lcd.clearPixel(i,j); //if the pixel is off turn it on } } } lcd.refresh(); if (b_A & menu_select==0&story_progress>=1) { Tutorial(); } else if (b_A & menu_select==8&story_progress>=2) { Chapter1(); } else if (b_A & menu_select==16&story_progress>=3) { Chapter2(); } else if (b_A & menu_select==24&story_progress>=4) { Chapter3(); } else if (b_A & menu_select==32&story_progress>=5) { Chapter4(); } if (b_B) { menuState=0; story_mode_flag=0; return; } } sleep(); } } void Tutorial() { lcd.clear(); lcd.printString("Welcome to",0,0); lcd.printString("boot camp",0,1); lcd.printString("soldier",0,2); lcd.printString("Press A >>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("Are you ready",0,0); lcd.printString("to begin your",0,1); lcd.printString("training?",0,2); lcd.printString("Press A >>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("Okay use",0,0); lcd.printString("joysick to",0,1); lcd.printString("move right and",0,2); lcd.printString("left to...",0,3); lcd.printString("Press A >>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("... move",0,0); lcd.printString("forwards and",0,1); lcd.printString("backwards.",0,2); lcd.printString("Understand?",0,3); lcd.printString("Yes Sir!>>",22,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("Now you try...",0,0); lcd.printString("Okay!>>",30,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } difficulty =-1; Game(); lcd.clear(); lcd.printString("Good!!!",0,0); lcd.printString("Now lets try",0,1); lcd.printString("jumping. To",0,2); lcd.printString("jump press B",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } difficulty =-1; Game(); lcd.clear(); lcd.printString("You can also",0,0); lcd.printString("crouch if you",0,1); lcd.printString("move your",0,2); lcd.printString("joystick down",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("And if you",0,0); lcd.printString("move the joy-",0,1); lcd.printString("stick up you",0,2); lcd.printString("will activate",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("your shield,",0,0); lcd.printString("this will",0,1); lcd.printString("protect you",0,2); lcd.printString("for 1 sec but",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("it'll cost",0,0); lcd.printString("you 10 score",0,1); lcd.printString("points.",0,2); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("Try it...",0,0); lcd.printString("Okay>>",30,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } difficulty =-1; score=20; Game(); lcd.clear(); lcd.printString("Great!!!",0,0); lcd.printString("To shoot press",0,1); lcd.printString("A, but watch",0,2); lcd.printString("out you...",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("... might use",0,0); lcd.printString("all your ammo",0,1); lcd.printString("Give it a go!",0,3); lcd.printString("Okay>>",30,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } difficulty =-1; Game(); lcd.clear(); lcd.printString("Remember you",0,0); lcd.printString("can also shoot",0,1); lcd.printString("while jumping",0,2); lcd.printString("and crouching",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("Information",0,0); lcd.printString("about your",0,1); lcd.printString("status (ammo",0,2); lcd.printString("and score) ...",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10);; g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("... is shown",0,0); lcd.printString("above, and the",0,1); lcd.printString("number",0,2); lcd.printString("lives you ...",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("... have is",0,0); lcd.printString("displayed on",0,1); lcd.printString("the LED bar,",0,2); lcd.printString("when they...",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("... all turn",0,0); lcd.printString("off you will",0,1); lcd.printString("die, so make",0,2); lcd.printString("sure that...",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("... it doesn't",0,0); lcd.printString("happen!!!",0,1); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("Excellent!!!",0,0); lcd.printString("Your training",0,1); lcd.printString("is over",0,2); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("Are you ready",0,0); lcd.printString("for your first",0,1); lcd.printString("mission?",0,2); lcd.printString("Yes!!!>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; story_progress=2; writeSD_progress(); break; } sleep(); } } void Chapter1() { lcd.clear(); lcd.printString("150+ MISSIONS",0,1); lcd.printString("LATER",18,2); lcd.refresh(); ticker_wait(20); lcd.clear(); lcd.printString("MISSION #158:",0,0); lcd.printString("We have intel",0,1); lcd.printString("of a new range",0,2); lcd.printString("of high tech",0,3); lcd.printString("military grade",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("weapons being",0,0); lcd.printString("developed in",0,1); lcd.printString("a remote",0,2); lcd.printString("island in the",0,3); lcd.printString("South...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } ticker_wait(10); lcd.clear(); lcd.printString("... Pacific.",0,0); lcd.printString("Your mission",0,1); lcd.printString("is to",0,2); lcd.printString("infiltrate the",0,3); lcd.printString("island and...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } ticker_wait(10); lcd.clear(); lcd.printString("... destroy",0,0); lcd.printString("as many of",0,1); lcd.printString("the weapons as",0,2); lcd.printString("you can. Are",0,3); lcd.printString("you ready?",0,4); lcd.printString("Yes!!>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } ticker_wait(10); lcd.clear(); lcd.printString("Excellent, you",0,0); lcd.printString("will land on",0,1); lcd.printString("the farside of",0,2); lcd.printString("the island and",0,3); lcd.printString("work your...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } ticker_wait(10); lcd.clear(); lcd.printString("...way towards",0,0); lcd.printString("the centre the",0,1); lcd.printString("closer you get",0,2); lcd.printString("the more",0,3); lcd.printString("defences...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } ticker_wait(20); lcd.clear(); lcd.printString("they'll have.",0,0); lcd.printString("For now you",0,1); lcd.printString("need to look",0,2); lcd.printString("out for the",0,3); lcd.printString("cacti they...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } ticker_wait(20); lcd.clear(); lcd.printString("if you touch",0,0); lcd.printString("one you'll",0,1); lcd.printString("lose a life so",0,2); lcd.printString("jump over...",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } ticker_wait(20); lcd.clear(); lcd.printString("...them, also,",0,0); lcd.printString("watch out for",0,1); lcd.printString("low tech cyber",0,2); lcd.printString("rats running",0,3); lcd.printString("around, you'll...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } ticker_wait(20); lcd.clear(); lcd.printString("have to jump",0,0); lcd.printString("them aswell",0,1); lcd.printString("as you cannot",0,2); lcd.printString("destroy them.",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } ticker_wait(20); lcd.clear(); lcd.printString("That's all you",0,0); lcd.printString("need to know ",0,1); lcd.printString("for now. Get",0,2); lcd.printString("to work and",0,3); lcd.printString("Good Luck!!!",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } difficulty=0; Game(); story_progress=3; writeSD_progress(); lcd.clear(); lcd.printString("Well done!!!",0,0); lcd.printString("Oh no...",0,1); lcd.printString("It looks like",0,2); lcd.printString("things are",0,3); lcd.printString("steping up",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } } void Chapter2() { lcd.clear(); lcd.printString("Now you'll",0,0); lcd.printString("encounter",0,1); lcd.printString("robotic birds",0,2); lcd.printString("and robotic",0,3); lcd.printString("hounds aswell.",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("Watch out for",0,0); lcd.printString("the birds as",0,1); lcd.printString("they may swoop",0,2); lcd.printString("and the hounds",0,3); lcd.printString("will pounce",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } difficulty=1; Game(); story_progress=4; writeSD_progress(); lcd.clear(); lcd.printString("Oh dear...",0,0); lcd.printString("There is more",0,1); lcd.printString("trouble ahead",0,2); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } } void Chapter3() { lcd.clear(); lcd.printString("It looks like",0,0); lcd.printString("there is some",0,1); lcd.printString("sort of",0,2); lcd.printString("bionic bear!!",0,3); lcd.printString("You better...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("... watch out",0,0); lcd.printString("it looks like",0,1); lcd.printString("it will be",0,2); lcd.printString("able to",0,3); lcd.printString("withstand...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("a few shots",0,0); lcd.printString("before",0,1); lcd.printString("destroying it",0,2); lcd.printString("4 hits should",0,3); lcd.printString("do it. GO!",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } difficulty=2; Game(); story_progress=5; writeSD_progress(); lcd.clear(); lcd.printString("OH DEAR",0,0); lcd.printString("LORD...",0,1); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } } void Chapter4() { g_press_b_A_flag=0; lcd.clear(); lcd.printString("You won't",0,0); lcd.printString("beleve this",0,1); lcd.printString("it's it's...",0,2); lcd.printString("it can't be",0,3); lcd.printString("it's not...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("it's not",0,0); lcd.printString("possible...",0,1); lcd.printString("It's a T Rex,",0,2); lcd.printString("a robotic",0,3); lcd.printString("T Rex!!!!",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("It's it's...",0,0); lcd.printString("it's",0,1); lcd.printString("breathing",0,2); lcd.printString("fire!!!",0,3); lcd.printString("It looks...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("... like it",0,0); lcd.printString("will only",0,1); lcd.printString("take damage",0,2); lcd.printString("when it's",0,3); lcd.printString("attacking...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("and I think",0,0); lcd.printString("you'll have",0,1); lcd.printString("to shoot it",0,2); lcd.printString("at least 8",0,3); lcd.printString("times to...",0,4); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("...destroy it",0,0); lcd.printString("I'll drop",0,1); lcd.printString("some ammo",0,2); lcd.printString("for you.",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } lcd.clear(); lcd.printString("Good Luck",0,0); lcd.printString("You'll need",0,1); lcd.printString("it",0,2); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(10); g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } difficulty=3; Game(); initialize_values(); if (g_story_mode_win) { lcd.clear(); lcd.printString("Well done",0,0); lcd.printString("Recks",0,1); lcd.printString("Lets clear",0,2); lcd.printString("get you home",0,3); lcd.printString("Press A>>",24,5); lcd.refresh(); ticker_wait(30); } g_press_b_A_flag=0; while (1) { if (g_press_b_A_flag) { g_press_b_A_flag=0; break; } sleep(); } } void freeze() { lcd.inverseMode(); lcd.refresh(); ticker_wait(5); lcd.normalMode(); } void Settings() { menuState=0; while (1) { if (g_Ticker_Menu_flag) { g_Ticker_Menu_flag=0; updateJoystick(); menu_select = fsm_settings_menu[menuState].menu_select; // set ouput depending on current state menuState = fsm_settings_menu[menuState].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 lcd.clear(); lcd.printString("Brightness",13,0); lcd.printString("Difficulty",13,1); lcd.printString("SD card",13,2); lcd.printString("Guns",13,3); for (int i=0; i<85; i++) { //go through every pixel on the x axis for (int j=menu_select; j<(menu_select+8); j++) { // go through relevant pixels on the y axis if (lcd.getPixel(i,j)== 0) { //if the pixel is on trun it off lcd.setPixel(i,j); } else { lcd.clearPixel(i,j); //if the pixel is off turn it on } } } lcd.refresh(); if (b_A & menu_select==0) { Brightness(); return; } else if (b_A & menu_select==8) { Difficulty(); return; } else if (b_A & menu_select==16) { Delete_Highscores(); return; } else if (b_A & menu_select==24) { guns(); return; } if (b_B) { menuState=0; return; } } } } void Difficulty() { menuState=0; while(1) { if (g_Ticker_Menu_flag) { g_Ticker_Menu_flag=0; updateJoystick(); menu_select = fsm_main_menu[menuState].menu_select; // set ouput depending on current state menuState = fsm_main_menu[menuState].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 lcd.clear(); lcd.printString("Piece of Cake",3,0); lcd.printString("Easy",30,1); lcd.printString("Regular",23,2); lcd.printString("Hard",30,3); lcd.printString("Legendary",15,4); for (int i=0; i<85; i++) { //go through every pixel on the x axis for (int j=menu_select; j<(menu_select+8); j++) { // go through relevant pixels on the y axis if (lcd.getPixel(i,j)== 0) { //if the pixel is on trun it off lcd.setPixel(i,j); } else { lcd.clearPixel(i,j); //if the pixel is off turn it on } } } lcd.refresh(); if (b_A & menu_select==0) { difficulty=0; return; } else if (b_A & menu_select==8) { difficulty=1; return; } else if (b_A & menu_select==16) { difficulty=2; return; } else if (b_A & menu_select==24) { difficulty=3; return; } else if (b_A & menu_select==32) { difficulty=4; return; } if (b_B) { menuState=0; return; } } sleep(); } } void Brightness() { menuState=0; while(1) { if (g_Ticker_Menu_flag) { g_Ticker_Menu_flag=0; updateJoystick(); menu_select = fsm_main_menu[menuState].menu_select; // set ouput depending on current state menuState = fsm_main_menu[menuState].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 lcd.clear(); lcd.printString("Dark",30,0); lcd.printString("Eco",33,1); lcd.printString("Regular",23,2); lcd.printString("Bright",26,3); lcd.printString("Blinding",20,4); for (int i=0; i<85; i++) { //go through every pixel on the x axis for (int j=menu_select; j<(menu_select+8); j++) { // go through relevant pixels on the y axis if (lcd.getPixel(i,j)== 0) { //if the pixel is on trun it off lcd.setPixel(i,j); } else { lcd.clearPixel(i,j); //if the pixel is off turn it on } } } lcd.refresh(); if (b_A & menu_select==0) { brightness=0; return; } else if (b_A & menu_select==8) { brightness=0.3; return; } else if (b_A & menu_select==16) { brightness=0.5; return; } else if (b_A & menu_select==24) { brightness=0.7; return; } else if (b_A & menu_select==32) { brightness=1; return; } if (b_B) { menuState=0; return; } } sleep(); } } void Leaderboard() { lcd.clear(); readSD_and_print_top_score(); g_press_b_B_flag=0; while(1) { if (g_press_b_B_flag) { g_press_b_B_flag=0; return; } lcd.refresh(); sleep(); } } void guns() { menuState=0; while(1) { if (g_Ticker_Menu_flag) { g_Ticker_Menu_flag=0; updateJoystick(); menu_select = fsm_settings_menu[menuState].menu_select; // set ouput depending on current state menuState = fsm_settings_menu[menuState].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 lcd.clear(); lcd.printString("Pistol",10,0); lcd.printString("Revolver",10,1); lcd.printString("Rifle",10,2); lcd.printString("Random",10,3); for (int i=0; i<85; i++) { //go through every pixel on the x axis for (int j=menu_select; j<(menu_select+8); j++) { // go through relevant pixels on the y axis if (lcd.getPixel(i,j)== 0) { //if the pixel is on trun it off lcd.setPixel(i,j); } else { lcd.clearPixel(i,j); //if the pixel is off turn it on } } } lcd.refresh(); if (b_A & menu_select==0) { g_g1=0; g_g2=0; return; } else if (b_A & menu_select==8) { g_g1=1; g_g2=0; return; } else if (b_A & menu_select==16) { g_g1=1; g_g2=1; return; } else if (b_A & menu_select==24) { if (rand()%3==0) { g_g1=0; g_g2=0; } else if (rand()%3==1) { g_g1=1; g_g2=0; } else if (rand()%3==2) { g_g1=1; g_g2=1; } return; } if (b_B) { menuState=0; return; } } sleep(); } } void Credits() { } void Game() { int run_game=1; g_music_count=1; while (run_game==1) { ground(); set_difficulty(); if (g_Ticker_Game_flag) { play_music(); g_Ticker_Game_flag=0; lcd.clear(); updateJoystick(); led_bar(); print_score(); generate_random_number(); if (lose_lives_delay_flag==1) { lives_delay_loop++; if (lives_delay_loop>=10) { //means that the delay between one life beeing lost and another one beeing lost is at least 1s lives_delay_loop=0; lose_lives_delay_flag=0; } } if (ammo<=5) { if (i%8>=4) { print_ammo(); } } else { print_ammo(); } if (b_B) { jump_flag=1; } if (shoot_flag==0) { bullet=9; if (joystick.direction==DOWN&jump_flag!=1) { bullet_height=42; } else { bullet_height=g_jump+4; } } else if (shoot_flag==1&loop==0) { loop++; ammo--; if (joystick.direction==DOWN&jump_flag!=1) { bullet_height=42; } else { bullet_height=g_jump+4; } } if (b_A) { if (ammo<=0) { shoot_flag=0; } else { shoot_flag=1; } } if (joystick.direction==UP&score>=10&jump_flag!=1) { shield_flag=1; } else if (joystick.direction==UP&score<10&jump_flag!=1) { print_recks_still_gun(); } if (print_t_rex_flag==1&random_num%10==0&fire_on_screen==0) { fire_on_screen=1; print_fire_ball_flag=1; fire_ball_hMovement=t_rex_movement-6; fire_ball_vMovement=25; } if (joystick.direction==CENTRE&jump_flag!=1&shield_flag!=1) { lcd.setPixel(bullet,bullet_height); lcd.setPixel(bullet+1,bullet_height); print_recks_still_gun(); if (shoot_flag==1) { bullet+=20; if (bullet>=84) { shoot_flag=0; loop=0; } } } else if (joystick.direction==LEFT&jump_flag!=1&shield_flag!=1) { if (run%2==0) { print_recks_still_gun(); } else if (run%2==1) { print_recks_moving_gun(); } lcd.setPixel(bullet,bullet_height); lcd.setPixel(bullet+1,bullet_height); if (shoot_flag==1) { bullet+=21; if (bullet>=84) { shoot_flag=0; loop=0; } } h_movement--; run++; } else if (joystick.direction==RIGHT&jump_flag!=1&shield_flag!=1) { if (run%2==0) { print_recks_still_gun(); } else if (run%2==1) { print_recks_moving_gun(); } lcd.setPixel(bullet,bullet_height); lcd.setPixel(bullet+1,bullet_height); if (shoot_flag==1) { bullet+=19; if (bullet>=84) { shoot_flag=0; loop=0; } } h_movement++; run++; } else if (joystick.direction==DOWN&jump_flag!=1&shield_flag!=1) { lcd.setPixel(bullet,bullet_height); lcd.setPixel(bullet+1,bullet_height); print_recks_crouch_gun(); bullet_height=42; if (shoot_flag==1) { bullet+=20; if (bullet>=84) { shoot_flag=0; loop=0; } } } else if (jump_flag==1&shield_flag!=1) { if (joystick.direction==LEFT) { if (shoot_flag==1) { bullet+=21; if (bullet>=84) { shoot_flag=0; loop=0; } } h_movement--; } else if (joystick.direction==RIGHT) { if (shoot_flag==1) { bullet+=19; if (bullet>=84) { shoot_flag=0; loop=0; } } h_movement++; } else if (joystick.direction==CENTRE) { if (shoot_flag==1) { bullet+=20; if (bullet>=84) { shoot_flag=0; loop=0; } } } if (g_jump<=36&jumpUp==0&g_jump!=15) { lcd.setPixel(bullet,bullet_height); lcd.setPixel(bullet+1,bullet_height); if (bullet>=84) { shoot_flag=0; loop=0; } print_recks_jump_gun(); g_jump-=6-accel; accel++; } else if (g_jump>=15&g_jump!=36) { lcd.setPixel(bullet,bullet_height); lcd.setPixel(bullet+1,bullet_height); if (bullet>=84) { shoot_flag=0; loop=0; } print_recks_jump_gun(); g_jump+=6-accel; accel--; jumpUp=1; } else if (g_jump==36&jumpUp==1) { lcd.setPixel(bullet,bullet_height); lcd.setPixel(bullet+1,bullet_height); if (bullet>=84) { shoot_flag=0; loop=0; } print_recks_still_gun(); jump_flag=0; jumpUp=0; g_jump=36; accel=0; } } if (print_rat_flag==1) { if (i%4>=2) { print_mob_rat_p1(); } else if (i%4<2) { print_mob_rat_p2(); } if (joystick.direction==LEFT) { rat_movement+=recks_movement; } else if (joystick.direction==RIGHT) { rat_movement-=recks_movement; } rat_movement-=3; if (rat_movement<=-15) { rat_movement=100; print_rat_flag=0; } if (rat_movement<=5&rat_movement>=-3&g_jump>32&lose_lives_delay_flag==0&shield_flag!=1) { //a life is lost if recks has an vertical and horizontal position equal to one of the pixels corresponding to the bears position lives--; freeze(); lose_lives_delay_flag=1; } } if (print_hound_flag==1) { if (i%4>=2&hound_jump_flag!=1) { print_mob_hound_p1(); } else if (i%4<2&hound_jump_flag!=1) { print_mob_hound_p2(); } if (joystick.direction==LEFT) { hound_hMovement+=recks_movement; } else if (joystick.direction==RIGHT) { hound_hMovement-=recks_movement; } hound_hMovement-=2; if (hound_hMovement<=-15) { hound_hMovement=100; print_hound_flag=0; } if (random_num%10==0) { hound_jump_flag=1; } if (hound_jump_flag==1) { hound_jump++; hound_hMovement--; if (hound_jump==1) { hound_vMovement-=3; } else if (hound_jump==2) { hound_vMovement-=2; } else if (hound_jump==3) { hound_vMovement-=1; } else if (hound_jump==4) { hound_vMovement+=1; } else if (hound_jump==5) { hound_vMovement+=2; } else if (hound_jump==6) { hound_vMovement+=3; } else if (hound_jump==7) { hound_jump_flag=0; hound_jump=0; } print_mob_hound_p2(); } if ((hound_hMovement<=8&hound_hMovement>=-5&g_jump>30&lose_lives_delay_flag==0&hound_jump_flag!=1&shield_flag!=1)|(hound_hMovement<=8&hound_hMovement>=-5&g_jump>26&lose_lives_delay_flag==0&hound_jump_flag==1&shield_flag!=1)) { //a life is lost if recks has an vertical and horizontal position equal to one of the pixels corresponding to the hounds position lives--; freeze(); lose_lives_delay_flag=1; } if (shoot_flag==1&bullet_height>hound_vMovement&bullet_height<hound_vMovement+8) { print_mob_hound_dead(); print_hound_flag=0; hound_hMovement=90; kill_score+=5; } } if (print_bear_flag==1) { if (i%4>=2) { print_mob_bear_p1(); } else if (i%4<2) { print_mob_bear_p2(); } if (joystick.direction==LEFT) { bear_movement+=recks_movement; } else if (joystick.direction==RIGHT) { bear_movement-=recks_movement; } bear_movement-=2; if (bear_movement<=-15) { bear_movement=100; print_bear_flag=0; } if (bear_movement<=8&bear_movement>=-5&g_jump>26&lose_lives_delay_flag==0&shield_flag!=1) { //a life is lost if recks has an vertical and horizontal position equal to one of the pixels corresponding to the bears position lives--; freeze(); lose_lives_delay_flag=1; } if (shoot_flag==1&bullet_height>38) { bear_lives++; if (bear_lives==12-3*g_g1-3*g_g2) { print_mob_bear_dead(); print_bear_flag=0; bear_movement=100; kill_score+=7; bear_lives=0; } } } if (print_bird_flag==1) { if (i%8>=4) { print_mob_bird_p1(); } else if (i%8<4) { print_mob_bird_p2(); } bird_hMovement-=2; if (joystick.direction==LEFT) { bird_hMovement+=recks_movement; } else if (joystick.direction==RIGHT) { bird_hMovement-=recks_movement; } if (random_num%6==0) { bird_vMovement--; } else if (random_num%6>=4) { bird_vMovement++; } if (bird_vMovement>=37) { bird_vMovement=37; } else if (bird_vMovement<=10) { bird_vMovement=10; } if (bird_hMovement<=-10) { print_bird_flag=0; bird_hMovement=100; bird_vMovement=20; bear_lives=0; } if ((bird_hMovement>=0&bird_hMovement<=10)&(bird_vMovement+5>=g_jump&bird_vMovement+5<=g_jump+10&lose_lives_delay_flag==0)&shield_flag!=1) { lives--; freeze(); lose_lives_delay_flag=1; } if (shoot_flag==1&(bullet_height==bird_vMovement+5|bullet_height==bird_vMovement+4)) { print_mob_bird_dead(); print_bird_flag=0; bird_hMovement=100; bird_vMovement=20; kill_score+=5; } } if (print_cactus_flag==1) { print_cactus(); if (joystick.direction==LEFT) { cactus_movement+=recks_movement; } else if (joystick.direction==RIGHT) { cactus_movement-=recks_movement; } if (cactus_movement<=-10) { cactus_movement=110; print_cactus_flag=0; } if (cactus_movement<=10&cactus_movement>=2&g_jump>32&lose_lives_delay_flag==0&shield_flag!=1) { lives--; freeze(); lose_lives_delay_flag=1; } } if (print_t_rex_flag==1) { if (joystick.direction==LEFT) { t_rex_movement+=recks_movement; } else if (joystick.direction==RIGHT) { t_rex_movement-=recks_movement; } if (random_num%4==0&print_fire_ball_flag!=1) { t_rex_movement+=3; print_t_rex_moving(); } else if (random_num%4==1&print_fire_ball_flag!=1) { t_rex_movement-=3; print_t_rex_moving(); } else if (random_num%4>1&print_fire_ball_flag!=1) { print_t_rex(); } if (t_rex_movement<=-100) { t_rex_movement=120; print_t_rex_flag=0; } if (t_rex_movement<=6&t_rex_movement>=2&lose_lives_delay_flag==0&shield_flag!=1) { lives--; freeze(); lose_lives_delay_flag=1; } } if (print_fire_ball_flag==1) { print_t_rex_attack(); fire_ball_hMovement-=4; if (joystick.direction==LEFT) { fire_ball_hMovement+=recks_movement; } else if (joystick.direction==RIGHT) { fire_ball_hMovement-=recks_movement; } if (i%4>=2) { print_fire_ball_p1(); } else { print_fire_ball_p2(); } if (fire_ball_vMovement>=37) { fire_ball_vMovement=37; } if (random_num%3==0) { fire_ball_vMovement++; } else if (random_num%3==1) { fire_ball_vMovement+=2; } if (fire_ball_hMovement<=-10) { fire_ball_vMovement=27; fire_ball_hMovement=t_rex_movement-6; print_fire_ball_flag=0; fire_on_screen=0; } if (fire_ball_hMovement>=3&fire_ball_hMovement<=8&fire_ball_vMovement>g_jump-5&fire_ball_vMovement<g_jump+10&lose_lives_delay_flag==0&shield_flag!=1) { lives--; freeze(); lose_lives_delay_flag=1; } if (shoot_flag==1) { t_rex_lives++; if (t_rex_lives>=27-3*g_g1-3*g_g2) { print_t_rex_flag=0; t_rex_movement=120; kill_score+=20; t_rex_lives=0; } } } if (print_chasm_flag==1) { print_chasm(); if (joystick.direction==LEFT) { chasm_movement+=recks_movement; } else if (joystick.direction==RIGHT) { chasm_movement-=recks_movement; } if (chasm_movement<3&chasm_movement>-5&jump_flag!=1) { lives-=5; falling_animation(); chasm_movement=85; if (chasm_movement<-8) { print_chasm_flag=0; } } } if (print_heart_flag==1) { print_heart(); if (joystick.direction==LEFT) { heart_movement+=recks_movement; } else if (joystick.direction==RIGHT) { heart_movement-=recks_movement; } if (heart_movement<=7&g_jump>26) { heart_movement=90; print_heart_flag=0; lives++; } } if (print_ammo_flag==1) { print_ammo_pickUp(); if (joystick.direction==LEFT) { ammo_movement+=recks_movement; } else if (joystick.direction==RIGHT) { ammo_movement-=recks_movement; } if (ammo_movement<=7&g_jump>26) { ammo_movement=90; print_ammo_flag=0; ammo+=5; ammo+=rand()%7; } } if (print_speed_boost_flag==1) { print_speed_boost(); if (joystick.direction==LEFT) { speed_boost_movement+=recks_movement; } else if (joystick.direction==RIGHT) { speed_boost_movement-=recks_movement; } if (speed_boost_movement<=5&g_jump>26) { speed_boost_movement=120; print_speed_boost_flag=0; recks_movement++; } } if (recks_movement>=3&i%150==0) { recks_movement=2; } if (lives<=0) { run_game=Game_over(); //calls game over returns 1 if continue was selected returns 0 if back to menu } if (swJoy==1) { Pause(); } if (shield_flag==1) { print_recks_shield(); recks_movement=0; jump_flag=0; shoot_flag=0; shield_counter++; if (shield_counter>=10) { shield_counter=0; recks_movement=2; shield_score+=10; shield_flag=0; } } if (difficulty==-1&story_mode_flag==1) { if (i>70) { initialize_values(); return; } } else if (difficulty==0&story_mode_flag==1) { if (score>60) { return; } } else if (difficulty==1&story_mode_flag==1) { if (score>200) { return; } } else if (difficulty==2&story_mode_flag==1) { if (score>500) { return; } } else if (difficulty==3&story_mode_flag==1) { print_t_rex_flag=1; g_story_mode_win=0; if (t_rex_lives>=24) { print_t_rex_flag=0; g_story_mode_win=1; return; } } i++; print_clouds(); } lcd.refresh(); sleep(); } } void Pause() { int q; lcd.printString("PAUSED",25,3); ticker_wait(10); while (!swJoy) { if (g_Ticker_Menu_flag) { g_Ticker_Menu_flag=0; if (swJoy&q>5) { q=0; lcd.setBrightness(brightness); led_bar(); } else if (q>=20) { lcd.setBrightness(0); led=0; } } sleep(); } } void set_difficulty() { switch(difficulty) { case -1: break; case 0: if (random_num<3000) { print_cactus_flag=1; } else if (random_num>=3000&random_num<6000) { print_rat_flag=1; } else if (random_num>=6000&random_num<6100) { print_heart_flag=1; } break; case 1: if (random_num<3000) { print_cactus_flag=1; } else if (random_num>=3000&random_num<5000) { print_rat_flag=1; } else if (random_num>=5000&random_num<6000) { print_bird_flag=1; } else if (random_num>=6000&random_num<6050) { print_heart_flag=1; } else if (random_num>=6050&random_num<7000) { print_hound_flag=1; } else if (random_num>=7000&random_num<7200) { print_ammo_flag=1; } break; case 2: if (random_num<3000) { print_cactus_flag=1; } else if (random_num>=3000&random_num<5000) { print_rat_flag=1; } else if (random_num>=5000&random_num<6000) { print_bird_flag=1; } else if (random_num>=6000&random_num<6040) { print_heart_flag=1; } else if (random_num>=6040&random_num<7000) { print_hound_flag=1; } else if (random_num>=7000&random_num<7200) { print_ammo_flag=1; } else if (random_num>=7200&random_num<8000) { print_bear_flag=1; } else if (random_num>=8000&random_num<8200) { print_speed_boost_flag=1; } break; case 3: if (random_num<1000) { print_bear_flag=1; } else if (random_num>=1000&random_num<3000) { print_bird_flag=1; } else if (random_num>=3000&random_num<3010) { print_heart_flag=1; } else if (random_num>=3010&random_num<3050) { print_ammo_flag=1; } else if (random_num>=3050&random_num<6000) { print_cactus_flag=1; } else if (random_num>=6000&random_num<6100) { print_ammo_flag=1; print_t_rex_flag=1; } else if (random_num>=6100&random_num<7000) { print_rat_flag=1; } else if (random_num>=7000&random_num<8000) { print_hound_flag=1; } else if (random_num>=8000&random_num<8200) { print_speed_boost_flag=1; } break; case 4: if (random_num<1000) { print_bear_flag=1; } else if (random_num>=1000&random_num<3000) { print_bird_flag=1; } else if (random_num>=3000&random_num<3010) { print_heart_flag=1; } else if (random_num>=3010&random_num<3050) { print_ammo_flag=1; } else if (random_num>=3050&random_num<6000) { print_cactus_flag=1; } else if (random_num>=6000&random_num<6300) { print_ammo_flag=1; print_t_rex_flag=1; } else if (random_num>=6300&random_num<7000) { print_rat_flag=1; } else if (random_num>=7000&random_num<8000) { print_hound_flag=1; } else if (random_num>=8000&random_num<8200) { print_speed_boost_flag=1; } else if (random_num>=8200&random_num<9000) { print_chasm_flag=1; } break; } } int Game_over() { led_bar(); lcd.clear(); sort_top_scores(); writeSD(); lcd.printString("GAME",25,1); lcd.printString("OVER",25,2); lcd.refresh(); ticker_wait(10); lcd.printString("A Retry",40,4); lcd.printString("B Back to Menu",0,5); lcd.refresh(); g_press_b_A_flag=0; g_press_b_B_flag=0; while (1) { if (g_press_b_A_flag|g_press_b_B_flag) { if (g_press_b_A_flag) { initialize_values(); g_press_b_A_flag=0; return 1; } else { initialize_values(); g_press_b_B_flag=0; return 0; } } sleep(); } } void print_ammo() { for(int c=0; c<=2; c++) { // 2 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=4; r++) { for (int n=70; n<=74; n+=4) { if (n==74&ammo%10==0) { if (zero[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==74&ammo%10==1) { if (one[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==74&ammo%10==2) { if (two[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==74&ammo%10==3) { if (three[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==74&ammo%10==4) { if (four[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==74&ammo%10==5) { if (five[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==74&ammo%10==6) { if (six[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==74&ammo%10==7) { if (seven[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==74&ammo%10==8) { if (eight[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==74&ammo%10==9) { if (nine[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } if (n==70&(ammo%100>=0&ammo%100<10)) { if (zero[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==70&(ammo%100>=10&ammo%100<20)) { if (one[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==70&(ammo%100>=20&ammo%100<30)) { if (two[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==70&(ammo%100>=30&ammo%100<40)) { if (three[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==70&(ammo%100>=40&ammo%100<50)) { if (four[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==70&(ammo%100>=50&ammo%100<60)) { if (five[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==70&(ammo%100>=60&ammo%100<70)) { if (six[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==70&(ammo%100>=70&ammo%100<80)) { if (seven[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==70&(ammo%100>=80&ammo%100<90)) { if (eight[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==70&(ammo%100>=90&ammo%100<100)) { if (nine[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } } } } for(int c=0; c<=14; c++) { //14 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=4; r++) { if (g_ammo[r][c]==0) { lcd.clearPixel(c+50,r); } else if (g_ammo[r][c]==1) { lcd.setPixel(c+50,r); } } } if (ammo>=99) { ammo=99; } lcd.refresh(); } void print_score() { score=h_movement/10+kill_score-shield_score; if (score<=0) { score=0; } for(int c=0; c<=2; c++) { //2 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=4; r++) { for (int n=24; n<=36; n+=4) { if (n==36&score%10==0) { if (zero[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==36&score%10==1) { if (one[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==36&score%10==2) { if (two[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==36&score%10==3) { if (three[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==36&score%10==4) { if (four[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==36&score%10==5) { if (five[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==36&score%10==6) { if (six[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==36&score%10==7) { if (seven[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==36&score%10==8) { if (eight[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==36&score%10==9) { if (nine[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } if (n==32&(score%100>=0&score%100<10)) { if (zero[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==32&(score%100>=10&score%100<20)) { if (one[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==32&(score%100>=20&score%100<30)) { if (two[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==32&(score%100>=30&score%100<40)) { if (three[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==32&(score%100>=40&score%100<50)) { if (four[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==32&(score%100>=50&score%100<60)) { if (five[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==32&(score%100>=60&score%100<70)) { if (six[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==32&(score%100>=70&score%100<80)) { if (seven[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==32&(score%100>=80&score%100<90)) { if (eight[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==32&(score%100>=90&score%100<100)) { if (nine[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } if (n==28&(score%1000>=0&score%1000<100)) { if (zero[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==28&(score%1000>=100&score%1000<200)) { if (one[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==28&(score%1000>=200&score%1000<300)) { if (two[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==28&(score%1000>=300&score%1000<400)) { if (three[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==28&(score%1000>=400&score%1000<500)) { if (four[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==28&(score%1000>=500&score%1000<600)) { if (five[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==28&(score%1000>=600&score%1000<700)) { if (six[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==28&(score%1000>=700&score%1000<800)) { if (seven[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==28&(score%1000>=800&score%1000<900)) { if (eight[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==28&(score%1000>=900&score%1000<1000)) { if (nine[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } if (n==24&(score%10000>=0&score%10000<1000)) { if (zero[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==24&(score%10000>=1000&score%10000<2000)) { if (one[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==24&(score%10000>=2000&score%10000<3000)) { if (two[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==24&(score%10000>=3000&score%10000<4000)) { if (three[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==24&(score%10000>=4000&score%10000<5000)) { if (four[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==24&(score%10000>=5000&score%10000<6000)) { if (five[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==24&(score%10000>=6000&score%10000<7000)) { if (six[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==24&(score%10000>=7000&score%10000<8000)) { if (seven[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==24&(score%10000>=8000&score%10000<9000)) { if (eight[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } else if (n==24&(score%10000>=9000&score%10000<10000)) { if (nine[r][c]==1) { lcd.setPixel(c+n,r); } else { lcd.clearPixel(c+n,r); } } } } } for(int c=0; c<=18; c++) { //18 beacause the the loop stats from 0 but the array size from 1 for(int r=0; r<=4; r++) { if (g_score[r][c]==0) { lcd.clearPixel(c,r); } else if (g_score[r][c]==1) { lcd.setPixel(c,r); } } } lcd.refresh(); }