![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
demo
Dependencies: mbed Gamepad N5110
main.cpp@0:ba32cfe0051e, 2020-05-14 (annotated)
- Committer:
- Ting12138
- Date:
- Thu May 14 12:57:32 2020 +0000
- Revision:
- 0:ba32cfe0051e
- Child:
- 1:7b5a843acc05
demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ting12138 | 0:ba32cfe0051e | 1 | ///////// pre-processor directives //////// |
Ting12138 | 0:ba32cfe0051e | 2 | /* |
Ting12138 | 0:ba32cfe0051e | 3 | ELEC2645 Embed Systems Project |
Ting12138 | 0:ba32cfe0051e | 4 | School of Electronic &Electrical Engineering |
Ting12138 | 0:ba32cfe0051e | 5 | University of Leeds |
Ting12138 | 0:ba32cfe0051e | 6 | |
Ting12138 | 0:ba32cfe0051e | 7 | Name:Liu Liting |
Ting12138 | 0:ba32cfe0051e | 8 | Username:el17ll |
Ting12138 | 0:ba32cfe0051e | 9 | Student ID Number: ID For LEEDS:201199465 ID For SWJTU:2017110353 |
Ting12138 | 0:ba32cfe0051e | 10 | Date: 15/05/2020 |
Ting12138 | 0:ba32cfe0051e | 11 | */ |
Ting12138 | 0:ba32cfe0051e | 12 | #include "mbed.h" |
Ting12138 | 0:ba32cfe0051e | 13 | #include "Gamepad.h" |
Ting12138 | 0:ba32cfe0051e | 14 | #include "N5110.h" |
Ting12138 | 0:ba32cfe0051e | 15 | #include "Engine.h" |
Ting12138 | 0:ba32cfe0051e | 16 | #include "main.h" |
Ting12138 | 0:ba32cfe0051e | 17 | |
Ting12138 | 0:ba32cfe0051e | 18 | #define THE_WALL_WIDTH 2 |
Ting12138 | 0:ba32cfe0051e | 19 | #define THE_WALL_GAP 12 |
Ting12138 | 0:ba32cfe0051e | 20 | #define ROCKET_SIZE 2 |
Ting12138 | 0:ba32cfe0051e | 21 | #define FOODS_SIZE 2 |
Ting12138 | 0:ba32cfe0051e | 22 | #define SPEED 2 |
Ting12138 | 0:ba32cfe0051e | 23 | |
Ting12138 | 0:ba32cfe0051e | 24 | /////////////// structs ///////////////// |
Ting12138 | 0:ba32cfe0051e | 25 | struct UserInput { |
Ting12138 | 0:ba32cfe0051e | 26 | Direction d; |
Ting12138 | 0:ba32cfe0051e | 27 | float mag; |
Ting12138 | 0:ba32cfe0051e | 28 | Vector2D mapped_coord; |
Ting12138 | 0:ba32cfe0051e | 29 | }; |
Ting12138 | 0:ba32cfe0051e | 30 | /////////////// objects /////////////// |
Ting12138 | 0:ba32cfe0051e | 31 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
Ting12138 | 0:ba32cfe0051e | 32 | Gamepad pad; |
Ting12138 | 0:ba32cfe0051e | 33 | Engine eng; |
Ting12138 | 0:ba32cfe0051e | 34 | |
Ting12138 | 0:ba32cfe0051e | 35 | ///////////// prototypes /////////////// |
Ting12138 | 0:ba32cfe0051e | 36 | void init(); |
Ting12138 | 0:ba32cfe0051e | 37 | void update_game(UserInput input); |
Ting12138 | 0:ba32cfe0051e | 38 | void renders(); |
Ting12138 | 0:ba32cfe0051e | 39 | void beginning(); |
Ting12138 | 0:ba32cfe0051e | 40 | void end_game(); |
Ting12138 | 0:ba32cfe0051e | 41 | void introduction(); |
Ting12138 | 0:ba32cfe0051e | 42 | void finger_snap(); |
Ting12138 | 0:ba32cfe0051e | 43 | |
Ting12138 | 0:ba32cfe0051e | 44 | ///////////// Images /////////////// |
Ting12138 | 0:ba32cfe0051e | 45 | const int symbol1[25][32] = { |
Ting12138 | 0:ba32cfe0051e | 46 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 47 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 48 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 49 | { 0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 50 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 51 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 52 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 53 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 54 | { 0,0,0,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,0,1,0,0,1,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 55 | { 0,0,0,1,0,0,0,1,1,0,0,1,0,0,0,0,1,1,0,0,1,0,1,0,1,1,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 56 | { 0,0,0,1,0,0,0,1,1,0,1,1,0,0,0,1,0,0,1,1,1,0,1,1,0,1,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 57 | { 0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,1,0,0,1,0,0,0,1,0,1,1,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 58 | { 0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,0,0,1,0,1,1,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 59 | { 0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 60 | { 0,0,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 61 | { 0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 62 | { 0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 63 | { 0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 64 | { 0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 65 | { 0,0,0,0,0,0,0,0,0,1,1,0,1,0,1,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 66 | { 0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 67 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 68 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 69 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 70 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 71 | |
Ting12138 | 0:ba32cfe0051e | 72 | |
Ting12138 | 0:ba32cfe0051e | 73 | }; |
Ting12138 | 0:ba32cfe0051e | 74 | |
Ting12138 | 0:ba32cfe0051e | 75 | const int symbol2[25][32] = { |
Ting12138 | 0:ba32cfe0051e | 76 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 77 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 78 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 79 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 80 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 81 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 82 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 83 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 84 | { 0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,0,1,0,0,1,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 85 | { 0,0,1,1,1,0,0,1,1,0,0,1,0,0,0,0,1,1,0,0,1,0,1,0,1,1,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 86 | { 0,0,0,1,0,0,0,1,1,0,1,1,0,0,0,1,0,0,1,1,1,0,1,1,0,1,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 87 | { 0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,1,0,0,1,0,0,0,1,0,1,1,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 88 | { 0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,0,0,1,0,1,1,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 89 | { 0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 90 | { 0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 91 | { 0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 92 | { 0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 93 | { 0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 94 | { 0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 95 | { 0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 96 | { 0,0,0,1,0,0,0,0,0,0,0,1,1,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 97 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 98 | { 0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 99 | { 0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 100 | { 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 101 | |
Ting12138 | 0:ba32cfe0051e | 102 | }; |
Ting12138 | 0:ba32cfe0051e | 103 | |
Ting12138 | 0:ba32cfe0051e | 104 | |
Ting12138 | 0:ba32cfe0051e | 105 | //////////////// the main functions ////////////////////// |
Ting12138 | 0:ba32cfe0051e | 106 | int main() { |
Ting12138 | 0:ba32cfe0051e | 107 | while (1) { |
Ting12138 | 0:ba32cfe0051e | 108 | int fps = 6; |
Ting12138 | 0:ba32cfe0051e | 109 | |
Ting12138 | 0:ba32cfe0051e | 110 | init(); // initialise and then display screen... |
Ting12138 | 0:ba32cfe0051e | 111 | beginning(); |
Ting12138 | 0:ba32cfe0051e | 112 | introduction(); // The intro of the story |
Ting12138 | 0:ba32cfe0051e | 113 | renders(); |
Ting12138 | 0:ba32cfe0051e | 114 | wait(1.0f/fps); // and wait for one frame period |
Ting12138 | 0:ba32cfe0051e | 115 | |
Ting12138 | 0:ba32cfe0051e | 116 | while (1) { |
Ting12138 | 0:ba32cfe0051e | 117 | eng.read_input(pad); |
Ting12138 | 0:ba32cfe0051e | 118 | eng.update(pad); |
Ting12138 | 0:ba32cfe0051e | 119 | renders(); |
Ting12138 | 0:ba32cfe0051e | 120 | wait(1.0f/fps); |
Ting12138 | 0:ba32cfe0051e | 121 | if (eng.get_final_score() < 3) { // setting diffculty to regard the current ffoods number |
Ting12138 | 0:ba32cfe0051e | 122 | fps = 6; |
Ting12138 | 0:ba32cfe0051e | 123 | } |
Ting12138 | 0:ba32cfe0051e | 124 | if (eng.get_final_score() == 3) { |
Ting12138 | 0:ba32cfe0051e | 125 | fps = 9; |
Ting12138 | 0:ba32cfe0051e | 126 | } |
Ting12138 | 0:ba32cfe0051e | 127 | if (eng.get_final_score() == 4) { |
Ting12138 | 0:ba32cfe0051e | 128 | fps = 12; |
Ting12138 | 0:ba32cfe0051e | 129 | } |
Ting12138 | 0:ba32cfe0051e | 130 | if (eng.get_final_score() == 5) { |
Ting12138 | 0:ba32cfe0051e | 131 | fps = 15; |
Ting12138 | 0:ba32cfe0051e | 132 | } |
Ting12138 | 0:ba32cfe0051e | 133 | if (eng.get_final_score() == 6) { // you win!! |
Ting12138 | 0:ba32cfe0051e | 134 | finger_snap(); |
Ting12138 | 0:ba32cfe0051e | 135 | break; |
Ting12138 | 0:ba32cfe0051e | 136 | } else if (eng.get_final_score() < 0) { // you lose :( |
Ting12138 | 0:ba32cfe0051e | 137 | end_game(); |
Ting12138 | 0:ba32cfe0051e | 138 | break; |
Ting12138 | 0:ba32cfe0051e | 139 | } |
Ting12138 | 0:ba32cfe0051e | 140 | } |
Ting12138 | 0:ba32cfe0051e | 141 | } |
Ting12138 | 0:ba32cfe0051e | 142 | } |
Ting12138 | 0:ba32cfe0051e | 143 | |
Ting12138 | 0:ba32cfe0051e | 144 | /////////////the introduction part//////////////// |
Ting12138 | 0:ba32cfe0051e | 145 | const int introduction1[8][84] = { |
Ting12138 | 0:ba32cfe0051e | 146 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 147 | { 1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 148 | { 1,1,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0 }, |
Ting12138 | 0:ba32cfe0051e | 149 | { 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1 }, |
Ting12138 | 0:ba32cfe0051e | 150 | { 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1 }, |
Ting12138 | 0:ba32cfe0051e | 151 | { 1,1,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0 }, |
Ting12138 | 0:ba32cfe0051e | 152 | { 1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 153 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 154 | }; |
Ting12138 | 0:ba32cfe0051e | 155 | const int introduction2[8][80] = { |
Ting12138 | 0:ba32cfe0051e | 156 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 157 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 158 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0 }, |
Ting12138 | 0:ba32cfe0051e | 159 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1 }, |
Ting12138 | 0:ba32cfe0051e | 160 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1 }, |
Ting12138 | 0:ba32cfe0051e | 161 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0 }, |
Ting12138 | 0:ba32cfe0051e | 162 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 163 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 164 | }; |
Ting12138 | 0:ba32cfe0051e | 165 | const int introduction3[8][80] = { |
Ting12138 | 0:ba32cfe0051e | 166 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 167 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 168 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0 }, |
Ting12138 | 0:ba32cfe0051e | 169 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1 }, |
Ting12138 | 0:ba32cfe0051e | 170 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1 }, |
Ting12138 | 0:ba32cfe0051e | 171 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0 }, |
Ting12138 | 0:ba32cfe0051e | 172 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 173 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 174 | }; |
Ting12138 | 0:ba32cfe0051e | 175 | |
Ting12138 | 0:ba32cfe0051e | 176 | const int intro3[16][18] = { |
Ting12138 | 0:ba32cfe0051e | 177 | { 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 178 | { 0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 179 | { 0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 180 | { 0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 181 | { 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 182 | { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 183 | { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 }, |
Ting12138 | 0:ba32cfe0051e | 184 | { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, |
Ting12138 | 0:ba32cfe0051e | 185 | { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, |
Ting12138 | 0:ba32cfe0051e | 186 | { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 }, |
Ting12138 | 0:ba32cfe0051e | 187 | { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 188 | { 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 189 | { 0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 190 | { 0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 191 | { 0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 192 | { 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0 }, |
Ting12138 | 0:ba32cfe0051e | 193 | }; |
Ting12138 | 0:ba32cfe0051e | 194 | |
Ting12138 | 0:ba32cfe0051e | 195 | void init() { |
Ting12138 | 0:ba32cfe0051e | 196 | // need to initialise LCD and Gamepad |
Ting12138 | 0:ba32cfe0051e | 197 | lcd.init(); |
Ting12138 | 0:ba32cfe0051e | 198 | pad.init(); |
Ting12138 | 0:ba32cfe0051e | 199 | |
Ting12138 | 0:ba32cfe0051e | 200 | // initialise the game with correct ball and paddle sizes |
Ting12138 | 0:ba32cfe0051e | 201 | eng.init(THE_WALL_WIDTH,THE_WALL_GAP,FOODS_SIZE,SPEED); |
Ting12138 | 0:ba32cfe0051e | 202 | } |
Ting12138 | 0:ba32cfe0051e | 203 | |
Ting12138 | 0:ba32cfe0051e | 204 | void beginning() { |
Ting12138 | 0:ba32cfe0051e | 205 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 206 | lcd.printString("The power food",0,0); //play messages |
Ting12138 | 0:ba32cfe0051e | 207 | lcd.printString("Start story",9,4); |
Ting12138 | 0:ba32cfe0051e | 208 | lcd.drawSprite(25,8,25,32,(int *)symbol1); |
Ting12138 | 0:ba32cfe0051e | 209 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 210 | pad.tone(440.00,0.60); // adding the theme music, which is my favorite song(hei,hei) |
Ting12138 | 0:ba32cfe0051e | 211 | wait(0.60); |
Ting12138 | 0:ba32cfe0051e | 212 | pad.tone(329.63,0.60); |
Ting12138 | 0:ba32cfe0051e | 213 | wait(0.60); |
Ting12138 | 0:ba32cfe0051e | 214 | pad.tone(392.00,0.60); |
Ting12138 | 0:ba32cfe0051e | 215 | wait(0.60); |
Ting12138 | 0:ba32cfe0051e | 216 | |
Ting12138 | 0:ba32cfe0051e | 217 | pad.tone(392.00,0.30); |
Ting12138 | 0:ba32cfe0051e | 218 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 219 | pad.tone(293.66,0.30); |
Ting12138 | 0:ba32cfe0051e | 220 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 221 | pad.tone(293.66,0.30); |
Ting12138 | 0:ba32cfe0051e | 222 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 223 | pad.tone(261.63,0.30); |
Ting12138 | 0:ba32cfe0051e | 224 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 225 | pad.tone(293.66,0.30); |
Ting12138 | 0:ba32cfe0051e | 226 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 227 | pad.tone(261.63,0.30); |
Ting12138 | 0:ba32cfe0051e | 228 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 229 | pad.tone(392.00,0.30); |
Ting12138 | 0:ba32cfe0051e | 230 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 231 | pad.tone(293.66,0.15); |
Ting12138 | 0:ba32cfe0051e | 232 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 233 | pad.tone(261.63,0.15); |
Ting12138 | 0:ba32cfe0051e | 234 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 235 | pad.tone(293.66,0.30); |
Ting12138 | 0:ba32cfe0051e | 236 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 237 | pad.tone(392.00,0.30); |
Ting12138 | 0:ba32cfe0051e | 238 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 239 | |
Ting12138 | 0:ba32cfe0051e | 240 | while (pad.check_event(Gamepad::START_PRESSED) == false) { // animation loop until start button is pressed |
Ting12138 | 0:ba32cfe0051e | 241 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 242 | lcd.printString("Look for food",0,0); |
Ting12138 | 0:ba32cfe0051e | 243 | lcd.printString("Start story",9,4); |
Ting12138 | 0:ba32cfe0051e | 244 | lcd.drawSprite(25,8,25,32,(int *)symbol1); |
Ting12138 | 0:ba32cfe0051e | 245 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 246 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 247 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 248 | lcd.printString("Look for food",0,0); |
Ting12138 | 0:ba32cfe0051e | 249 | lcd.printString("Start story",9,4); |
Ting12138 | 0:ba32cfe0051e | 250 | lcd.drawSprite(25,8,25,32,(int *)symbol2); |
Ting12138 | 0:ba32cfe0051e | 251 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 252 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 253 | } |
Ting12138 | 0:ba32cfe0051e | 254 | } |
Ting12138 | 0:ba32cfe0051e | 255 | |
Ting12138 | 0:ba32cfe0051e | 256 | void introduction() { // background story |
Ting12138 | 0:ba32cfe0051e | 257 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 258 | lcd.printString("Liu Liting",0,0); |
Ting12138 | 0:ba32cfe0051e | 259 | lcd.printString("ID:201199465",0,4); |
Ting12138 | 0:ba32cfe0051e | 260 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 261 | wait(1.0); |
Ting12138 | 0:ba32cfe0051e | 262 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 263 | lcd.printString("long long ago",0,0); |
Ting12138 | 0:ba32cfe0051e | 264 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 265 | wait(1.0); |
Ting12138 | 0:ba32cfe0051e | 266 | lcd.printString("Since the",6,2); |
Ting12138 | 0:ba32cfe0051e | 267 | lcd.printString("earth destoried",0,3); |
Ting12138 | 0:ba32cfe0051e | 268 | lcd.printString("we need go",9,4); |
Ting12138 | 0:ba32cfe0051e | 269 | lcd.printString("to find",18,5); |
Ting12138 | 0:ba32cfe0051e | 270 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 271 | wait(1.0); |
Ting12138 | 0:ba32cfe0051e | 272 | lcd.printString("(Press start)",3,1); |
Ting12138 | 0:ba32cfe0051e | 273 | wait(1.0); |
Ting12138 | 0:ba32cfe0051e | 274 | while (pad.check_event(Gamepad::START_PRESSED) == false) { // while-looping until the button is on |
Ting12138 | 0:ba32cfe0051e | 275 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 276 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 277 | } |
Ting12138 | 0:ba32cfe0051e | 278 | |
Ting12138 | 0:ba32cfe0051e | 279 | lcd.clear(); // background story |
Ting12138 | 0:ba32cfe0051e | 280 | lcd.printString("You will ",12,0); |
Ting12138 | 0:ba32cfe0051e | 281 | lcd.printString("control them",9,1); |
Ting12138 | 0:ba32cfe0051e | 282 | lcd.printString("to get what",6,2); |
Ting12138 | 0:ba32cfe0051e | 283 | lcd.printString("you need to",9,3); |
Ting12138 | 0:ba32cfe0051e | 284 | lcd.printString("then travel in",0,4); |
Ting12138 | 0:ba32cfe0051e | 285 | lcd.printString("the forest",3,5); |
Ting12138 | 0:ba32cfe0051e | 286 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 287 | wait(1.0); |
Ting12138 | 0:ba32cfe0051e | 288 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { // while-looping until the button is on |
Ting12138 | 0:ba32cfe0051e | 289 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 290 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 291 | } |
Ting12138 | 0:ba32cfe0051e | 292 | |
Ting12138 | 0:ba32cfe0051e | 293 | while (pad.check_event(Gamepad::START_PRESSED) == false) { // tutorial with animation |
Ting12138 | 0:ba32cfe0051e | 294 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 295 | lcd.printString("Useing your",10,0); |
Ting12138 | 0:ba32cfe0051e | 296 | lcd.printString("joystick to",8,1); |
Ting12138 | 0:ba32cfe0051e | 297 | lcd.printString("send yourself",2,2); |
Ting12138 | 0:ba32cfe0051e | 298 | lcd.printString("to the right",5,3); |
Ting12138 | 0:ba32cfe0051e | 299 | lcd.printString("forest",17,4); |
Ting12138 | 0:ba32cfe0051e | 300 | lcd.drawSprite(2,40,8,80,(int *)introduction1); |
Ting12138 | 0:ba32cfe0051e | 301 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 302 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 303 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 304 | lcd.printString("Useing your",10,0); |
Ting12138 | 0:ba32cfe0051e | 305 | lcd.printString("joystick to",8,1); |
Ting12138 | 0:ba32cfe0051e | 306 | lcd.printString("send yourself",2,2); |
Ting12138 | 0:ba32cfe0051e | 307 | lcd.printString("to the right",5,3); |
Ting12138 | 0:ba32cfe0051e | 308 | lcd.printString("forest",17,4); |
Ting12138 | 0:ba32cfe0051e | 309 | lcd.drawSprite(2,40,8,80,(int *)introduction2); |
Ting12138 | 0:ba32cfe0051e | 310 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 311 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 312 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 313 | lcd.printString("Useing your",10,0); |
Ting12138 | 0:ba32cfe0051e | 314 | lcd.printString("joystick to",8,1); |
Ting12138 | 0:ba32cfe0051e | 315 | lcd.printString("send yourself",2,2); |
Ting12138 | 0:ba32cfe0051e | 316 | lcd.printString("to the right",5,3); |
Ting12138 | 0:ba32cfe0051e | 317 | lcd.printString("forest",17,4); |
Ting12138 | 0:ba32cfe0051e | 318 | lcd.drawSprite(2,40,8,80,(int *)introduction3); |
Ting12138 | 0:ba32cfe0051e | 319 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 320 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 321 | } |
Ting12138 | 0:ba32cfe0051e | 322 | |
Ting12138 | 0:ba32cfe0051e | 323 | while (pad.check_event(Gamepad::START_PRESSED) == false) { // tutorial with animation |
Ting12138 | 0:ba32cfe0051e | 324 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 325 | lcd.printString("try not to",0,0); |
Ting12138 | 0:ba32cfe0051e | 326 | lcd.printString("interrupt it",0,1); |
Ting12138 | 0:ba32cfe0051e | 327 | lcd.printString("line when",0,3); |
Ting12138 | 0:ba32cfe0051e | 328 | lcd.printString("pass thro.",0,4); |
Ting12138 | 0:ba32cfe0051e | 329 | lcd.printString("the gap",0,5); |
Ting12138 | 0:ba32cfe0051e | 330 | lcd.drawSprite(54,16,16,18,(int *)intro3); |
Ting12138 | 0:ba32cfe0051e | 331 | lcd.drawRect(78,0,2,18,FILL_BLACK); |
Ting12138 | 0:ba32cfe0051e | 332 | lcd.drawRect(78,30,2,18,FILL_BLACK); |
Ting12138 | 0:ba32cfe0051e | 333 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 334 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 335 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 336 | lcd.printString("try not to",0,0); |
Ting12138 | 0:ba32cfe0051e | 337 | lcd.printString("interrupt it",0,1); |
Ting12138 | 0:ba32cfe0051e | 338 | lcd.printString("line when",0,3); |
Ting12138 | 0:ba32cfe0051e | 339 | lcd.printString("pass thro.",0,4); |
Ting12138 | 0:ba32cfe0051e | 340 | lcd.printString("the gap",0,5); |
Ting12138 | 0:ba32cfe0051e | 341 | lcd.drawSprite(62,16,16,18,(int *)intro3); |
Ting12138 | 0:ba32cfe0051e | 342 | lcd.drawRect(78,0,2,18,FILL_BLACK); |
Ting12138 | 0:ba32cfe0051e | 343 | lcd.drawRect(78,30,2,18,FILL_BLACK); |
Ting12138 | 0:ba32cfe0051e | 344 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 345 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 346 | } |
Ting12138 | 0:ba32cfe0051e | 347 | |
Ting12138 | 0:ba32cfe0051e | 348 | lcd.clear(); // last message before the game begins |
Ting12138 | 0:ba32cfe0051e | 349 | lcd.printString("rearch 6",12,0); |
Ting12138 | 0:ba32cfe0051e | 350 | lcd.printString("foods and then",0,1); |
Ting12138 | 0:ba32cfe0051e | 351 | lcd.printString("win the game",6,2); |
Ting12138 | 0:ba32cfe0051e | 352 | lcd.printString("God speed",15,3); |
Ting12138 | 0:ba32cfe0051e | 353 | lcd.printString("Going!",15,4); |
Ting12138 | 0:ba32cfe0051e | 354 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 355 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 356 | |
Ting12138 | 0:ba32cfe0051e | 357 | while (pad.check_event(Gamepad::START_PRESSED) == false) { //sparking leds |
Ting12138 | 0:ba32cfe0051e | 358 | pad.leds_on(); |
Ting12138 | 0:ba32cfe0051e | 359 | wait(0.25); |
Ting12138 | 0:ba32cfe0051e | 360 | pad.leds_off(); |
Ting12138 | 0:ba32cfe0051e | 361 | wait(0.25); |
Ting12138 | 0:ba32cfe0051e | 362 | } |
Ting12138 | 0:ba32cfe0051e | 363 | } |
Ting12138 | 0:ba32cfe0051e | 364 | |
Ting12138 | 0:ba32cfe0051e | 365 | void renders() { |
Ting12138 | 0:ba32cfe0051e | 366 | // clear screen, re-draw and refresh |
Ting12138 | 0:ba32cfe0051e | 367 | lcd.clear(); |
Ting12138 | 0:ba32cfe0051e | 368 | eng.draw(lcd); |
Ting12138 | 0:ba32cfe0051e | 369 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 370 | } |
Ting12138 | 0:ba32cfe0051e | 371 | |
Ting12138 | 0:ba32cfe0051e | 372 | void finger_snap() { |
Ting12138 | 0:ba32cfe0051e | 373 | lcd.clear(); // at this point the game has broken the while loop, clear screen to display congrat message |
Ting12138 | 0:ba32cfe0051e | 374 | lcd.printString("Congrat!!",17,0); |
Ting12138 | 0:ba32cfe0051e | 375 | lcd.printString("Liu Liting",0,1); |
Ting12138 | 0:ba32cfe0051e | 376 | lcd.printString("201199465",15,2); |
Ting12138 | 0:ba32cfe0051e | 377 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 378 | |
Ting12138 | 0:ba32cfe0051e | 379 | pad.tone(440.00,0.60); // adding the theme music |
Ting12138 | 0:ba32cfe0051e | 380 | wait(0.60); |
Ting12138 | 0:ba32cfe0051e | 381 | pad.tone(329.63,0.60); |
Ting12138 | 0:ba32cfe0051e | 382 | wait(0.60); |
Ting12138 | 0:ba32cfe0051e | 383 | pad.tone(392.00,0.60); |
Ting12138 | 0:ba32cfe0051e | 384 | wait(0.60); |
Ting12138 | 0:ba32cfe0051e | 385 | pad.tone(392.00,0.30); |
Ting12138 | 0:ba32cfe0051e | 386 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 387 | pad.tone(293.66,0.30); |
Ting12138 | 0:ba32cfe0051e | 388 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 389 | pad.tone(293.66,0.30); |
Ting12138 | 0:ba32cfe0051e | 390 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 391 | pad.tone(261.63,0.30); |
Ting12138 | 0:ba32cfe0051e | 392 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 393 | pad.tone(293.66,0.30); |
Ting12138 | 0:ba32cfe0051e | 394 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 395 | pad.tone(261.63,0.30); |
Ting12138 | 0:ba32cfe0051e | 396 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 397 | pad.tone(392.00,0.30); |
Ting12138 | 0:ba32cfe0051e | 398 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 399 | pad.tone(293.66,0.15); |
Ting12138 | 0:ba32cfe0051e | 400 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 401 | pad.tone(261.63,0.15); |
Ting12138 | 0:ba32cfe0051e | 402 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 403 | pad.tone(293.66,0.30); |
Ting12138 | 0:ba32cfe0051e | 404 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 405 | pad.tone(392.00,0.30); |
Ting12138 | 0:ba32cfe0051e | 406 | wait(0.30); |
Ting12138 | 0:ba32cfe0051e | 407 | while (pad.check_event(Gamepad::START_PRESSED) == false) { // enter loop waiting to restart the game |
Ting12138 | 0:ba32cfe0051e | 408 | lcd.printString("press start",9,4); |
Ting12138 | 0:ba32cfe0051e | 409 | lcd.printString("to return",15,5); |
Ting12138 | 0:ba32cfe0051e | 410 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 411 | pad.leds_on(); |
Ting12138 | 0:ba32cfe0051e | 412 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 413 | pad.leds_off(); |
Ting12138 | 0:ba32cfe0051e | 414 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 415 | } |
Ting12138 | 0:ba32cfe0051e | 416 | } |
Ting12138 | 0:ba32cfe0051e | 417 | |
Ting12138 | 0:ba32cfe0051e | 418 | void end_game() { |
Ting12138 | 0:ba32cfe0051e | 419 | lcd.clear(); //break the while loop and enter gameover |
Ting12138 | 0:ba32cfe0051e | 420 | lcd.printString("OH!!!",18,1); |
Ting12138 | 0:ba32cfe0051e | 421 | lcd.printString("I don't feel",6,2); |
Ting12138 | 0:ba32cfe0051e | 422 | lcd.printString("so good ...",9,3); |
Ting12138 | 0:ba32cfe0051e | 423 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 424 | |
Ting12138 | 0:ba32cfe0051e | 425 | pad.tone(261.63,1.63); // play sad music when lose |
Ting12138 | 0:ba32cfe0051e | 426 | wait(1.63); |
Ting12138 | 0:ba32cfe0051e | 427 | pad.tone(0.0,0.06); |
Ting12138 | 0:ba32cfe0051e | 428 | wait(0.06); |
Ting12138 | 0:ba32cfe0051e | 429 | pad.tone(261.63,0.63); |
Ting12138 | 0:ba32cfe0051e | 430 | wait(0.63); |
Ting12138 | 0:ba32cfe0051e | 431 | pad.tone(293.66,0.63); |
Ting12138 | 0:ba32cfe0051e | 432 | wait(0.06); |
Ting12138 | 0:ba32cfe0051e | 433 | pad.tone(329.63,0.63); |
Ting12138 | 0:ba32cfe0051e | 434 | wait(0.63); |
Ting12138 | 0:ba32cfe0051e | 435 | pad.tone(261.63,0.63); |
Ting12138 | 0:ba32cfe0051e | 436 | wait(0.06); |
Ting12138 | 0:ba32cfe0051e | 437 | pad.tone(329.63,1.63); |
Ting12138 | 0:ba32cfe0051e | 438 | wait(1.63); |
Ting12138 | 0:ba32cfe0051e | 439 | pad.tone(0.00,0.06); |
Ting12138 | 0:ba32cfe0051e | 440 | wait(0.06); |
Ting12138 | 0:ba32cfe0051e | 441 | pad.tone(261.63,0.63); |
Ting12138 | 0:ba32cfe0051e | 442 | wait(0.63); |
Ting12138 | 0:ba32cfe0051e | 443 | pad.tone(293.66,0.63); |
Ting12138 | 0:ba32cfe0051e | 444 | wait(0.63); |
Ting12138 | 0:ba32cfe0051e | 445 | pad.tone(329.63,0.63); |
Ting12138 | 0:ba32cfe0051e | 446 | wait(0.63); |
Ting12138 | 0:ba32cfe0051e | 447 | pad.tone(261.63,0.63); |
Ting12138 | 0:ba32cfe0051e | 448 | wait(0.63); |
Ting12138 | 0:ba32cfe0051e | 449 | pad.tone(349.23,0.63); |
Ting12138 | 0:ba32cfe0051e | 450 | wait(0.63); |
Ting12138 | 0:ba32cfe0051e | 451 | |
Ting12138 | 0:ba32cfe0051e | 452 | while (pad.check_event(Gamepad::START_PRESSED) == false) { // enter loop waiting to restart the game |
Ting12138 | 0:ba32cfe0051e | 453 | lcd.printString("press start",9,4); |
Ting12138 | 0:ba32cfe0051e | 454 | lcd.printString("to return",15,5); |
Ting12138 | 0:ba32cfe0051e | 455 | lcd.refresh(); |
Ting12138 | 0:ba32cfe0051e | 456 | wait(0.5); |
Ting12138 | 0:ba32cfe0051e | 457 | } |
Ting12138 | 0:ba32cfe0051e | 458 | } |