ELEC2645 (2015/16)
/
el14ws_Project
Snake Game
Fork of ProjectSnake by
main.cpp@1:44cc07feab7e, 2016-05-04 (annotated)
- Committer:
- el14ws
- Date:
- Wed May 04 18:24:37 2016 +0000
- Revision:
- 1:44cc07feab7e
- Parent:
- 0:4b8288518876
- Child:
- 2:3389133a2223
Good position
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el14ws | 0:4b8288518876 | 1 | #include "mbed.h" |
el14ws | 0:4b8288518876 | 2 | #include "N5110.h" |
el14ws | 0:4b8288518876 | 3 | #define DIRECTION_TOLERANCE 0.05// change this to alter tolerance of joystick direction |
el14ws | 0:4b8288518876 | 4 | |
el14ws | 0:4b8288518876 | 5 | DigitalIn button(PTB11);// connections for joystick |
el14ws | 0:4b8288518876 | 6 | AnalogIn xPot(PTB2); |
el14ws | 0:4b8288518876 | 7 | AnalogIn yPot(PTB3); |
el14ws | 0:4b8288518876 | 8 | Ticker pollJoystick;// timer to regularly read the joystick |
el14ws | 0:4b8288518876 | 9 | // Serial for debug |
el14ws | 0:4b8288518876 | 10 | Serial serial(USBTX,USBRX);// Serial for debug |
el14ws | 0:4b8288518876 | 11 | // create enumerated type (0,1,2,3 etc. for direction) |
el14ws | 0:4b8288518876 | 12 | // could be extended for diagonals etc. |
el14ws | 0:4b8288518876 | 13 | enum DirectionName { |
el14ws | 0:4b8288518876 | 14 | UP, |
el14ws | 0:4b8288518876 | 15 | DOWN, |
el14ws | 0:4b8288518876 | 16 | LEFT, |
el14ws | 0:4b8288518876 | 17 | RIGHT, |
el14ws | 0:4b8288518876 | 18 | CENTRE, |
el14ws | 0:4b8288518876 | 19 | UNKNOWN |
el14ws | 0:4b8288518876 | 20 | }; |
el14ws | 0:4b8288518876 | 21 | typedef struct JoyStick Joystick;// struct for Joystick |
el14ws | 0:4b8288518876 | 22 | struct JoyStick { |
el14ws | 0:4b8288518876 | 23 | float x; // current x value |
el14ws | 0:4b8288518876 | 24 | float x0; // 'centred' x value |
el14ws | 0:4b8288518876 | 25 | float y; // current y value |
el14ws | 0:4b8288518876 | 26 | float y0; // 'centred' y value |
el14ws | 0:4b8288518876 | 27 | int button; // button state (assume pull-down used, so 1 = pressed, 0 = unpressed) |
el14ws | 0:4b8288518876 | 28 | DirectionName direction; // current direction |
el14ws | 0:4b8288518876 | 29 | }; |
el14ws | 0:4b8288518876 | 30 | Joystick joystick;// create struct variable |
el14ws | 0:4b8288518876 | 31 | int printFlag = 0; |
el14ws | 0:4b8288518876 | 32 | |
el14ws | 0:4b8288518876 | 33 | // VCC, SCE, RST, D/C, MOSI, SCLK, LED |
el14ws | 0:4b8288518876 | 34 | N5110 lcd( PTE26, PTA0, PTC4, PTD0, PTD2, PTD1, PTC3); |
el14ws | 0:4b8288518876 | 35 | DigitalIn buttonA(PTB18); |
el14ws | 0:4b8288518876 | 36 | int ni = 84; |
el14ws | 0:4b8288518876 | 37 | int x = 0; |
el14ws | 0:4b8288518876 | 38 | int x1 = 0; |
el14ws | 0:4b8288518876 | 39 | int x2 = 0; |
el14ws | 0:4b8288518876 | 40 | int x3 = 0; |
el14ws | 0:4b8288518876 | 41 | int x4 = 0; |
el14ws | 0:4b8288518876 | 42 | int x5 = 0; |
el14ws | 0:4b8288518876 | 43 | int x6 = 0; |
el14ws | 0:4b8288518876 | 44 | int x7 = 0; |
el14ws | 0:4b8288518876 | 45 | int x8 = 0; |
el14ws | 0:4b8288518876 | 46 | int x9 = 0; |
el14ws | 0:4b8288518876 | 47 | int x10 = 0; |
el14ws | 0:4b8288518876 | 48 | int x11 = 0; |
el14ws | 0:4b8288518876 | 49 | int x12 = 0; |
el14ws | 0:4b8288518876 | 50 | int x13 = 0; |
el14ws | 0:4b8288518876 | 51 | int x14 = 0; |
el14ws | 0:4b8288518876 | 52 | int x15 = 0; |
el14ws | 0:4b8288518876 | 53 | int x16 = 0; |
el14ws | 0:4b8288518876 | 54 | int x17 = 0; |
el14ws | 0:4b8288518876 | 55 | int x18 = 0; |
el14ws | 0:4b8288518876 | 56 | int x19 = 0; |
el14ws | 0:4b8288518876 | 57 | int x20 = 0; |
el14ws | 0:4b8288518876 | 58 | int x21 = 0; |
el14ws | 0:4b8288518876 | 59 | int x22 = 0; |
el14ws | 0:4b8288518876 | 60 | int x23 = 0; |
el14ws | 0:4b8288518876 | 61 | int x24 = 0; |
el14ws | 0:4b8288518876 | 62 | int y = 0; |
el14ws | 0:4b8288518876 | 63 | int y1 = 1; |
el14ws | 0:4b8288518876 | 64 | int y2 = 2; |
el14ws | 0:4b8288518876 | 65 | int y3 = 3; |
el14ws | 0:4b8288518876 | 66 | int y4 = 4; |
el14ws | 0:4b8288518876 | 67 | int y5 = 5; |
el14ws | 0:4b8288518876 | 68 | int y6 = 6; |
el14ws | 0:4b8288518876 | 69 | int y7 = 7; |
el14ws | 0:4b8288518876 | 70 | int y8 = 8; |
el14ws | 0:4b8288518876 | 71 | int y9 = 9; |
el14ws | 0:4b8288518876 | 72 | int y10 = 10; |
el14ws | 0:4b8288518876 | 73 | int y11 = 11; |
el14ws | 0:4b8288518876 | 74 | int y12 = 12; |
el14ws | 0:4b8288518876 | 75 | int y13 = 13; |
el14ws | 0:4b8288518876 | 76 | int y14 = 14; |
el14ws | 0:4b8288518876 | 77 | int y15 = 15; |
el14ws | 0:4b8288518876 | 78 | int y16 = 16; |
el14ws | 0:4b8288518876 | 79 | int y17 = 17; |
el14ws | 0:4b8288518876 | 80 | int y18 = 18; |
el14ws | 0:4b8288518876 | 81 | int y19 = 19; |
el14ws | 0:4b8288518876 | 82 | int y20 = 20; |
el14ws | 0:4b8288518876 | 83 | int y21 = 21; |
el14ws | 0:4b8288518876 | 84 | int y22 = 22; |
el14ws | 0:4b8288518876 | 85 | int y23 = 23; |
el14ws | 0:4b8288518876 | 86 | int y24 = 24; |
el14ws | 0:4b8288518876 | 87 | int change = 1; |
el14ws | 0:4b8288518876 | 88 | int n[84][48]; |
el14ws | 0:4b8288518876 | 89 | int array[48][84]; |
el14ws | 0:4b8288518876 | 90 | int nj = 48; |
el14ws | 0:4b8288518876 | 91 | int cells[84][48]; |
el14ws | 0:4b8288518876 | 92 | int Score = 0; |
el14ws | 0:4b8288518876 | 93 | int randX; |
el14ws | 0:4b8288518876 | 94 | int randY; |
el14ws | 0:4b8288518876 | 95 | char str[64]; |
el14ws | 0:4b8288518876 | 96 | int pause=0; |
el14ws | 0:4b8288518876 | 97 | |
el14ws | 0:4b8288518876 | 98 | void Menu(); //Start screen |
el14ws | 0:4b8288518876 | 99 | void Welcomescreen(); //Prints Welcome to snake on screen |
el14ws | 0:4b8288518876 | 100 | void clearCells(); //Clears Screen |
el14ws | 0:4b8288518876 | 101 | void checkerBoard(); //produces checkers before game begins |
el14ws | 0:4b8288518876 | 102 | void DrawArray(); //Sets the pixel depending on whether 0 or higher than 1 |
el14ws | 0:4b8288518876 | 103 | void ClearArray();//Checks over each individual pixel and if its 0 it will clear |
el14ws | 0:4b8288518876 | 104 | void GenerateFood();//Generates food at random places |
el14ws | 0:4b8288518876 | 105 | void MakeSnake(); //sets the pixels for the snake |
el14ws | 0:4b8288518876 | 106 | void SnakeGame(); // Game Rules |
el14ws | 0:4b8288518876 | 107 | void MoveSnake(); //moving the snake using the joy stick |
el14ws | 0:4b8288518876 | 108 | void calibrateJoystick(); |
el14ws | 0:4b8288518876 | 109 | void updateJoystick(); |
el14ws | 0:4b8288518876 | 110 | void SnakeGrowing(); |
el14ws | 0:4b8288518876 | 111 | void GameOver();//Game ends |
el14ws | 0:4b8288518876 | 112 | void drawLine(); |
el14ws | 0:4b8288518876 | 113 | void calibrateJoystick(); |
el14ws | 0:4b8288518876 | 114 | void updateJoystick(); |
el14ws | 0:4b8288518876 | 115 | |
el14ws | 0:4b8288518876 | 116 | int main() |
el14ws | 0:4b8288518876 | 117 | { |
el14ws | 0:4b8288518876 | 118 | buttonA.mode(PullDown); |
el14ws | 0:4b8288518876 | 119 | calibrateJoystick(); // get centred values of joystick |
el14ws | 0:4b8288518876 | 120 | pollJoystick.attach(&updateJoystick,1.0/10.0); // read joystick 10 times per second |
el14ws | 0:4b8288518876 | 121 | calibrateJoystick(); |
el14ws | 0:4b8288518876 | 122 | updateJoystick(); |
el14ws | 0:4b8288518876 | 123 | lcd.init(); |
el14ws | 0:4b8288518876 | 124 | Welcomescreen(); |
el14ws | 0:4b8288518876 | 125 | lcd.clear(); |
el14ws | 0:4b8288518876 | 126 | GenerateFood(); |
el14ws | 0:4b8288518876 | 127 | DrawArray(); |
el14ws | 0:4b8288518876 | 128 | Menu(); |
el14ws | 0:4b8288518876 | 129 | while(1) { |
el14ws | 0:4b8288518876 | 130 | |
el14ws | 0:4b8288518876 | 131 | MakeSnake(); |
el14ws | 0:4b8288518876 | 132 | ClearArray(); |
el14ws | 0:4b8288518876 | 133 | DrawArray(); |
el14ws | 0:4b8288518876 | 134 | } |
el14ws | 0:4b8288518876 | 135 | } |
el14ws | 0:4b8288518876 | 136 | //menu screen |
el14ws | 0:4b8288518876 | 137 | void Menu() |
el14ws | 0:4b8288518876 | 138 | { |
el14ws | 0:4b8288518876 | 139 | // first need to initialise display |
el14ws | 0:4b8288518876 | 140 | |
el14ws | 0:4b8288518876 | 141 | lcd.clear(); |
el14ws | 0:4b8288518876 | 142 | lcd.printString("Press Button",6,1); |
el14ws | 0:4b8288518876 | 143 | lcd.printString("To",35,3); |
el14ws | 0:4b8288518876 | 144 | lcd.printString("START",27,5); |
el14ws | 0:4b8288518876 | 145 | wait(0.3); |
el14ws | 0:4b8288518876 | 146 | |
el14ws | 0:4b8288518876 | 147 | while(1) { |
el14ws | 0:4b8288518876 | 148 | if (buttonA==1) { |
el14ws | 0:4b8288518876 | 149 | lcd.clear(); |
el14ws | 0:4b8288518876 | 150 | checkerBoard(); |
el14ws | 0:4b8288518876 | 151 | wait(0.5); |
el14ws | 0:4b8288518876 | 152 | lcd.clear(); |
el14ws | 0:4b8288518876 | 153 | |
el14ws | 0:4b8288518876 | 154 | |
el14ws | 0:4b8288518876 | 155 | while(1) { |
el14ws | 0:4b8288518876 | 156 | |
el14ws | 0:4b8288518876 | 157 | wait(0.005); |
el14ws | 0:4b8288518876 | 158 | SnakeGame(); |
el14ws | 0:4b8288518876 | 159 | if (buttonA==1) { |
el14ws | 0:4b8288518876 | 160 | pause=0; |
el14ws | 0:4b8288518876 | 161 | Menu(); |
el14ws | 0:4b8288518876 | 162 | } |
el14ws | 0:4b8288518876 | 163 | |
el14ws | 0:4b8288518876 | 164 | if (button==1) { |
el14ws | 0:4b8288518876 | 165 | pause=0; |
el14ws | 0:4b8288518876 | 166 | lcd.clear(); |
el14ws | 0:4b8288518876 | 167 | sprintf(str,"%d",Score); |
el14ws | 0:4b8288518876 | 168 | lcd.printString(str,37,2); |
el14ws | 0:4b8288518876 | 169 | wait(1); |
el14ws | 0:4b8288518876 | 170 | } |
el14ws | 0:4b8288518876 | 171 | } |
el14ws | 0:4b8288518876 | 172 | } |
el14ws | 0:4b8288518876 | 173 | } |
el14ws | 0:4b8288518876 | 174 | } |
el14ws | 0:4b8288518876 | 175 | |
el14ws | 0:4b8288518876 | 176 | void Welcomescreen() // Display welcome screen |
el14ws | 0:4b8288518876 | 177 | { |
el14ws | 0:4b8288518876 | 178 | lcd.printString("Welcome",20,1); // display Welcome |
el14ws | 0:4b8288518876 | 179 | wait(0.1); |
el14ws | 0:4b8288518876 | 180 | lcd.printString("To",35,3); // display To |
el14ws | 0:4b8288518876 | 181 | wait(0.1); |
el14ws | 0:4b8288518876 | 182 | lcd.printString("SNAKE",27,5); // display Snake |
el14ws | 0:4b8288518876 | 183 | wait(1); |
el14ws | 0:4b8288518876 | 184 | } |
el14ws | 0:4b8288518876 | 185 | |
el14ws | 0:4b8288518876 | 186 | void checkerBoard() |
el14ws | 0:4b8288518876 | 187 | { |
el14ws | 0:4b8288518876 | 188 | // |
el14ws | 0:4b8288518876 | 189 | for (int i = 0; i < ni ; i+=2) { |
el14ws | 0:4b8288518876 | 190 | for (int j = 0; j < nj ; j+=2) { |
el14ws | 0:4b8288518876 | 191 | lcd.setPixel(i,j); |
el14ws | 0:4b8288518876 | 192 | } |
el14ws | 0:4b8288518876 | 193 | } |
el14ws | 0:4b8288518876 | 194 | lcd.refresh(); |
el14ws | 0:4b8288518876 | 195 | } |
el14ws | 0:4b8288518876 | 196 | |
el14ws | 0:4b8288518876 | 197 | void DrawArray() |
el14ws | 0:4b8288518876 | 198 | { |
el14ws | 0:4b8288518876 | 199 | for(int x=0; x<84; x++) { |
el14ws | 0:4b8288518876 | 200 | for (int y=0; y<48; y++) { |
el14ws | 0:4b8288518876 | 201 | if(array[y][x]>=1) { |
el14ws | 0:4b8288518876 | 202 | lcd.setPixel(x,y); |
el14ws | 0:4b8288518876 | 203 | } else { |
el14ws | 0:4b8288518876 | 204 | lcd.clearPixel(x,y); |
el14ws | 0:4b8288518876 | 205 | } |
el14ws | 0:4b8288518876 | 206 | } |
el14ws | 0:4b8288518876 | 207 | } |
el14ws | 0:4b8288518876 | 208 | lcd.refresh(); |
el14ws | 0:4b8288518876 | 209 | } |
el14ws | 0:4b8288518876 | 210 | |
el14ws | 0:4b8288518876 | 211 | void ClearArray() |
el14ws | 0:4b8288518876 | 212 | { |
el14ws | 0:4b8288518876 | 213 | for(int x=0; x<84; x++) { |
el14ws | 0:4b8288518876 | 214 | for(int y=0; y<48; y++) { |
el14ws | 0:4b8288518876 | 215 | if (array[y][x]==0) { |
el14ws | 0:4b8288518876 | 216 | lcd.clearPixel(x,y); |
el14ws | 0:4b8288518876 | 217 | } else { |
el14ws | 0:4b8288518876 | 218 | lcd.setPixel(x,y); |
el14ws | 0:4b8288518876 | 219 | } |
el14ws | 0:4b8288518876 | 220 | } |
el14ws | 0:4b8288518876 | 221 | } |
el14ws | 0:4b8288518876 | 222 | lcd.refresh(); |
el14ws | 0:4b8288518876 | 223 | } |
el14ws | 0:4b8288518876 | 224 | |
el14ws | 0:4b8288518876 | 225 | void calibrateJoystick()// read default positions of the joystick to calibrate later readings |
el14ws | 0:4b8288518876 | 226 | { |
el14ws | 0:4b8288518876 | 227 | button.mode(PullDown); // must not move during calibration |
el14ws | 0:4b8288518876 | 228 | joystick.x0 = xPot; // initial positions in the range 0.0 to 1.0 (0.5 if centred exactly) |
el14ws | 0:4b8288518876 | 229 | joystick.y0 = yPot; |
el14ws | 0:4b8288518876 | 230 | } |
el14ws | 0:4b8288518876 | 231 | void updateJoystick() |
el14ws | 0:4b8288518876 | 232 | { |
el14ws | 0:4b8288518876 | 233 | joystick.x = xPot - joystick.x0;// read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred) |
el14ws | 0:4b8288518876 | 234 | joystick.y = yPot - joystick.y0;// read button state |
el14ws | 0:4b8288518876 | 235 | joystick.button = button; // calculate direction depending on x,y values |
el14ws | 0:4b8288518876 | 236 | if ( fabs(joystick.y) < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { // tolerance allows a little lee-way in case joystick not exactly in the stated direction |
el14ws | 0:4b8288518876 | 237 | joystick.direction = CENTRE; |
el14ws | 0:4b8288518876 | 238 | } else if ( joystick.y > DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { |
el14ws | 0:4b8288518876 | 239 | joystick.direction = LEFT; |
el14ws | 0:4b8288518876 | 240 | } else if ( joystick.y < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { |
el14ws | 0:4b8288518876 | 241 | joystick.direction = RIGHT; |
el14ws | 0:4b8288518876 | 242 | } else if ( joystick.x > DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) { |
el14ws | 0:4b8288518876 | 243 | joystick.direction = DOWN; |
el14ws | 0:4b8288518876 | 244 | } else if ( joystick.x < DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) { |
el14ws | 0:4b8288518876 | 245 | joystick.direction = UP; |
el14ws | 0:4b8288518876 | 246 | } else { |
el14ws | 0:4b8288518876 | 247 | joystick.direction = UNKNOWN; |
el14ws | 0:4b8288518876 | 248 | } |
el14ws | 0:4b8288518876 | 249 | printFlag = 1;// set flag for printing |
el14ws | 0:4b8288518876 | 250 | } |
el14ws | 0:4b8288518876 | 251 | |
el14ws | 0:4b8288518876 | 252 | void GenerateFood() |
el14ws | 0:4b8288518876 | 253 | { |
el14ws | 0:4b8288518876 | 254 | randX = rand() %83; //make random number between 0 - 84 |
el14ws | 0:4b8288518876 | 255 | randY = rand() %47; //make random number between 0 - 48 |
el14ws | 0:4b8288518876 | 256 | while(array[randY][randX]) { |
el14ws | 0:4b8288518876 | 257 | randX= rand() %83; |
el14ws | 0:4b8288518876 | 258 | randY= rand() %47; |
el14ws | 0:4b8288518876 | 259 | } |
el14ws | 0:4b8288518876 | 260 | array[randY][randX]= 5; |
el14ws | 0:4b8288518876 | 261 | } |
el14ws | 0:4b8288518876 | 262 | void MakeSnake() |
el14ws | 0:4b8288518876 | 263 | { |
el14ws | 0:4b8288518876 | 264 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 265 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 266 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 267 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 268 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 269 | array[y5+36][x5+5]= 0; |
el14ws | 0:4b8288518876 | 270 | array[y6+36][x6+5]= 0; |
el14ws | 0:4b8288518876 | 271 | array[y7+36][x7+5]= 0; |
el14ws | 0:4b8288518876 | 272 | array[y8+36][x7+5]= 0; |
el14ws | 0:4b8288518876 | 273 | array[y9+36][x9+5]= 0; |
el14ws | 0:4b8288518876 | 274 | array[y10+36][x10+5]= 0; |
el14ws | 0:4b8288518876 | 275 | array[y11+36][x11+5]= 0; |
el14ws | 0:4b8288518876 | 276 | array[y12+36][x12+5]= 0; |
el14ws | 0:4b8288518876 | 277 | array[y13+36][x13+5]= 0; |
el14ws | 0:4b8288518876 | 278 | array[y14+36][x14+5]= 0; |
el14ws | 0:4b8288518876 | 279 | array[y15+36][x15+5]= 0; |
el14ws | 0:4b8288518876 | 280 | array[y16+36][x16+5]= 0; |
el14ws | 0:4b8288518876 | 281 | array[y17+36][x17+5]= 0; |
el14ws | 0:4b8288518876 | 282 | array[y18+36][x18+5]= 0; |
el14ws | 0:4b8288518876 | 283 | array[y19+36][x19+5]= 0; |
el14ws | 0:4b8288518876 | 284 | array[y20+36][x20+5]= 0; |
el14ws | 0:4b8288518876 | 285 | array[y21+36][x21+5]= 0; |
el14ws | 0:4b8288518876 | 286 | array[y22+36][x22+5]= 0; |
el14ws | 0:4b8288518876 | 287 | array[y23+36][x23+5]= 0; |
el14ws | 0:4b8288518876 | 288 | array[y24+36][x24+5]= 0; |
el14ws | 0:4b8288518876 | 289 | } |
el14ws | 0:4b8288518876 | 290 | |
el14ws | 0:4b8288518876 | 291 | void SnakeGame() |
el14ws | 0:4b8288518876 | 292 | { |
el14ws | 0:4b8288518876 | 293 | MakeSnake(); |
el14ws | 0:4b8288518876 | 294 | ClearArray(); |
el14ws | 0:4b8288518876 | 295 | DrawArray(); |
el14ws | 0:4b8288518876 | 296 | SnakeGrowing(); |
el14ws | 0:4b8288518876 | 297 | if(pause==0) { |
el14ws | 0:4b8288518876 | 298 | MoveSnake(); |
el14ws | 0:4b8288518876 | 299 | } |
el14ws | 0:4b8288518876 | 300 | if(y+36==randY && x+5==randX) { |
el14ws | 0:4b8288518876 | 301 | GenerateFood(); |
el14ws | 0:4b8288518876 | 302 | |
el14ws | 0:4b8288518876 | 303 | Score= Score+10; |
el14ws | 0:4b8288518876 | 304 | } |
el14ws | 0:4b8288518876 | 305 | |
el14ws | 0:4b8288518876 | 306 | } |
el14ws | 0:4b8288518876 | 307 | void MoveSnake() |
el14ws | 0:4b8288518876 | 308 | { |
el14ws | 0:4b8288518876 | 309 | array[y+36][x+5]= 0; |
el14ws | 0:4b8288518876 | 310 | |
el14ws | 0:4b8288518876 | 311 | array[y1+36][x1+5]= 0; |
el14ws | 0:4b8288518876 | 312 | |
el14ws | 0:4b8288518876 | 313 | array[y2+36][x2+5]= 0; |
el14ws | 0:4b8288518876 | 314 | |
el14ws | 0:4b8288518876 | 315 | array[y3+36][x3+5]= 0; |
el14ws | 0:4b8288518876 | 316 | |
el14ws | 0:4b8288518876 | 317 | array[y4+36][x4+5]= 0; |
el14ws | 0:4b8288518876 | 318 | |
el14ws | 0:4b8288518876 | 319 | array[y5+36][x5+5]= 0; |
el14ws | 0:4b8288518876 | 320 | |
el14ws | 0:4b8288518876 | 321 | array[y6+36][x6+5]= 0; |
el14ws | 0:4b8288518876 | 322 | |
el14ws | 0:4b8288518876 | 323 | array[y7+36][x7+5]= 0; |
el14ws | 0:4b8288518876 | 324 | |
el14ws | 0:4b8288518876 | 325 | array[y8+36][x8+5]= 0; |
el14ws | 0:4b8288518876 | 326 | |
el14ws | 0:4b8288518876 | 327 | array[y9+36][x9+5]= 0; |
el14ws | 0:4b8288518876 | 328 | |
el14ws | 0:4b8288518876 | 329 | array[y10+36][x10+5]= 0; |
el14ws | 0:4b8288518876 | 330 | |
el14ws | 0:4b8288518876 | 331 | array[y11+36][x11+5]= 0; |
el14ws | 0:4b8288518876 | 332 | |
el14ws | 0:4b8288518876 | 333 | array[y12+36][x12+5]= 0; |
el14ws | 0:4b8288518876 | 334 | |
el14ws | 0:4b8288518876 | 335 | array[y13+36][x13+5]= 0; |
el14ws | 0:4b8288518876 | 336 | |
el14ws | 0:4b8288518876 | 337 | array[y14+36][x14+5]= 0; |
el14ws | 0:4b8288518876 | 338 | |
el14ws | 0:4b8288518876 | 339 | array[y15+36][x15+5]= 0; |
el14ws | 0:4b8288518876 | 340 | |
el14ws | 0:4b8288518876 | 341 | array[y16+36][x16+5]= 0; |
el14ws | 0:4b8288518876 | 342 | |
el14ws | 0:4b8288518876 | 343 | array[y17+36][x17+5]= 0; |
el14ws | 0:4b8288518876 | 344 | |
el14ws | 0:4b8288518876 | 345 | array[y18+36][x18+5]= 0; |
el14ws | 0:4b8288518876 | 346 | |
el14ws | 0:4b8288518876 | 347 | array[y19+36][x19+5]= 0; |
el14ws | 0:4b8288518876 | 348 | |
el14ws | 0:4b8288518876 | 349 | array[y20+36][x20+5]= 0; |
el14ws | 0:4b8288518876 | 350 | |
el14ws | 0:4b8288518876 | 351 | array[y21+36][x21+5]= 0; |
el14ws | 0:4b8288518876 | 352 | |
el14ws | 0:4b8288518876 | 353 | array[y22+36][x22+5]= 0; |
el14ws | 0:4b8288518876 | 354 | |
el14ws | 0:4b8288518876 | 355 | array[y23+36][x23+5]= 0; |
el14ws | 0:4b8288518876 | 356 | |
el14ws | 0:4b8288518876 | 357 | array[y24+36][x24+5]= 0; |
el14ws | 0:4b8288518876 | 358 | |
el14ws | 0:4b8288518876 | 359 | x24=x23; |
el14ws | 0:4b8288518876 | 360 | y24=y23; |
el14ws | 0:4b8288518876 | 361 | x23=x22; |
el14ws | 0:4b8288518876 | 362 | y23=y22; |
el14ws | 0:4b8288518876 | 363 | x22=x21; |
el14ws | 0:4b8288518876 | 364 | y22=y21; |
el14ws | 0:4b8288518876 | 365 | x21=x20; |
el14ws | 0:4b8288518876 | 366 | y21=y20; |
el14ws | 0:4b8288518876 | 367 | x20=x19; |
el14ws | 0:4b8288518876 | 368 | y20=y19; |
el14ws | 0:4b8288518876 | 369 | x19=x18; |
el14ws | 0:4b8288518876 | 370 | y19=y18; |
el14ws | 0:4b8288518876 | 371 | x18=x17; |
el14ws | 0:4b8288518876 | 372 | y18=y17; |
el14ws | 0:4b8288518876 | 373 | x17=x16; |
el14ws | 0:4b8288518876 | 374 | y17=y16; |
el14ws | 0:4b8288518876 | 375 | x16=x15; |
el14ws | 0:4b8288518876 | 376 | y16=y15; |
el14ws | 0:4b8288518876 | 377 | x15=x14; |
el14ws | 0:4b8288518876 | 378 | y15=y14; |
el14ws | 0:4b8288518876 | 379 | x14=x13; |
el14ws | 0:4b8288518876 | 380 | y14=y13; |
el14ws | 0:4b8288518876 | 381 | x13=x12; |
el14ws | 0:4b8288518876 | 382 | y13=y12; |
el14ws | 0:4b8288518876 | 383 | x12=x11; |
el14ws | 0:4b8288518876 | 384 | y12=y11; |
el14ws | 0:4b8288518876 | 385 | x11=x10; |
el14ws | 0:4b8288518876 | 386 | y11=y10; |
el14ws | 0:4b8288518876 | 387 | x10=x9; |
el14ws | 0:4b8288518876 | 388 | y10=y9; |
el14ws | 0:4b8288518876 | 389 | x9=x8; |
el14ws | 0:4b8288518876 | 390 | y9=y8; |
el14ws | 0:4b8288518876 | 391 | x8=x7; |
el14ws | 0:4b8288518876 | 392 | y8=y7; |
el14ws | 0:4b8288518876 | 393 | x7=x6; |
el14ws | 0:4b8288518876 | 394 | y7=y6; |
el14ws | 0:4b8288518876 | 395 | x6=x5; |
el14ws | 0:4b8288518876 | 396 | y6=y5; |
el14ws | 0:4b8288518876 | 397 | x5=x4; |
el14ws | 0:4b8288518876 | 398 | y5=y4; |
el14ws | 0:4b8288518876 | 399 | x4=x3; |
el14ws | 0:4b8288518876 | 400 | y4=y3; |
el14ws | 0:4b8288518876 | 401 | x3=x2; |
el14ws | 0:4b8288518876 | 402 | y3=y2; |
el14ws | 0:4b8288518876 | 403 | x2=x1; |
el14ws | 0:4b8288518876 | 404 | y2=y1; |
el14ws | 0:4b8288518876 | 405 | x1 = x; |
el14ws | 0:4b8288518876 | 406 | y1 = y; |
el14ws | 0:4b8288518876 | 407 | if (joystick.direction == CENTRE) { |
el14ws | 0:4b8288518876 | 408 | //lcd.printString("CENTRE",20,1); // display welcome |
el14ws | 0:4b8288518876 | 409 | wait(0.05); |
el14ws | 0:4b8288518876 | 410 | } else if (joystick.direction == UP) { |
el14ws | 0:4b8288518876 | 411 | //lcd.printString("UP",20,1); // display welcome |
el14ws | 0:4b8288518876 | 412 | wait(0.05); |
el14ws | 1:44cc07feab7e | 413 | //y--; |
el14ws | 0:4b8288518876 | 414 | change = 1; |
el14ws | 1:44cc07feab7e | 415 | if |
el14ws | 0:4b8288518876 | 416 | } else if (joystick.direction == DOWN) { |
el14ws | 0:4b8288518876 | 417 | //lcd.printString("DOWN",20,1); // display welcome |
el14ws | 0:4b8288518876 | 418 | wait(0.05); |
el14ws | 0:4b8288518876 | 419 | change = 2; |
el14ws | 1:44cc07feab7e | 420 | //y++; |
el14ws | 0:4b8288518876 | 421 | } else if (joystick.direction == LEFT) { |
el14ws | 0:4b8288518876 | 422 | //lcd.printString("LEFT",20,1); // display welcome |
el14ws | 0:4b8288518876 | 423 | wait(0.05); |
el14ws | 1:44cc07feab7e | 424 | //x--; |
el14ws | 0:4b8288518876 | 425 | change = 3; |
el14ws | 0:4b8288518876 | 426 | } else if (joystick.direction == RIGHT) { |
el14ws | 0:4b8288518876 | 427 | //lcd.printString("RIGHT",20,1); // display welcome |
el14ws | 0:4b8288518876 | 428 | wait(0.05); |
el14ws | 1:44cc07feab7e | 429 | //x++; |
el14ws | 0:4b8288518876 | 430 | change = 4; |
el14ws | 0:4b8288518876 | 431 | } |
el14ws | 1:44cc07feab7e | 432 | if (change == 1) { |
el14ws | 1:44cc07feab7e | 433 | y--; |
el14ws | 1:44cc07feab7e | 434 | } else if (change == 2) { |
el14ws | 1:44cc07feab7e | 435 | y++; |
el14ws | 1:44cc07feab7e | 436 | } else if (change == 3) { |
el14ws | 1:44cc07feab7e | 437 | x--; |
el14ws | 1:44cc07feab7e | 438 | } else if (change == 4) { |
el14ws | 1:44cc07feab7e | 439 | x++; |
el14ws | 1:44cc07feab7e | 440 | } |
el14ws | 1:44cc07feab7e | 441 | |
el14ws | 0:4b8288518876 | 442 | } |
el14ws | 1:44cc07feab7e | 443 | void SnakeGrowing() { |
el14ws | 0:4b8288518876 | 444 | |
el14ws | 0:4b8288518876 | 445 | |
el14ws | 1:44cc07feab7e | 446 | if(Score>=10) { |
el14ws | 1:44cc07feab7e | 447 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 448 | |
el14ws | 1:44cc07feab7e | 449 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 450 | |
el14ws | 1:44cc07feab7e | 451 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 452 | |
el14ws | 1:44cc07feab7e | 453 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 454 | |
el14ws | 1:44cc07feab7e | 455 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 456 | |
el14ws | 1:44cc07feab7e | 457 | array[y5+36][x5+5]= 1; |
el14ws | 0:4b8288518876 | 458 | |
el14ws | 1:44cc07feab7e | 459 | array[y6+36][x6+5]= 1; |
el14ws | 0:4b8288518876 | 460 | |
el14ws | 1:44cc07feab7e | 461 | } |
el14ws | 0:4b8288518876 | 462 | |
el14ws | 0:4b8288518876 | 463 | |
el14ws | 1:44cc07feab7e | 464 | if(Score>=20) { |
el14ws | 1:44cc07feab7e | 465 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 466 | |
el14ws | 1:44cc07feab7e | 467 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 468 | |
el14ws | 1:44cc07feab7e | 469 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 470 | |
el14ws | 1:44cc07feab7e | 471 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 472 | |
el14ws | 1:44cc07feab7e | 473 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 474 | |
el14ws | 1:44cc07feab7e | 475 | array[y5+36][x5+5]= 1; |
el14ws | 0:4b8288518876 | 476 | |
el14ws | 1:44cc07feab7e | 477 | array[y6+36][x6+5]= 1; |
el14ws | 0:4b8288518876 | 478 | |
el14ws | 1:44cc07feab7e | 479 | array[y7+36][x7+5]= 1; |
el14ws | 0:4b8288518876 | 480 | |
el14ws | 1:44cc07feab7e | 481 | array[y8+36][x8+5]= 1; |
el14ws | 1:44cc07feab7e | 482 | } |
el14ws | 1:44cc07feab7e | 483 | if(Score>=30) { |
el14ws | 1:44cc07feab7e | 484 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 485 | |
el14ws | 1:44cc07feab7e | 486 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 487 | |
el14ws | 1:44cc07feab7e | 488 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 489 | |
el14ws | 1:44cc07feab7e | 490 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 491 | |
el14ws | 1:44cc07feab7e | 492 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 493 | |
el14ws | 1:44cc07feab7e | 494 | array[y5+36][x5+5]= 1; |
el14ws | 0:4b8288518876 | 495 | |
el14ws | 1:44cc07feab7e | 496 | array[y6+36][x6+5]= 1; |
el14ws | 0:4b8288518876 | 497 | |
el14ws | 1:44cc07feab7e | 498 | array[y7+36][x7+5]= 1; |
el14ws | 0:4b8288518876 | 499 | |
el14ws | 1:44cc07feab7e | 500 | array[y8+36][x8+5]= 1; |
el14ws | 0:4b8288518876 | 501 | |
el14ws | 1:44cc07feab7e | 502 | array[y9+36][x9+5]= 1; |
el14ws | 0:4b8288518876 | 503 | |
el14ws | 1:44cc07feab7e | 504 | array[y10+36][x10+5]= 1; |
el14ws | 0:4b8288518876 | 505 | |
el14ws | 1:44cc07feab7e | 506 | } |
el14ws | 1:44cc07feab7e | 507 | if(Score>=40) { |
el14ws | 1:44cc07feab7e | 508 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 509 | |
el14ws | 1:44cc07feab7e | 510 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 511 | |
el14ws | 1:44cc07feab7e | 512 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 513 | |
el14ws | 1:44cc07feab7e | 514 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 515 | |
el14ws | 1:44cc07feab7e | 516 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 517 | |
el14ws | 1:44cc07feab7e | 518 | array[y5+36][x5+5]= 1; |
el14ws | 0:4b8288518876 | 519 | |
el14ws | 1:44cc07feab7e | 520 | array[y6+36][x6+5]= 1; |
el14ws | 0:4b8288518876 | 521 | |
el14ws | 1:44cc07feab7e | 522 | array[y7+36][x7+5]= 1; |
el14ws | 0:4b8288518876 | 523 | |
el14ws | 1:44cc07feab7e | 524 | array[y8+36][x8+5]= 1; |
el14ws | 0:4b8288518876 | 525 | |
el14ws | 1:44cc07feab7e | 526 | array[y9+36][x9+5]= 1; |
el14ws | 0:4b8288518876 | 527 | |
el14ws | 1:44cc07feab7e | 528 | array[y10+36][x10+5]= 1; |
el14ws | 0:4b8288518876 | 529 | |
el14ws | 1:44cc07feab7e | 530 | array[y11+36][x11+5]= 1; |
el14ws | 0:4b8288518876 | 531 | |
el14ws | 1:44cc07feab7e | 532 | array[y12+36][x12+5]= 1; |
el14ws | 0:4b8288518876 | 533 | |
el14ws | 1:44cc07feab7e | 534 | } |
el14ws | 1:44cc07feab7e | 535 | |
el14ws | 0:4b8288518876 | 536 | if(Score>=50) { |
el14ws | 0:4b8288518876 | 537 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 538 | |
el14ws | 0:4b8288518876 | 539 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 540 | |
el14ws | 0:4b8288518876 | 541 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 542 | |
el14ws | 0:4b8288518876 | 543 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 544 | |
el14ws | 0:4b8288518876 | 545 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 546 | |
el14ws | 0:4b8288518876 | 547 | array[y5+36][x5+5]= 1; |
el14ws | 0:4b8288518876 | 548 | |
el14ws | 0:4b8288518876 | 549 | array[y6+36][x6+5]= 1; |
el14ws | 0:4b8288518876 | 550 | |
el14ws | 0:4b8288518876 | 551 | array[y7+36][x7+5]= 1; |
el14ws | 0:4b8288518876 | 552 | |
el14ws | 0:4b8288518876 | 553 | array[y8+36][x8+5]= 1; |
el14ws | 0:4b8288518876 | 554 | |
el14ws | 0:4b8288518876 | 555 | array[y9+36][x9+5]= 1; |
el14ws | 0:4b8288518876 | 556 | |
el14ws | 0:4b8288518876 | 557 | array[y10+36][x10+5]= 1; |
el14ws | 0:4b8288518876 | 558 | |
el14ws | 0:4b8288518876 | 559 | array[y11+36][x11+5]= 1; |
el14ws | 0:4b8288518876 | 560 | |
el14ws | 0:4b8288518876 | 561 | array[y12+36][x12+5]= 1; |
el14ws | 0:4b8288518876 | 562 | |
el14ws | 0:4b8288518876 | 563 | array[y13+36][x13+5]= 1; |
el14ws | 0:4b8288518876 | 564 | |
el14ws | 0:4b8288518876 | 565 | array[y14+36][x14+5]= 1; |
el14ws | 0:4b8288518876 | 566 | |
el14ws | 0:4b8288518876 | 567 | } |
el14ws | 0:4b8288518876 | 568 | if(Score>=60) { |
el14ws | 0:4b8288518876 | 569 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 570 | |
el14ws | 0:4b8288518876 | 571 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 572 | |
el14ws | 0:4b8288518876 | 573 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 574 | |
el14ws | 0:4b8288518876 | 575 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 576 | |
el14ws | 0:4b8288518876 | 577 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 578 | |
el14ws | 0:4b8288518876 | 579 | array[y5+36][x5+5]= 1; |
el14ws | 0:4b8288518876 | 580 | |
el14ws | 0:4b8288518876 | 581 | array[y6+36][x6+5]= 1; |
el14ws | 0:4b8288518876 | 582 | |
el14ws | 0:4b8288518876 | 583 | array[y7+36][x7+5]= 1; |
el14ws | 0:4b8288518876 | 584 | |
el14ws | 0:4b8288518876 | 585 | array[y8+36][x8+5]= 1; |
el14ws | 0:4b8288518876 | 586 | |
el14ws | 0:4b8288518876 | 587 | array[y9+36][x9+5]= 1; |
el14ws | 0:4b8288518876 | 588 | |
el14ws | 0:4b8288518876 | 589 | array[y10+36][x10+5]= 1; |
el14ws | 0:4b8288518876 | 590 | |
el14ws | 0:4b8288518876 | 591 | array[y11+36][x11+5]= 1; |
el14ws | 0:4b8288518876 | 592 | |
el14ws | 0:4b8288518876 | 593 | array[y12+36][x12+5]= 1; |
el14ws | 0:4b8288518876 | 594 | |
el14ws | 0:4b8288518876 | 595 | array[y13+36][x13+5]= 1; |
el14ws | 0:4b8288518876 | 596 | |
el14ws | 0:4b8288518876 | 597 | array[y14+36][x14+5]= 1; |
el14ws | 0:4b8288518876 | 598 | |
el14ws | 0:4b8288518876 | 599 | array[y15+36][x15+5]= 1; |
el14ws | 0:4b8288518876 | 600 | |
el14ws | 0:4b8288518876 | 601 | array[y16+36][x16+5]= 1; |
el14ws | 0:4b8288518876 | 602 | |
el14ws | 0:4b8288518876 | 603 | } |
el14ws | 0:4b8288518876 | 604 | if(Score>=70) { |
el14ws | 0:4b8288518876 | 605 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 606 | |
el14ws | 0:4b8288518876 | 607 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 608 | |
el14ws | 0:4b8288518876 | 609 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 610 | |
el14ws | 0:4b8288518876 | 611 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 612 | |
el14ws | 0:4b8288518876 | 613 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 614 | |
el14ws | 0:4b8288518876 | 615 | array[y5+36][x5+5]= 1; |
el14ws | 0:4b8288518876 | 616 | |
el14ws | 0:4b8288518876 | 617 | array[y6+36][x6+5]= 1; |
el14ws | 0:4b8288518876 | 618 | |
el14ws | 0:4b8288518876 | 619 | array[y7+36][x7+5]= 1; |
el14ws | 0:4b8288518876 | 620 | |
el14ws | 0:4b8288518876 | 621 | array[y8+36][x8+5]= 1; |
el14ws | 0:4b8288518876 | 622 | |
el14ws | 0:4b8288518876 | 623 | array[y9+36][x9+5]= 1; |
el14ws | 0:4b8288518876 | 624 | |
el14ws | 0:4b8288518876 | 625 | array[y10+36][x10+5]= 1; |
el14ws | 0:4b8288518876 | 626 | |
el14ws | 0:4b8288518876 | 627 | array[y11+36][x11+5]= 1; |
el14ws | 0:4b8288518876 | 628 | |
el14ws | 0:4b8288518876 | 629 | array[y12+36][x12+5]= 1; |
el14ws | 0:4b8288518876 | 630 | |
el14ws | 0:4b8288518876 | 631 | array[y13+36][x13+5]= 1; |
el14ws | 0:4b8288518876 | 632 | |
el14ws | 0:4b8288518876 | 633 | array[y14+36][x14+5]= 1; |
el14ws | 0:4b8288518876 | 634 | |
el14ws | 0:4b8288518876 | 635 | array[y15+36][x15+5]= 1; |
el14ws | 0:4b8288518876 | 636 | |
el14ws | 0:4b8288518876 | 637 | array[y16+36][x16+5]= 1; |
el14ws | 0:4b8288518876 | 638 | |
el14ws | 0:4b8288518876 | 639 | array[y17+36][x17+5]= 1; |
el14ws | 0:4b8288518876 | 640 | |
el14ws | 0:4b8288518876 | 641 | array[y18+36][x18+5]= 1; |
el14ws | 0:4b8288518876 | 642 | |
el14ws | 0:4b8288518876 | 643 | } |
el14ws | 0:4b8288518876 | 644 | if(Score>=80) { |
el14ws | 0:4b8288518876 | 645 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 646 | |
el14ws | 0:4b8288518876 | 647 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 648 | |
el14ws | 0:4b8288518876 | 649 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 650 | |
el14ws | 0:4b8288518876 | 651 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 652 | |
el14ws | 0:4b8288518876 | 653 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 654 | |
el14ws | 0:4b8288518876 | 655 | array[y5+36][x5+5]= 1; |
el14ws | 0:4b8288518876 | 656 | |
el14ws | 0:4b8288518876 | 657 | array[y6+36][x6+5]= 1; |
el14ws | 0:4b8288518876 | 658 | |
el14ws | 0:4b8288518876 | 659 | array[y7+36][x7+5]= 1; |
el14ws | 0:4b8288518876 | 660 | |
el14ws | 0:4b8288518876 | 661 | array[y8+36][x8+5]= 1; |
el14ws | 0:4b8288518876 | 662 | |
el14ws | 0:4b8288518876 | 663 | array[y9+36][x9+5]= 1; |
el14ws | 0:4b8288518876 | 664 | |
el14ws | 0:4b8288518876 | 665 | array[y10+36][x10+5]= 1; |
el14ws | 0:4b8288518876 | 666 | |
el14ws | 0:4b8288518876 | 667 | array[y11+36][x11+5]= 1; |
el14ws | 0:4b8288518876 | 668 | |
el14ws | 0:4b8288518876 | 669 | array[y12+36][x12+5]= 1; |
el14ws | 0:4b8288518876 | 670 | |
el14ws | 0:4b8288518876 | 671 | array[y13+36][x13+5]= 1; |
el14ws | 0:4b8288518876 | 672 | |
el14ws | 0:4b8288518876 | 673 | array[y14+36][x14+5]= 1; |
el14ws | 0:4b8288518876 | 674 | |
el14ws | 0:4b8288518876 | 675 | array[y15+36][x15+5]= 1; |
el14ws | 0:4b8288518876 | 676 | |
el14ws | 0:4b8288518876 | 677 | array[y16+36][x16+5]= 1; |
el14ws | 0:4b8288518876 | 678 | |
el14ws | 0:4b8288518876 | 679 | array[y17+36][x17+5]= 1; |
el14ws | 0:4b8288518876 | 680 | |
el14ws | 0:4b8288518876 | 681 | array[y18+36][x18+5]= 1; |
el14ws | 0:4b8288518876 | 682 | |
el14ws | 0:4b8288518876 | 683 | array[y19+36][x19+5]= 1; |
el14ws | 0:4b8288518876 | 684 | |
el14ws | 0:4b8288518876 | 685 | array[y20+36][x20+5]= 1; |
el14ws | 0:4b8288518876 | 686 | |
el14ws | 0:4b8288518876 | 687 | } |
el14ws | 0:4b8288518876 | 688 | if(Score>=90) { |
el14ws | 0:4b8288518876 | 689 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 690 | |
el14ws | 0:4b8288518876 | 691 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 692 | |
el14ws | 0:4b8288518876 | 693 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 694 | |
el14ws | 0:4b8288518876 | 695 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 696 | |
el14ws | 0:4b8288518876 | 697 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 698 | |
el14ws | 0:4b8288518876 | 699 | array[y5+36][x5+5]= 1; |
el14ws | 0:4b8288518876 | 700 | |
el14ws | 0:4b8288518876 | 701 | array[y6+36][x6+5]= 1; |
el14ws | 0:4b8288518876 | 702 | |
el14ws | 0:4b8288518876 | 703 | array[y7+36][x7+5]= 1; |
el14ws | 0:4b8288518876 | 704 | |
el14ws | 0:4b8288518876 | 705 | array[y8+36][x8+5]= 1; |
el14ws | 0:4b8288518876 | 706 | |
el14ws | 0:4b8288518876 | 707 | array[y9+36][x9+5]= 1; |
el14ws | 0:4b8288518876 | 708 | |
el14ws | 0:4b8288518876 | 709 | array[y10+36][x10+5]= 1; |
el14ws | 0:4b8288518876 | 710 | |
el14ws | 0:4b8288518876 | 711 | array[y11+36][x11+5]= 1; |
el14ws | 0:4b8288518876 | 712 | |
el14ws | 0:4b8288518876 | 713 | array[y12+36][x12+5]= 1; |
el14ws | 0:4b8288518876 | 714 | |
el14ws | 0:4b8288518876 | 715 | array[y13+36][x13+5]= 1; |
el14ws | 0:4b8288518876 | 716 | |
el14ws | 0:4b8288518876 | 717 | array[y14+36][x14+5]= 1; |
el14ws | 0:4b8288518876 | 718 | |
el14ws | 0:4b8288518876 | 719 | array[y15+36][x15+5]= 1; |
el14ws | 0:4b8288518876 | 720 | |
el14ws | 0:4b8288518876 | 721 | array[y16+36][x16+5]= 1; |
el14ws | 0:4b8288518876 | 722 | |
el14ws | 0:4b8288518876 | 723 | array[y17+36][x17+5]= 1; |
el14ws | 0:4b8288518876 | 724 | |
el14ws | 0:4b8288518876 | 725 | array[y18+36][x18+5]= 1; |
el14ws | 0:4b8288518876 | 726 | |
el14ws | 0:4b8288518876 | 727 | array[y19+36][x19+5]= 1; |
el14ws | 0:4b8288518876 | 728 | |
el14ws | 0:4b8288518876 | 729 | array[y20+36][x20+5]= 1; |
el14ws | 0:4b8288518876 | 730 | |
el14ws | 0:4b8288518876 | 731 | array[y21+36][x21+5]= 1; |
el14ws | 0:4b8288518876 | 732 | |
el14ws | 0:4b8288518876 | 733 | array[y22+36][x22+5]= 1; |
el14ws | 0:4b8288518876 | 734 | |
el14ws | 0:4b8288518876 | 735 | } |
el14ws | 0:4b8288518876 | 736 | if(Score>=100) { |
el14ws | 0:4b8288518876 | 737 | array[y+36][x+5]= 1; |
el14ws | 0:4b8288518876 | 738 | |
el14ws | 0:4b8288518876 | 739 | array[y1+36][x1+5]= 1; |
el14ws | 0:4b8288518876 | 740 | |
el14ws | 0:4b8288518876 | 741 | array[y2+36][x2+5]= 1; |
el14ws | 0:4b8288518876 | 742 | |
el14ws | 0:4b8288518876 | 743 | array[y3+36][x3+5]= 1; |
el14ws | 0:4b8288518876 | 744 | |
el14ws | 0:4b8288518876 | 745 | array[y4+36][x4+5]= 1; |
el14ws | 0:4b8288518876 | 746 | |
el14ws | 0:4b8288518876 | 747 | array[y5+36][x5+5]= 1; |
el14ws | 0:4b8288518876 | 748 | |
el14ws | 0:4b8288518876 | 749 | array[y6+36][x6+5]= 1; |
el14ws | 0:4b8288518876 | 750 | |
el14ws | 0:4b8288518876 | 751 | array[y7+36][x7+5]= 1; |
el14ws | 0:4b8288518876 | 752 | |
el14ws | 0:4b8288518876 | 753 | array[y8+36][x8+5]= 1; |
el14ws | 0:4b8288518876 | 754 | |
el14ws | 0:4b8288518876 | 755 | array[y9+36][x9+5]= 1; |
el14ws | 0:4b8288518876 | 756 | |
el14ws | 0:4b8288518876 | 757 | array[y10+36][x10+5]= 1; |
el14ws | 0:4b8288518876 | 758 | |
el14ws | 0:4b8288518876 | 759 | array[y11+36][x11+5]= 1; |
el14ws | 0:4b8288518876 | 760 | |
el14ws | 0:4b8288518876 | 761 | array[y12+36][x12+5]= 1; |
el14ws | 0:4b8288518876 | 762 | |
el14ws | 0:4b8288518876 | 763 | array[y13+36][x13+5]= 1; |
el14ws | 0:4b8288518876 | 764 | |
el14ws | 0:4b8288518876 | 765 | array[y14+36][x14+5]= 1; |
el14ws | 0:4b8288518876 | 766 | |
el14ws | 0:4b8288518876 | 767 | array[y15+36][x15+5]= 1; |
el14ws | 0:4b8288518876 | 768 | |
el14ws | 0:4b8288518876 | 769 | array[y16+36][x16+5]= 1; |
el14ws | 0:4b8288518876 | 770 | |
el14ws | 0:4b8288518876 | 771 | array[y17+36][x17+5]= 1; |
el14ws | 0:4b8288518876 | 772 | |
el14ws | 0:4b8288518876 | 773 | array[y18+36][x18+5]= 1; |
el14ws | 0:4b8288518876 | 774 | |
el14ws | 0:4b8288518876 | 775 | array[y19+36][x19+5]= 1; |
el14ws | 0:4b8288518876 | 776 | |
el14ws | 0:4b8288518876 | 777 | array[y20+36][x20+5]= 1; |
el14ws | 0:4b8288518876 | 778 | |
el14ws | 0:4b8288518876 | 779 | array[y21+36][x21+5]= 1; |
el14ws | 0:4b8288518876 | 780 | |
el14ws | 0:4b8288518876 | 781 | array[y22+36][x22+5]= 1; |
el14ws | 0:4b8288518876 | 782 | |
el14ws | 0:4b8288518876 | 783 | array[y23+36][x23+5]= 1; |
el14ws | 0:4b8288518876 | 784 | |
el14ws | 0:4b8288518876 | 785 | array[y24+36][x24+5]= 1; |
el14ws | 0:4b8288518876 | 786 | |
el14ws | 0:4b8288518876 | 787 | } |
el14ws | 0:4b8288518876 | 788 | DrawArray(); |
el14ws | 0:4b8288518876 | 789 | |
el14ws | 0:4b8288518876 | 790 | |
el14ws | 0:4b8288518876 | 791 | |
el14ws | 0:4b8288518876 | 792 | } |
el14ws | 0:4b8288518876 | 793 | |
el14ws | 0:4b8288518876 | 794 | |
el14ws | 0:4b8288518876 | 795 | /*void GameOver() |
el14ws | 0:4b8288518876 | 796 | { |
el14ws | 1:44cc07feab7e | 797 | if (joystick.direction == CENTRE) { |
el14ws | 1:44cc07feab7e | 798 | //lcd.printString("CENTRE",20,1); // display welcome |
el14ws | 1:44cc07feab7e | 799 | wait(0.05); |
el14ws | 1:44cc07feab7e | 800 | } else if (joystick.direction == UP) { |
el14ws | 1:44cc07feab7e | 801 | lcd.printString("UP",20,1); // display welcome |
el14ws | 1:44cc07feab7e | 802 | wait(0.05); |
el14ws | 1:44cc07feab7e | 803 | if(y+36==2 && x+5==2) { |
el14ws | 1:44cc07feab7e | 804 | GenerateFood(); |
el14ws | 1:44cc07feab7e | 805 | } else if (joystick.direction == DOWN) { |
el14ws | 1:44cc07feab7e | 806 | lcd.printString("DOWN",20,1); // display welcome |
el14ws | 1:44cc07feab7e | 807 | wait(0.05); |
el14ws | 1:44cc07feab7e | 808 | change = 2; |
el14ws | 1:44cc07feab7e | 809 | if(y+36==randY && x+5==randX) { |
el14ws | 1:44cc07feab7e | 810 | GenerateFood(); |
el14ws | 1:44cc07feab7e | 811 | } else if (joystick.direction == LEFT) { |
el14ws | 1:44cc07feab7e | 812 | //lcd.printString("LEFT",20,1); // display welcome |
el14ws | 1:44cc07feab7e | 813 | wait(0.05); |
el14ws | 1:44cc07feab7e | 814 | change = 3; |
el14ws | 1:44cc07feab7e | 815 | } else if (joystick.direction == RIGHT) { |
el14ws | 1:44cc07feab7e | 816 | //lcd.printString("RIGHT",20,1); // display welcome |
el14ws | 1:44cc07feab7e | 817 | wait(0.05); |
el14ws | 1:44cc07feab7e | 818 | change = 4; |
el14ws | 1:44cc07feab7e | 819 | } |
el14ws | 0:4b8288518876 | 820 | |
el14ws | 0:4b8288518876 | 821 | } |
el14ws | 0:4b8288518876 | 822 | } |
el14ws | 1:44cc07feab7e | 823 | */ |