Robin Milward Cooney 200849894

Dependencies:   N5110 SDFileSystem gameCharacters mbed

Revision:
1:046e66f1ca76
Parent:
0:28392431dbad
Child:
2:158d57cdbf1e
diff -r 28392431dbad -r 046e66f1ca76 main.cpp
--- a/main.cpp	Tue Apr 26 18:44:09 2016 +0000
+++ b/main.cpp	Fri Apr 29 10:45:15 2016 +0000
@@ -11,12 +11,16 @@
 #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)
@@ -29,29 +33,39 @@
 Ticker Ticker_Game;
 
 int i;                                          //loop counter
+int run=0;
 int loop=0;
+int difficulty=2;
 int g_jump=36;
 int jumpUp;
 int accel=0;
 int bullet=9;
 int bullet_height;
 int menu_select;
-int score;
+int score=0;
+int highscore;
 int kill_score;
 int h_movement=0;
 int ammo=24;
+int rat_movement=85;
+int hound_hMovement=90;
+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 fire_ball_hMovement=t_rex_movement-6;
-int fire_ball_vMovement=27;
+int fire_ball_vMovement=25;
 int heart_movement=90;
 int ammo_movement=100;
 int menuState=0;          //initial state for the menu fsm
 int jump_flag=0;
 int shoot_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;
@@ -62,10 +76,12 @@
 int lose_lives_delay_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;
 double lives=4;
 int bear_lives=0;
 int t_rex_lives=0;
 int random_num;
+float brightness=0.5;
 volatile int g_Ticker_Menu_flag=0;
 volatile int g_Ticker_Game_flag=0;
 volatile int g_press_b_A_flag=0;
@@ -73,6 +89,8 @@
 
 void initialize_values()
 {
+    red_led = 1;
+    green_led=1;
     i=0;                                          //loop counter
     loop=0;
     g_jump=36;
@@ -80,18 +98,25 @@
     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;
     fire_ball_hMovement=t_rex_movement-6;
-    fire_ball_vMovement=27;
+    fire_ball_vMovement=25;
     heart_movement=90;
     ammo_movement=100;
     menuState=0;          //initial state for the menu fsm
     jump_flag=0;
     shoot_flag=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;
@@ -200,11 +225,6 @@
     }
 }
 
-void get_recks_still_gun()
-{
-
-}
-
 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
@@ -240,6 +260,91 @@
     }
 }
 
+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
@@ -274,7 +379,7 @@
     }
 }
 
-void print_mob_bear_dead()            //funtion to print the moving bear on the LCD
+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++) {
@@ -358,15 +463,15 @@
 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<=25; r++) {
+        for(int r=0; r<=27; r++) {
             if (g_t_rex[r][c]==0) {
-                if (lcd.getPixel(c+t_rex_movement,r+21)!=0) {
-                    lcd.setPixel(c+t_rex_movement,r+21);
+                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+21);
+                    lcd.clearPixel(c+t_rex_movement,r+19);
                 }
             } else if (g_t_rex[r][c]==1) {
-                lcd.setPixel(c+t_rex_movement,r+21);
+                lcd.setPixel(c+t_rex_movement,r+19);
             }
         }
     }
@@ -375,15 +480,15 @@
 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<=25; r++) {
+        for(int r=0; r<=27; r++) {
             if (g_t_rex_moving[r][c]==0) {
-                if (lcd.getPixel(c+t_rex_movement,r+21)!=0) {
-                    lcd.setPixel(c+t_rex_movement,r+21);
+                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+21);
+                    lcd.clearPixel(c+t_rex_movement,r+19);
                 }
             } else if (g_t_rex_moving[r][c]==1) {
-                lcd.setPixel(c+t_rex_movement,r+21);
+                lcd.setPixel(c+t_rex_movement,r+19);
             }
         }
     }
@@ -392,15 +497,15 @@
 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<=25; r++) {
+        for(int r=0; r<=27; r++) {
             if (g_t_rex_attack[r][c]==0) {
-                if (lcd.getPixel(c+t_rex_movement,r+21)!=0) {
-                    lcd.setPixel(c+t_rex_movement,r+21);
+                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+21);
+                    lcd.clearPixel(c+t_rex_movement,r+19);
                 }
             } else if (g_t_rex_attack[r][c]==1) {
-                lcd.setPixel(c+t_rex_movement,r+21);
+                lcd.setPixel(c+t_rex_movement,r+19);
             }
         }
     }
@@ -455,16 +560,34 @@
     }
 }
 
-void clearCells()   // function to clear all pixels on screen
+void print_locks()
 {
-    for (int i=0; i<85; i++) {      //go through every pixel on the x axis
-        for (int j=0; j<49; j++) {  // go through every pixel on the y axis
-            lcd.clearPixel(i,j);    // clear the cell
+    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);
+                }
+            }
         }
     }
-    lcd.refresh();                  //refresh  the lcd
+    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);
@@ -545,7 +668,7 @@
     }
 }
 
-struct motion {         //defines the motion of the charecters
+struct motion {         //defines the motion of the characters
     int x;
     int v_x;
     int acc_x;
@@ -576,6 +699,7 @@
     {32,{4,4,4,4,4}}
 };
 
+void game();
 int main()                      //main function, currently used to test different functions
 {
     b_A.mode(PullDown);
@@ -588,18 +712,17 @@
     //press_b_A.fall(&press_b_A_isr);
     //press_b_A.mode(PullDown);
     calibrateJoystick();
-    int run=0;
 
 Menu:       //declares a "goto" location for the goto functions
+    menuState=0;
     while(1) {
-
         if (g_Ticker_Menu_flag) {
             g_Ticker_Menu_flag=0;
             updateJoystick();
-            generate_random_number();
+            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
-            clearCells();
+            lcd.clear();
             lcd.printString("Story mode",13,0);
             lcd.printString("Minigame",18,1);
             lcd.printString("Settings",18,2);
@@ -631,7 +754,48 @@
     }
 
 Story_Mode:
-Minigame:
+    menuState=0;
+    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("Chapter 1",20,0);
+            lcd.printString("Chapter 2",20,1);
+            lcd.printString("Chapter 3",20,2);
+            lcd.printString("Chapter 4",20,3);
+            lcd.printString("Chapter 5",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) {
+                goto Story_Mode;
+            } else if (b_A & menu_select==8&story_progress<=2) {
+                goto Minigame;
+            } else if (b_A & menu_select==16&story_progress<=3) {
+                goto Settings;
+            } else if (b_A & menu_select==24&story_progress<=4) {
+                goto Leaderboard;
+            } else if (b_A & menu_select==32&story_progress<=5) {
+                goto Credits;
+            }
+            if (b_B) {
+                goto Menu;
+            }
+        }
+        sleep();
+    }
 Settings:
     menuState=0;
     while (1) {
@@ -640,9 +804,9 @@
             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
-            clearCells();
+            lcd.clear();
             lcd.printString("Brightness",13,0);
-            lcd.printString("Music",18,1);
+            lcd.printString("Difficulty",13,1);
             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
@@ -656,435 +820,665 @@
             if (b_A & menu_select==0) {
                 goto Brightness;
             } else if (b_A & menu_select==8) {
-                goto Music;
+                goto Difficulty;
+            }
+            if (b_B) {
+                goto Menu;
             }
         }
     }
 Brightness:
-Music:
+    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;
+                goto Menu;
+            } else if (b_A & menu_select==8) {
+                brightness=0.3;
+                goto Menu;
+            } else if (b_A & menu_select==16) {
+                brightness=0.5;
+                goto Menu;
+            } else if (b_A & menu_select==24) {
+                brightness=0.7;
+                goto Menu;
+            } else if (b_A & menu_select==32) {
+                brightness=1;
+                goto Menu;
+            }
+            if (b_B) {
+                goto Settings;
+            }
+        }
+        sleep();
+    }
+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;
+                goto Menu;
+            } else if (b_A & menu_select==8) {
+                difficulty=1;
+                goto Menu;
+            } else if (b_A & menu_select==16) {
+                difficulty=2;
+                goto Menu;
+            } else if (b_A & menu_select==24) {
+                difficulty=3;
+                goto Menu;
+            } else if (b_A & menu_select==32) {
+                difficulty=4;
+                goto Menu;
+            }
+            if (b_B) {
+                goto Settings;
+            }
+        }
+        sleep();
+    }
 Leaderboard:
+    while(1) {
+        lcd.clear();
+        char buffer[14];
+        int p = sprintf(buffer,"%d",score);
+        if (g_Ticker_Menu_flag) {
+            g_Ticker_Menu_flag=0;
+            FILE *Highscores = fopen("/sd/Highscores.txt", "w");
+            if (Highscores!=NULL) {
+                green_led=0;
+                fscanf(Highscores, "%d", &score);
+                fclose(Highscores);
+                lcd.printString("Highscore:",0,0);
+                lcd.printString(buffer,10,3);
+            } else if (Highscores!=NULL) {
+                red_led=0;
+                lcd.printString("Error reading",0,0);
+                lcd.printString("file try",0,1);
+                lcd.printString("re-inserting",0,2);
+                lcd.printString("SD card",0,3);
+            }
+        }
+        lcd.refresh();
+        sleep();
+    }
 Credits:
+Minigame:
 Continue:
     wait(0.5);
     while (1) {
-        clearCells();
-        updateJoystick();
-        led_bar();
-        print_score();
-        generate_random_number();
         if (g_Ticker_Game_flag) {
             g_Ticker_Game_flag=0;
             if (lives==0) {
                 goto GameOver;
             }
-            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 (swJoy==1) {
                 goto Pause;
             }
-            if (shoot_flag==0) {
-                bullet=9;
-                if (joystick.direction==DOWN) {
-                    bullet_height=40;
-                } 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 (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<7000) {
-                print_ammo_flag=1;
-                print_t_rex_flag=1;
-            }
-            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=27;
-            }
-            if (joystick.direction==CENTRE&jump_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) {
-                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) {
-                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) {
-                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) {
-                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;
-                }
-            }
+            lcd.clear();
+            updateJoystick();
+            game();
+
         }
-        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++;
-            } else if (joystick.direction==RIGHT) {
-                bear_movement--;
-            }
-            bear_movement-=2;
-            if (bear_movement<=-15) {
-                bear_movement=100;
-                print_bear_flag=0;
-            }
-            if (bear_movement<=8&bear_movement>=-5&g_jump>28&lose_lives_delay_flag==0) {     //a life is lost if recks has an vertical and horizontal position equal to one of the pixels corresponding to the bears position
-                lives--;
-                lose_lives_delay_flag=1;
-            }
-            if (shoot_flag==1&bullet_height<72) {
-                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++;
-            } else if (joystick.direction==RIGHT) {
-                bird_hMovement--;
-            }
-            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)) {
-                lives--;
-                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++;
-            } else if (joystick.direction==RIGHT) {
-                cactus_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) {
-                lives--;
-                lose_lives_delay_flag=1;
-            }
-        }
-
-        if (print_t_rex_flag==1) {
-            if (joystick.direction==LEFT) {
-                t_rex_movement++;
-            } else if (joystick.direction==RIGHT) {
-                t_rex_movement--;
-            }
-            if (random_num%4==0&print_fire_ball_flag!=1) {
-                t_rex_movement+=2;
-                print_t_rex_moving();
-            } else if (random_num%4==1&print_fire_ball_flag!=1) {
-                t_rex_movement-=2;
-                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) {
-                lives--;
-                lose_lives_delay_flag=1;
-            }
-        }
-        if (print_fire_ball_flag==1) {
-            print_t_rex_attack();
-            fire_ball_hMovement-=2;
-            if (joystick.direction==LEFT) {
-                fire_ball_hMovement++;
-            } else if (joystick.direction==RIGHT) {
-                fire_ball_hMovement--;
-            }
-            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) {
-                lives--;
-                lose_lives_delay_flag=1;
-            }
-            if (shoot_flag==1) {
-                t_rex_lives++;
-                if (t_rex_lives>=24-3*g_g1-3*g_g2) {
-                    print_t_rex_flag=0;
-                    t_rex_movement=120;
-                    kill_score+=20;
-                    t_rex_lives=0;
-                }
-            }
-        }
-        if (print_heart_flag==1)    {
-            print_heart();
-            if (joystick.direction==LEFT) {
-                heart_movement++;
-            } else if (joystick.direction==RIGHT) {
-                heart_movement--;
-            }
-            if (heart_movement<=5&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++;
-            } else if (joystick.direction==RIGHT) {
-                ammo_movement--;
-            }
-            if (ammo_movement<=5&g_jump>26) {
-                ammo_movement=90;
-                print_ammo_flag=0;
-                ammo+=5;
-                ammo+=rand()%7;
-            }
-        }
-        print_clouds();
-        ground();
         i++;
         lcd.refresh();
         sleep();
     }
 
 Pause:
+    int q;
     while (1) {
-        clearCells();
-        wait(0.2);
-        if (swJoy==1) {
-            goto Continue;
+        q++;
+        lcd.printString("PAUSED",25,3);
+        if (g_Ticker_Menu_flag) {
+            g_Ticker_Menu_flag=0;
+            if (swJoy&q>5) {
+                q=0;
+                lcd.setBrightness(brightness);
+                led_bar();
+                goto Continue;
+            } else if (q>=20) {
+                lcd.setBrightness(0);
+                led=0;
+            }
         }
+        sleep();
     }
 GameOver:
-    clearCells();
-    lcd.printString("GAME",25,1);
-    lcd.printString("OVER",25,2);
+    char buffer[14];
+    int p = sprintf(buffer,"%d",score);
+    FILE *Highscores = fopen("/sd/Highscores.txt", "w");
+    if (Highscores!=NULL) {
+        fprintf(Highscores, "%d\n", highscore);
+        fclose(Highscores);
+        green_led=0;
+    } else {
+        red_led=0;
+    }
+    led_bar();
+    lcd.clear();
+    for (int freeze=0; freeze<=30; freeze++) {
+        if (g_Ticker_Menu_flag) {
+            g_Ticker_Menu_flag=0;
+            lcd.clear();
+            lcd.printString("GAME",25,1);
+            lcd.printString("OVER",25,2);
+            lcd.refresh();
+        }
+        sleep();
+    }
+    green_led=1;
+    red_led=1;
     lcd.printString("A Retry",40,4);
     lcd.printString("B Back to Menu",0,5);
+    lcd.refresh();
     while (1) {
-        if (b_A==1) {
-            wait(0.2);
-            initialize_values();
-            goto Continue;
-        } else if (b_B==1) {
-            wait(0.2);
-            initialize_values();
-            goto Menu;
+        if (g_Ticker_Menu_flag) {
+            g_Ticker_Menu_flag=0;
+            if (b_A==1) {
+                initialize_values();
+                goto Continue;
+            } else if (b_B==1) {
+                initialize_values();
+                goto Menu;
+            }
         }
+        sleep();
     }
 }
 
 
-
-
-
 // -----------------------------------------------------------------------------------------------------------------------------------------
 
-void game() {
-    
-    };
+void game()
+{
+    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) {
+            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 (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<800) {
+        print_hound_flag=1;
+    }
+
+    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) {
+        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) {
+        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) {
+        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) {
+        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) {
+        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++;
+        } else if (joystick.direction==RIGHT) {
+            rat_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) {     //a life is lost if recks has an vertical and horizontal position equal to one of the pixels corresponding to the bears position
+            lives--;
+            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++;
+        } else if (joystick.direction==RIGHT) {
+            hound_hMovement--;
+        }
+        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>28&lose_lives_delay_flag==0&hound_jump_flag!=1)|(hound_hMovement<=8&hound_hMovement>=-5&g_jump>22&lose_lives_delay_flag==0&hound_jump_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--;
+            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++;
+        } else if (joystick.direction==RIGHT) {
+            bear_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) {     //a life is lost if recks has an vertical and horizontal position equal to one of the pixels corresponding to the bears position
+            lives--;
+            lose_lives_delay_flag=1;
+        }
+        if (shoot_flag==1&bullet_height>8) {
+            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++;
+        } else if (joystick.direction==RIGHT) {
+            bird_hMovement--;
+        }
+        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)) {
+            lives--;
+            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++;
+        } else if (joystick.direction==RIGHT) {
+            cactus_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) {
+            lives--;
+            lose_lives_delay_flag=1;
+        }
+    }
+
+    if (print_t_rex_flag==1) {
+        if (joystick.direction==LEFT) {
+            t_rex_movement++;
+        } else if (joystick.direction==RIGHT) {
+            t_rex_movement--;
+        }
+        if (random_num%4==0&print_fire_ball_flag!=1) {
+            t_rex_movement+=2;
+            print_t_rex_moving();
+        } else if (random_num%4==1&print_fire_ball_flag!=1) {
+            t_rex_movement-=2;
+            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) {
+            lives--;
+            lose_lives_delay_flag=1;
+        }
+    }
+    if (print_fire_ball_flag==1) {
+        print_t_rex_attack();
+        fire_ball_hMovement-=2;
+        if (joystick.direction==LEFT) {
+            fire_ball_hMovement++;
+        } else if (joystick.direction==RIGHT) {
+            fire_ball_hMovement--;
+        }
+        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) {
+            lives--;
+            lose_lives_delay_flag=1;
+        }
+        if (shoot_flag==1) {
+            t_rex_lives++;
+            if (t_rex_lives>=24-3*g_g1-3*g_g2) {
+                print_t_rex_flag=0;
+                t_rex_movement=120;
+                kill_score+=20;
+                t_rex_lives=0;
+            }
+        }
+    }
+    if (print_heart_flag==1) {
+        print_heart();
+        if (joystick.direction==LEFT) {
+            heart_movement++;
+        } else if (joystick.direction==RIGHT) {
+            heart_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++;
+        } else if (joystick.direction==RIGHT) {
+            ammo_movement--;
+        }
+        if (ammo_movement<=7&g_jump>26) {
+            ammo_movement=90;
+            print_ammo_flag=0;
+            ammo+=5;
+            ammo+=rand()%7;
+        }
+    }
+    print_clouds();
+    ground();
+}
 
 void print_ammo()
 {