
hgftf
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
main.cpp@9:d09b96b6c39c, 2020-11-20 (annotated)
- Committer:
- ajorgih3
- Date:
- Fri Nov 20 21:58:45 2020 +0000
- Revision:
- 9:d09b96b6c39c
- Parent:
- 8:34fd253d0fa5
- Child:
- 10:0b2f37cef9b9
yes;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DCchico | 2:4947d6a82971 | 1 | //================================================================= |
DCchico | 2:4947d6a82971 | 2 | // The main program file. |
DCchico | 2:4947d6a82971 | 3 | // |
DCchico | 2:4947d6a82971 | 4 | // Copyright 2020 Georgia Tech. All rights reserved. |
DCchico | 2:4947d6a82971 | 5 | // The materials provided by the instructor in this course are for |
DCchico | 2:4947d6a82971 | 6 | // the use of the students currently enrolled in the course. |
DCchico | 2:4947d6a82971 | 7 | // Copyrighted course materials may not be further disseminated. |
DCchico | 2:4947d6a82971 | 8 | // This file must not be made publicly available anywhere. |
DCchico | 2:4947d6a82971 | 9 | //================================================================== |
DCchico | 2:4947d6a82971 | 10 | |
DCchico | 2:4947d6a82971 | 11 | // Project includes |
DCchico | 1:10330bce85cb | 12 | #include "globals.h" |
DCchico | 1:10330bce85cb | 13 | #include "hardware.h" |
DCchico | 1:10330bce85cb | 14 | #include "map.h" |
DCchico | 1:10330bce85cb | 15 | #include "graphics.h" |
DCchico | 1:10330bce85cb | 16 | #include "snake.h" |
DCchico | 1:10330bce85cb | 17 | |
DCchico | 1:10330bce85cb | 18 | #include <math.h> |
DCchico | 1:10330bce85cb | 19 | #include<stdio.h> |
ajorgih3 | 5:5953ca12205d | 20 | #include <time.h> |
ajorgih3 | 5:5953ca12205d | 21 | #include <stdlib.h> |
ajorgih3 | 5:5953ca12205d | 22 | #include <ctime> |
ajorgih3 | 5:5953ca12205d | 23 | #include <cstdlib> |
ajorgih3 | 5:5953ca12205d | 24 | #include <iostream> |
DCchico | 1:10330bce85cb | 25 | |
DCchico | 1:10330bce85cb | 26 | #define CITY_HIT_MARGIN 1 |
DCchico | 1:10330bce85cb | 27 | #define CITY_UPPER_BOUND (SIZE_Y-(LANDSCAPE_HEIGHT+MAX_BUILDING_HEIGHT)) |
DCchico | 2:4947d6a82971 | 28 | |
DCchico | 1:10330bce85cb | 29 | // Helper function declarations |
DCchico | 1:10330bce85cb | 30 | void playSound(char* wav); |
DCchico | 1:10330bce85cb | 31 | |
DCchico | 1:10330bce85cb | 32 | /** |
DCchico | 1:10330bce85cb | 33 | * The main game state. Must include snake locations and previous locations for |
DCchico | 1:10330bce85cb | 34 | * drawing to work properly. Other items can be added as needed. |
DCchico | 1:10330bce85cb | 35 | */ |
DCchico | 1:10330bce85cb | 36 | |
DCchico | 1:10330bce85cb | 37 | /** |
DCchico | 1:10330bce85cb | 38 | * Given the game inputs, determine what kind of update needs to happen. |
DCchico | 1:10330bce85cb | 39 | * Possbile return values are defined below. |
DCchico | 1:10330bce85cb | 40 | */ |
DCchico | 1:10330bce85cb | 41 | Snake snake; |
ajorgih3 | 3:bb6f73642f01 | 42 | int score; |
ajorgih3 | 3:bb6f73642f01 | 43 | GameInputs input; |
ajorgih3 | 3:bb6f73642f01 | 44 | int main(); |
ajorgih3 | 3:bb6f73642f01 | 45 | int previousState; |
ajorgih3 | 3:bb6f73642f01 | 46 | int thisState; |
ajorgih3 | 3:bb6f73642f01 | 47 | int lives = 0; |
ajorgih3 | 3:bb6f73642f01 | 48 | int main2(); |
ajorgih3 | 4:697e1120f821 | 49 | int y; |
ajorgih3 | 3:bb6f73642f01 | 50 | MapItem *nextHead; |
ajorgih3 | 4:697e1120f821 | 51 | int updateY(); |
ajorgih3 | 4:697e1120f821 | 52 | void go_right2(); |
ajorgih3 | 4:697e1120f821 | 53 | void go_up2(); |
ajorgih3 | 5:5953ca12205d | 54 | void go_down2(); |
ajorgih3 | 5:5953ca12205d | 55 | void go_left2(); |
ajorgih3 | 5:5953ca12205d | 56 | int bodyLength = 1; |
ajorgih3 | 5:5953ca12205d | 57 | int bodyX[50]; |
ajorgih3 | 5:5953ca12205d | 58 | int bodyY[50]; |
ajorgih3 | 6:fbaee888e5ea | 59 | int reverseCounter; |
ajorgih3 | 6:fbaee888e5ea | 60 | int speedCounter; |
ajorgih3 | 6:fbaee888e5ea | 61 | bool invincibility = false; |
ajorgih3 | 6:fbaee888e5ea | 62 | int shieldCounter = 0; |
ajorgih3 | 7:7ab2f4b09196 | 63 | int slowflakeCounter = 0; |
ajorgih3 | 7:7ab2f4b09196 | 64 | void additional_info(); |
ajorgih3 | 7:7ab2f4b09196 | 65 | int redCounter = 0; |
ajorgih3 | 7:7ab2f4b09196 | 66 | int blueCounter = 0; |
DCchico | 1:10330bce85cb | 67 | |
DCchico | 1:10330bce85cb | 68 | // Function prototypes |
DCchico | 2:4947d6a82971 | 69 | |
DCchico | 2:4947d6a82971 | 70 | /** |
DCchico | 2:4947d6a82971 | 71 | * Given the game inputs, determine what kind of update needs to happen. |
DCchico | 2:4947d6a82971 | 72 | * Possible return values are defined below. |
DCchico | 2:4947d6a82971 | 73 | */ |
DCchico | 2:4947d6a82971 | 74 | #define NO_RESULT 0 |
DCchico | 2:4947d6a82971 | 75 | #define NO_ACTION 0 |
DCchico | 2:4947d6a82971 | 76 | #define ACTION_BUTTON 1 |
DCchico | 2:4947d6a82971 | 77 | #define MENU_BUTTON 2 |
DCchico | 2:4947d6a82971 | 78 | #define GO_LEFT 3 |
DCchico | 2:4947d6a82971 | 79 | #define GO_RIGHT 4 |
DCchico | 2:4947d6a82971 | 80 | #define GO_UP 5 |
DCchico | 2:4947d6a82971 | 81 | #define GO_DOWN 6 |
DCchico | 2:4947d6a82971 | 82 | #define GAME_OVER 7 |
DCchico | 2:4947d6a82971 | 83 | #define FULL_DRAW 8 |
ajorgih3 | 4:697e1120f821 | 84 | #define HAX 9 |
ajorgih3 | 8:34fd253d0fa5 | 85 | #define PAUSE 10 |
ajorgih3 | 3:bb6f73642f01 | 86 | #define IN_GAME_MENU 11 |
ajorgih3 | 3:bb6f73642f01 | 87 | #define NOT_RIGHT 12 |
ajorgih3 | 5:5953ca12205d | 88 | #define SNAKE_MAX_LENGTH 50 |
ajorgih3 | 7:7ab2f4b09196 | 89 | #define WIN_GAME 13 |
ajorgih3 | 3:bb6f73642f01 | 90 | |
ajorgih3 | 3:bb6f73642f01 | 91 | |
DCchico | 1:10330bce85cb | 92 | // Get Actions from User (push buttons & accelerometer) |
DCchico | 2:4947d6a82971 | 93 | // Based on push button and accelerometer inputs, determine which action |
DCchico | 2:4947d6a82971 | 94 | // needs to be performed (may be no action). |
DCchico | 1:10330bce85cb | 95 | int get_action(GameInputs inputs) |
DCchico | 1:10330bce85cb | 96 | { |
ajorgih3 | 3:bb6f73642f01 | 97 | // threshold for moving right |
ajorgih3 | 6:fbaee888e5ea | 98 | if (inputs.ax >= 0.30 && inputs.ax <= 0.60) { |
ajorgih3 | 6:fbaee888e5ea | 99 | return GO_RIGHT; |
ajorgih3 | 6:fbaee888e5ea | 100 | } |
ajorgih3 | 3:bb6f73642f01 | 101 | // threshold for moving left |
ajorgih3 | 6:fbaee888e5ea | 102 | if (inputs.ax <= -0.30 && inputs.ax >= -0.60) { |
ajorgih3 | 6:fbaee888e5ea | 103 | return GO_LEFT; |
ajorgih3 | 6:fbaee888e5ea | 104 | } |
ajorgih3 | 3:bb6f73642f01 | 105 | // threshold for moving up |
ajorgih3 | 6:fbaee888e5ea | 106 | if (inputs.ay >= 0.30 && inputs.ay <= 0.60) { |
ajorgih3 | 6:fbaee888e5ea | 107 | return GO_UP; |
ajorgih3 | 6:fbaee888e5ea | 108 | } |
ajorgih3 | 3:bb6f73642f01 | 109 | // threshold for moving down |
ajorgih3 | 6:fbaee888e5ea | 110 | if (inputs.ay <= -0.30 && inputs.ay >= -0.60) { |
ajorgih3 | 6:fbaee888e5ea | 111 | return GO_DOWN; |
ajorgih3 | 6:fbaee888e5ea | 112 | } |
ajorgih3 | 3:bb6f73642f01 | 113 | |
ajorgih3 | 6:fbaee888e5ea | 114 | if (!inputs.b1) { |
ajorgih3 | 6:fbaee888e5ea | 115 | return HAX; |
ajorgih3 | 6:fbaee888e5ea | 116 | } |
ajorgih3 | 8:34fd253d0fa5 | 117 | |
ajorgih3 | 8:34fd253d0fa5 | 118 | if (!inputs.b2) { |
ajorgih3 | 8:34fd253d0fa5 | 119 | return PAUSE; |
ajorgih3 | 8:34fd253d0fa5 | 120 | } |
ajorgih3 | 3:bb6f73642f01 | 121 | |
ajorgih3 | 3:bb6f73642f01 | 122 | // if we do not satisfy these conditions then |
ajorgih3 | 3:bb6f73642f01 | 123 | // no action is done |
ajorgih3 | 6:fbaee888e5ea | 124 | return NO_ACTION; |
DCchico | 1:10330bce85cb | 125 | } |
DCchico | 1:10330bce85cb | 126 | /** |
DCchico | 1:10330bce85cb | 127 | * Update the game state based on the user action. For example, if the user |
DCchico | 1:10330bce85cb | 128 | * requests GO_UP, then this function should determine if that is possible by |
DCchico | 1:10330bce85cb | 129 | * consulting the map, and update the snake position accordingly. |
DCchico | 1:10330bce85cb | 130 | * |
DCchico | 1:10330bce85cb | 131 | * Return values are defined below. FULL_DRAW indicates that for this frame, |
DCchico | 1:10330bce85cb | 132 | * draw_game should not optimize drawing and should draw every tile, even if |
DCchico | 1:10330bce85cb | 133 | * the snake has not moved. |
DCchico | 1:10330bce85cb | 134 | */ |
ajorgih3 | 3:bb6f73642f01 | 135 | |
DCchico | 1:10330bce85cb | 136 | |
DCchico | 1:10330bce85cb | 137 | /** |
DCchico | 1:10330bce85cb | 138 | * Draw the upper status bar. |
DCchico | 1:10330bce85cb | 139 | */ |
ajorgih3 | 3:bb6f73642f01 | 140 | void draw_upper_status(int x, int y, int z) |
DCchico | 1:10330bce85cb | 141 | { |
ajorgih3 | 6:fbaee888e5ea | 142 | uLCD.line(0, 9, 127, 9, GREEN); |
ajorgih3 | 6:fbaee888e5ea | 143 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 144 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 145 | uLCD.color(0xFFFF00); |
ajorgih3 | 6:fbaee888e5ea | 146 | uLCD.locate(0,0); |
ajorgih3 | 6:fbaee888e5ea | 147 | uLCD.printf("POS:%d,%d ", x, y); |
ajorgih3 | 6:fbaee888e5ea | 148 | uLCD.locate(10,0); |
ajorgih3 | 6:fbaee888e5ea | 149 | uLCD.printf("SCORE:%d", score); |
DCchico | 1:10330bce85cb | 150 | } |
DCchico | 1:10330bce85cb | 151 | |
DCchico | 1:10330bce85cb | 152 | /** |
DCchico | 1:10330bce85cb | 153 | * Draw the lower status bar. |
DCchico | 1:10330bce85cb | 154 | */ |
ajorgih3 | 3:bb6f73642f01 | 155 | void draw_lower_status(int lives) |
DCchico | 1:10330bce85cb | 156 | { |
ajorgih3 | 6:fbaee888e5ea | 157 | uLCD.line(0, 118, 127, 118, 0xFFFF00); |
ajorgih3 | 6:fbaee888e5ea | 158 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 159 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 160 | uLCD.color(0xFFFF00); |
ajorgih3 | 6:fbaee888e5ea | 161 | uLCD.locate(0,15); |
ajorgih3 | 6:fbaee888e5ea | 162 | uLCD.printf("LIVES:%d", lives); |
ajorgih3 | 6:fbaee888e5ea | 163 | |
DCchico | 1:10330bce85cb | 164 | } |
DCchico | 1:10330bce85cb | 165 | |
DCchico | 1:10330bce85cb | 166 | /** |
DCchico | 1:10330bce85cb | 167 | * Draw the border for the map. |
DCchico | 1:10330bce85cb | 168 | */ |
DCchico | 1:10330bce85cb | 169 | void draw_border() |
DCchico | 1:10330bce85cb | 170 | { |
ajorgih3 | 6:fbaee888e5ea | 171 | uLCD.filled_rectangle(0, 9, 127, 14, WHITE); // Top |
ajorgih3 | 6:fbaee888e5ea | 172 | uLCD.filled_rectangle(0, 13, 2, 114, WHITE); // Left |
ajorgih3 | 6:fbaee888e5ea | 173 | uLCD.filled_rectangle(0, 114, 127, 117, WHITE); // Bottom |
ajorgih3 | 6:fbaee888e5ea | 174 | uLCD.filled_rectangle(124, 14, 127, 117, WHITE); // Right |
DCchico | 1:10330bce85cb | 175 | } |
DCchico | 1:10330bce85cb | 176 | |
ajorgih3 | 3:bb6f73642f01 | 177 | |
DCchico | 1:10330bce85cb | 178 | /** |
DCchico | 1:10330bce85cb | 179 | * Entry point for frame drawing. This should be called once per iteration of |
DCchico | 1:10330bce85cb | 180 | * the game loop. This draws all tiles on the screen, followed by the status |
DCchico | 1:10330bce85cb | 181 | * bars. Unless init is nonzero, this function will optimize drawing by only |
DCchico | 1:10330bce85cb | 182 | * drawing tiles that have changed from the previous frame. |
DCchico | 1:10330bce85cb | 183 | */ |
DCchico | 1:10330bce85cb | 184 | void draw_game(int draw_option) |
ajorgih3 | 3:bb6f73642f01 | 185 | { |
ajorgih3 | 7:7ab2f4b09196 | 186 | if (draw_option == WIN_GAME) { |
ajorgih3 | 7:7ab2f4b09196 | 187 | int u = 58; |
ajorgih3 | 7:7ab2f4b09196 | 188 | int v = 56; |
ajorgih3 | 7:7ab2f4b09196 | 189 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 7:7ab2f4b09196 | 190 | uLCD.text_width(1); |
ajorgih3 | 7:7ab2f4b09196 | 191 | uLCD.text_height(1); |
ajorgih3 | 7:7ab2f4b09196 | 192 | uLCD.locate(5,7); |
ajorgih3 | 7:7ab2f4b09196 | 193 | uLCD.color(RED); |
ajorgih3 | 7:7ab2f4b09196 | 194 | uLCD.printf("YOU WIN\n"); |
ajorgih3 | 7:7ab2f4b09196 | 195 | draw_snake_head(u+11, v+11); |
ajorgih3 | 7:7ab2f4b09196 | 196 | draw_snake_body(u, v+11); |
ajorgih3 | 7:7ab2f4b09196 | 197 | draw_snake_tail(u-11, v+11); |
ajorgih3 | 7:7ab2f4b09196 | 198 | |
ajorgih3 | 7:7ab2f4b09196 | 199 | uLCD.textbackground_color(BLACK); |
ajorgih3 | 7:7ab2f4b09196 | 200 | uLCD.color(0xFFFFFF); |
ajorgih3 | 7:7ab2f4b09196 | 201 | uLCD.text_width(1); |
ajorgih3 | 7:7ab2f4b09196 | 202 | uLCD.text_height(1); |
ajorgih3 | 7:7ab2f4b09196 | 203 | uLCD.locate(4, 10); |
ajorgih3 | 7:7ab2f4b09196 | 204 | uLCD.printf("Press 'B2'\n"); |
ajorgih3 | 7:7ab2f4b09196 | 205 | uLCD.locate(2, 11); |
ajorgih3 | 7:7ab2f4b09196 | 206 | uLCD.printf("to play again!\n"); |
ajorgih3 | 7:7ab2f4b09196 | 207 | |
ajorgih3 | 7:7ab2f4b09196 | 208 | do { |
ajorgih3 | 7:7ab2f4b09196 | 209 | input = read_inputs(); |
ajorgih3 | 7:7ab2f4b09196 | 210 | } while(input.b2); |
ajorgih3 | 7:7ab2f4b09196 | 211 | |
ajorgih3 | 7:7ab2f4b09196 | 212 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 7:7ab2f4b09196 | 213 | main2(); |
ajorgih3 | 7:7ab2f4b09196 | 214 | |
ajorgih3 | 7:7ab2f4b09196 | 215 | } |
ajorgih3 | 7:7ab2f4b09196 | 216 | |
ajorgih3 | 7:7ab2f4b09196 | 217 | |
ajorgih3 | 3:bb6f73642f01 | 218 | // prints game over if the player loses. |
ajorgih3 | 6:fbaee888e5ea | 219 | if (draw_option == GAME_OVER) { |
ajorgih3 | 6:fbaee888e5ea | 220 | int u = 58; |
ajorgih3 | 6:fbaee888e5ea | 221 | int v = 56; |
ajorgih3 | 6:fbaee888e5ea | 222 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 6:fbaee888e5ea | 223 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 224 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 225 | uLCD.locate(5,7); |
ajorgih3 | 6:fbaee888e5ea | 226 | uLCD.color(RED); |
ajorgih3 | 6:fbaee888e5ea | 227 | uLCD.printf("GAME OVER\n"); |
ajorgih3 | 6:fbaee888e5ea | 228 | draw_snake_head(u+22, v+11); |
ajorgih3 | 6:fbaee888e5ea | 229 | draw_snake_tail(u-22, v+11); |
ajorgih3 | 3:bb6f73642f01 | 230 | |
ajorgih3 | 6:fbaee888e5ea | 231 | uLCD.textbackground_color(BLACK); |
ajorgih3 | 6:fbaee888e5ea | 232 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 233 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 234 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 235 | uLCD.locate(4, 10); |
ajorgih3 | 6:fbaee888e5ea | 236 | uLCD.printf("Press 'B2'\n"); |
ajorgih3 | 6:fbaee888e5ea | 237 | uLCD.locate(5, 11); |
ajorgih3 | 6:fbaee888e5ea | 238 | uLCD.printf("to retry!\n"); |
ajorgih3 | 3:bb6f73642f01 | 239 | |
ajorgih3 | 6:fbaee888e5ea | 240 | do { |
ajorgih3 | 6:fbaee888e5ea | 241 | input = read_inputs(); |
ajorgih3 | 6:fbaee888e5ea | 242 | } while(input.b2); |
ajorgih3 | 8:34fd253d0fa5 | 243 | |
ajorgih3 | 8:34fd253d0fa5 | 244 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 6:fbaee888e5ea | 245 | main(); |
ajorgih3 | 3:bb6f73642f01 | 246 | |
ajorgih3 | 6:fbaee888e5ea | 247 | } |
ajorgih3 | 3:bb6f73642f01 | 248 | |
DCchico | 1:10330bce85cb | 249 | // Draw game border first |
ajorgih3 | 6:fbaee888e5ea | 250 | if(draw_option == FULL_DRAW) |
ajorgih3 | 6:fbaee888e5ea | 251 | { |
ajorgih3 | 6:fbaee888e5ea | 252 | draw_border(); |
ajorgih3 | 6:fbaee888e5ea | 253 | int u = 58; |
ajorgih3 | 6:fbaee888e5ea | 254 | int v = 59; |
ajorgih3 | 3:bb6f73642f01 | 255 | |
ajorgih3 | 6:fbaee888e5ea | 256 | snake.locations[0].x = snake.body_x; |
ajorgih3 | 6:fbaee888e5ea | 257 | snake.locations[0].y = snake.body_y; |
ajorgih3 | 3:bb6f73642f01 | 258 | |
ajorgih3 | 6:fbaee888e5ea | 259 | draw_snake_head(u, v); |
ajorgih3 | 6:fbaee888e5ea | 260 | draw_snake_body(u-11, v); |
ajorgih3 | 6:fbaee888e5ea | 261 | draw_snake_tail(u-22, v); |
ajorgih3 | 3:bb6f73642f01 | 262 | |
ajorgih3 | 6:fbaee888e5ea | 263 | return; |
ajorgih3 | 6:fbaee888e5ea | 264 | } |
DCchico | 1:10330bce85cb | 265 | // Iterate over all visible map tiles |
ajorgih3 | 6:fbaee888e5ea | 266 | for (int i = -5; i <= 5; i++) { // Iterate over columns of tiles |
ajorgih3 | 6:fbaee888e5ea | 267 | for (int j = -4; j <= 4; j++) { // Iterate over one column of tiles |
DCchico | 1:10330bce85cb | 268 | // Here, we have a given (i,j) |
ajorgih3 | 6:fbaee888e5ea | 269 | |
DCchico | 1:10330bce85cb | 270 | // Compute the current map (x,y) of this tile |
ajorgih3 | 6:fbaee888e5ea | 271 | int x = i + snake.head_x; |
ajorgih3 | 6:fbaee888e5ea | 272 | int y = j + snake.head_y; |
ajorgih3 | 6:fbaee888e5ea | 273 | |
DCchico | 1:10330bce85cb | 274 | // Compute the previous map (px, py) of this tile |
ajorgih3 | 6:fbaee888e5ea | 275 | int px = i + snake.head_px; |
ajorgih3 | 6:fbaee888e5ea | 276 | int py = j + snake.head_py; |
ajorgih3 | 6:fbaee888e5ea | 277 | |
DCchico | 1:10330bce85cb | 278 | // Compute u,v coordinates for drawing |
ajorgih3 | 6:fbaee888e5ea | 279 | int u = (i+5)*11 + 3; |
ajorgih3 | 6:fbaee888e5ea | 280 | int v = (j+4)*11 + 15; |
ajorgih3 | 6:fbaee888e5ea | 281 | |
DCchico | 1:10330bce85cb | 282 | // Figure out what to draw |
ajorgih3 | 6:fbaee888e5ea | 283 | DrawFunc draw = NULL; |
ajorgih3 | 6:fbaee888e5ea | 284 | if (x >= 0 && y >= 0 && x < map_width() && y < map_height()) { // Current (i,j) in the map |
ajorgih3 | 6:fbaee888e5ea | 285 | MapItem* curr_item = get_here(x, y); |
ajorgih3 | 6:fbaee888e5ea | 286 | MapItem* prev_item = get_here(px, py); |
ajorgih3 | 6:fbaee888e5ea | 287 | if (draw_option || curr_item != prev_item) { // Only draw if they're different |
ajorgih3 | 6:fbaee888e5ea | 288 | if (curr_item) { // There's something here! Draw it |
ajorgih3 | 6:fbaee888e5ea | 289 | draw = curr_item->draw; |
ajorgih3 | 6:fbaee888e5ea | 290 | } |
ajorgih3 | 6:fbaee888e5ea | 291 | else { // There used to be something, but now there isn't |
ajorgih3 | 6:fbaee888e5ea | 292 | draw = draw_nothing; |
ajorgih3 | 6:fbaee888e5ea | 293 | } |
ajorgih3 | 6:fbaee888e5ea | 294 | } |
ajorgih3 | 6:fbaee888e5ea | 295 | else if (curr_item && curr_item->type == CLEAR) { |
DCchico | 1:10330bce85cb | 296 | // This is a special case for erasing things like doors. |
ajorgih3 | 6:fbaee888e5ea | 297 | draw = curr_item->draw; // i.e. draw_nothing |
DCchico | 1:10330bce85cb | 298 | } |
ajorgih3 | 6:fbaee888e5ea | 299 | } |
ajorgih3 | 6:fbaee888e5ea | 300 | else if (draw_option) { // If doing a full draw, but we're out of bounds, draw the walls. |
ajorgih3 | 6:fbaee888e5ea | 301 | draw = draw_wall; |
ajorgih3 | 6:fbaee888e5ea | 302 | } |
ajorgih3 | 6:fbaee888e5ea | 303 | |
DCchico | 1:10330bce85cb | 304 | // Actually draw the tile |
ajorgih3 | 6:fbaee888e5ea | 305 | if (draw) draw(u, v); |
ajorgih3 | 6:fbaee888e5ea | 306 | } |
ajorgih3 | 6:fbaee888e5ea | 307 | } |
DCchico | 1:10330bce85cb | 308 | |
DCchico | 1:10330bce85cb | 309 | // Draw status bars |
ajorgih3 | 6:fbaee888e5ea | 310 | draw_upper_status(snake.head_x, updateY(), score); |
ajorgih3 | 6:fbaee888e5ea | 311 | draw_lower_status(lives); |
ajorgih3 | 3:bb6f73642f01 | 312 | } |
ajorgih3 | 3:bb6f73642f01 | 313 | |
ajorgih3 | 4:697e1120f821 | 314 | int updateY() { |
ajorgih3 | 6:fbaee888e5ea | 315 | y = snake.head_y; |
ajorgih3 | 6:fbaee888e5ea | 316 | return y; |
ajorgih3 | 4:697e1120f821 | 317 | } |
ajorgih3 | 4:697e1120f821 | 318 | |
ajorgih3 | 3:bb6f73642f01 | 319 | void start_game() { |
ajorgih3 | 6:fbaee888e5ea | 320 | int u = 58; |
ajorgih3 | 6:fbaee888e5ea | 321 | int v = 56; |
ajorgih3 | 3:bb6f73642f01 | 322 | |
ajorgih3 | 6:fbaee888e5ea | 323 | uLCD.textbackground_color(GREEN); |
ajorgih3 | 6:fbaee888e5ea | 324 | uLCD.filled_rectangle(0, 9, 127, 14, WHITE); // Top |
ajorgih3 | 6:fbaee888e5ea | 325 | uLCD.filled_rectangle(0, 13, 2, 114, WHITE); // Left |
ajorgih3 | 6:fbaee888e5ea | 326 | uLCD.filled_rectangle(0, 114, 127, 117, WHITE); // Bottom |
ajorgih3 | 6:fbaee888e5ea | 327 | uLCD.filled_rectangle(124, 14, 127, 117, WHITE); // Right |
ajorgih3 | 6:fbaee888e5ea | 328 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 329 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 330 | uLCD.locate(2, 3); |
ajorgih3 | 6:fbaee888e5ea | 331 | uLCD.color(RED); |
ajorgih3 | 6:fbaee888e5ea | 332 | uLCD.printf("-Sneaky Snakey-"); |
ajorgih3 | 6:fbaee888e5ea | 333 | uLCD.textbackground_color(BLUE); |
ajorgih3 | 6:fbaee888e5ea | 334 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 335 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 336 | uLCD.locate(5, 4); |
ajorgih3 | 6:fbaee888e5ea | 337 | uLCD.color(0xFFFF00); |
ajorgih3 | 6:fbaee888e5ea | 338 | uLCD.printf("ECE 2035"); |
ajorgih3 | 6:fbaee888e5ea | 339 | uLCD.locate(7,5); |
ajorgih3 | 3:bb6f73642f01 | 340 | |
ajorgih3 | 6:fbaee888e5ea | 341 | draw_snake_head(u, v); |
ajorgih3 | 6:fbaee888e5ea | 342 | draw_snake_body(u-11, v); |
ajorgih3 | 6:fbaee888e5ea | 343 | draw_snake_tail(u-22, v); |
ajorgih3 | 3:bb6f73642f01 | 344 | |
ajorgih3 | 6:fbaee888e5ea | 345 | draw_goodie(u+22, v); |
ajorgih3 | 3:bb6f73642f01 | 346 | |
ajorgih3 | 6:fbaee888e5ea | 347 | uLCD.textbackground_color(BLACK); |
ajorgih3 | 6:fbaee888e5ea | 348 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 349 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 350 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 351 | uLCD.locate(4, 10); |
ajorgih3 | 6:fbaee888e5ea | 352 | uLCD.printf("Press 'B2'\n"); |
ajorgih3 | 6:fbaee888e5ea | 353 | uLCD.locate(5, 11); |
ajorgih3 | 6:fbaee888e5ea | 354 | uLCD.printf("to start!\n"); |
ajorgih3 | 3:bb6f73642f01 | 355 | |
ajorgih3 | 6:fbaee888e5ea | 356 | do { |
ajorgih3 | 6:fbaee888e5ea | 357 | input = read_inputs(); |
ajorgih3 | 6:fbaee888e5ea | 358 | } while(input.b2); |
ajorgih3 | 6:fbaee888e5ea | 359 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 3:bb6f73642f01 | 360 | } |
ajorgih3 | 3:bb6f73642f01 | 361 | |
ajorgih3 | 3:bb6f73642f01 | 362 | void title_page() { |
ajorgih3 | 3:bb6f73642f01 | 363 | |
ajorgih3 | 6:fbaee888e5ea | 364 | int u = 58; |
ajorgih3 | 6:fbaee888e5ea | 365 | int v = 56; |
ajorgih3 | 3:bb6f73642f01 | 366 | |
ajorgih3 | 6:fbaee888e5ea | 367 | uLCD.filled_rectangle(0, 9, 127, 14, 0xFFFF00); // Top |
ajorgih3 | 6:fbaee888e5ea | 368 | uLCD.filled_rectangle(0, 13, 2, 114, 0xFFFF00); // Left |
ajorgih3 | 6:fbaee888e5ea | 369 | uLCD.filled_rectangle(0, 114, 127, 117, 0xFFFF00); // Bottom |
ajorgih3 | 6:fbaee888e5ea | 370 | uLCD.filled_rectangle(124, 14, 127, 117, 0xFFFF00); // Right |
ajorgih3 | 6:fbaee888e5ea | 371 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 372 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 373 | uLCD.locate(5, 3); |
ajorgih3 | 6:fbaee888e5ea | 374 | uLCD.color(RED); |
ajorgih3 | 6:fbaee888e5ea | 375 | uLCD.printf("OBJECTIVE"); |
ajorgih3 | 6:fbaee888e5ea | 376 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 377 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 378 | uLCD.locate(2, 4); |
ajorgih3 | 6:fbaee888e5ea | 379 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 380 | uLCD.printf("Eat 20 goodies!"); |
ajorgih3 | 3:bb6f73642f01 | 381 | |
ajorgih3 | 6:fbaee888e5ea | 382 | uLCD.locate(7,5); |
ajorgih3 | 6:fbaee888e5ea | 383 | draw_goodie(u, v); |
ajorgih3 | 6:fbaee888e5ea | 384 | draw_goodie(u-22, v); |
ajorgih3 | 6:fbaee888e5ea | 385 | draw_goodie(u+22, v); |
ajorgih3 | 3:bb6f73642f01 | 386 | |
ajorgih3 | 6:fbaee888e5ea | 387 | uLCD.textbackground_color(BLACK); |
ajorgih3 | 6:fbaee888e5ea | 388 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 389 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 390 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 391 | uLCD.locate(3, 10); |
ajorgih3 | 6:fbaee888e5ea | 392 | uLCD.printf("Press 'B2'\n"); |
ajorgih3 | 6:fbaee888e5ea | 393 | uLCD.locate(3, 11); |
ajorgih3 | 6:fbaee888e5ea | 394 | uLCD.printf("to continue!\n"); |
ajorgih3 | 3:bb6f73642f01 | 395 | |
ajorgih3 | 6:fbaee888e5ea | 396 | do { |
ajorgih3 | 6:fbaee888e5ea | 397 | input = read_inputs(); |
ajorgih3 | 6:fbaee888e5ea | 398 | } while(input.b2); |
ajorgih3 | 6:fbaee888e5ea | 399 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 3:bb6f73642f01 | 400 | |
ajorgih3 | 3:bb6f73642f01 | 401 | } |
ajorgih3 | 3:bb6f73642f01 | 402 | |
ajorgih3 | 3:bb6f73642f01 | 403 | void helpful_items() { |
ajorgih3 | 3:bb6f73642f01 | 404 | int u = 58; |
ajorgih3 | 3:bb6f73642f01 | 405 | int v = 56; |
ajorgih3 | 3:bb6f73642f01 | 406 | |
ajorgih3 | 7:7ab2f4b09196 | 407 | uLCD.filled_rectangle(0, 9, 127, 14, 0xADD8E6); // Top |
ajorgih3 | 7:7ab2f4b09196 | 408 | uLCD.filled_rectangle(0, 13, 2, 114, 0xADD8E6); // Left |
ajorgih3 | 7:7ab2f4b09196 | 409 | uLCD.filled_rectangle(0, 114, 127, 117, 0xADD8E6); // Bottom |
ajorgih3 | 7:7ab2f4b09196 | 410 | uLCD.filled_rectangle(124, 14, 127, 117, 0xADD8E6); // Right |
ajorgih3 | 3:bb6f73642f01 | 411 | |
ajorgih3 | 6:fbaee888e5ea | 412 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 413 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 414 | uLCD.locate(6, 3); |
ajorgih3 | 6:fbaee888e5ea | 415 | uLCD.color(0xFFFF00); |
ajorgih3 | 6:fbaee888e5ea | 416 | uLCD.printf("BUFFS"); |
ajorgih3 | 3:bb6f73642f01 | 417 | |
ajorgih3 | 6:fbaee888e5ea | 418 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 419 | uLCD.text_height(1); |
ajorgih3 | 7:7ab2f4b09196 | 420 | uLCD.locate(1, 4); |
ajorgih3 | 6:fbaee888e5ea | 421 | uLCD.color(0xFFFFFF); |
ajorgih3 | 7:7ab2f4b09196 | 422 | uLCD.printf("Score w/o length"); |
ajorgih3 | 3:bb6f73642f01 | 423 | |
ajorgih3 | 6:fbaee888e5ea | 424 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 425 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 426 | uLCD.locate(2, 5); |
ajorgih3 | 6:fbaee888e5ea | 427 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 428 | uLCD.printf("Invincibility"); |
ajorgih3 | 3:bb6f73642f01 | 429 | |
ajorgih3 | 7:7ab2f4b09196 | 430 | draw_shield(u-22, v); |
ajorgih3 | 7:7ab2f4b09196 | 431 | draw_blue_potion(u+22, v); |
ajorgih3 | 3:bb6f73642f01 | 432 | |
ajorgih3 | 6:fbaee888e5ea | 433 | uLCD.textbackground_color(BLACK); |
ajorgih3 | 6:fbaee888e5ea | 434 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 435 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 436 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 437 | uLCD.locate(3, 10); |
ajorgih3 | 6:fbaee888e5ea | 438 | uLCD.printf("Press 'B2'\n"); |
ajorgih3 | 6:fbaee888e5ea | 439 | uLCD.locate(3, 11); |
ajorgih3 | 6:fbaee888e5ea | 440 | uLCD.printf("to continue!\n"); |
ajorgih3 | 3:bb6f73642f01 | 441 | |
ajorgih3 | 6:fbaee888e5ea | 442 | do { |
ajorgih3 | 6:fbaee888e5ea | 443 | input = read_inputs(); |
ajorgih3 | 6:fbaee888e5ea | 444 | } while(input.b2); |
ajorgih3 | 6:fbaee888e5ea | 445 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 3:bb6f73642f01 | 446 | |
ajorgih3 | 3:bb6f73642f01 | 447 | } |
ajorgih3 | 3:bb6f73642f01 | 448 | |
ajorgih3 | 3:bb6f73642f01 | 449 | void harmful_items() { |
ajorgih3 | 6:fbaee888e5ea | 450 | int u = 58; |
ajorgih3 | 3:bb6f73642f01 | 451 | int v = 56; |
ajorgih3 | 3:bb6f73642f01 | 452 | |
ajorgih3 | 6:fbaee888e5ea | 453 | uLCD.filled_rectangle(0, 9, 127, 14, RED); // Top |
ajorgih3 | 6:fbaee888e5ea | 454 | uLCD.filled_rectangle(0, 13, 2, 114, RED); // Left |
ajorgih3 | 6:fbaee888e5ea | 455 | uLCD.filled_rectangle(0, 114, 127, 117, RED); // Bottom |
ajorgih3 | 6:fbaee888e5ea | 456 | uLCD.filled_rectangle(124, 14, 127, 117, RED); // Right |
ajorgih3 | 3:bb6f73642f01 | 457 | |
ajorgih3 | 6:fbaee888e5ea | 458 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 459 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 460 | uLCD.locate(5, 3); |
ajorgih3 | 6:fbaee888e5ea | 461 | uLCD.color(0xFFA500); |
ajorgih3 | 6:fbaee888e5ea | 462 | uLCD.printf("DEBUFFS"); |
ajorgih3 | 3:bb6f73642f01 | 463 | |
ajorgih3 | 6:fbaee888e5ea | 464 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 465 | uLCD.text_height(1); |
ajorgih3 | 7:7ab2f4b09196 | 466 | uLCD.locate(5, 4); |
ajorgih3 | 6:fbaee888e5ea | 467 | uLCD.color(0xFFFFFF); |
ajorgih3 | 7:7ab2f4b09196 | 468 | uLCD.printf("Reverse"); |
ajorgih3 | 3:bb6f73642f01 | 469 | |
ajorgih3 | 6:fbaee888e5ea | 470 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 471 | uLCD.text_height(1); |
ajorgih3 | 7:7ab2f4b09196 | 472 | uLCD.locate(1, 5); |
ajorgih3 | 6:fbaee888e5ea | 473 | uLCD.color(0xFFFFFF); |
ajorgih3 | 7:7ab2f4b09196 | 474 | uLCD.printf("Length w/o score"); |
ajorgih3 | 3:bb6f73642f01 | 475 | |
ajorgih3 | 7:7ab2f4b09196 | 476 | draw_red_potion(u-22, v); |
ajorgih3 | 7:7ab2f4b09196 | 477 | draw_reverse(u+22, v); |
ajorgih3 | 3:bb6f73642f01 | 478 | |
ajorgih3 | 6:fbaee888e5ea | 479 | uLCD.textbackground_color(BLACK); |
ajorgih3 | 6:fbaee888e5ea | 480 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 481 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 482 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 483 | uLCD.locate(3, 10); |
ajorgih3 | 6:fbaee888e5ea | 484 | uLCD.printf("Press 'B2'\n"); |
ajorgih3 | 6:fbaee888e5ea | 485 | uLCD.locate(3, 11); |
ajorgih3 | 6:fbaee888e5ea | 486 | uLCD.printf("to continue!\n"); |
ajorgih3 | 3:bb6f73642f01 | 487 | |
ajorgih3 | 6:fbaee888e5ea | 488 | do { |
ajorgih3 | 6:fbaee888e5ea | 489 | input = read_inputs(); |
ajorgih3 | 6:fbaee888e5ea | 490 | } while(input.b2); |
ajorgih3 | 6:fbaee888e5ea | 491 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 7:7ab2f4b09196 | 492 | |
DCchico | 1:10330bce85cb | 493 | } |
DCchico | 1:10330bce85cb | 494 | |
ajorgih3 | 9:d09b96b6c39c | 495 | void helpful_items2() { |
ajorgih3 | 9:d09b96b6c39c | 496 | int u = 58; |
ajorgih3 | 9:d09b96b6c39c | 497 | int v = 56; |
ajorgih3 | 9:d09b96b6c39c | 498 | |
ajorgih3 | 9:d09b96b6c39c | 499 | uLCD.filled_rectangle(0, 9, 127, 14, 0x0000FF); // Top |
ajorgih3 | 9:d09b96b6c39c | 500 | uLCD.filled_rectangle(0, 13, 2, 114, 0x0000FF); // Left |
ajorgih3 | 9:d09b96b6c39c | 501 | uLCD.filled_rectangle(0, 114, 127, 117, 0x0000FF); // Bottom |
ajorgih3 | 9:d09b96b6c39c | 502 | uLCD.filled_rectangle(124, 14, 127, 117, 0x0000FF); // Right |
ajorgih3 | 9:d09b96b6c39c | 503 | |
ajorgih3 | 9:d09b96b6c39c | 504 | uLCD.text_width(1); |
ajorgih3 | 9:d09b96b6c39c | 505 | uLCD.text_height(1); |
ajorgih3 | 9:d09b96b6c39c | 506 | uLCD.locate(2, 3); |
ajorgih3 | 9:d09b96b6c39c | 507 | uLCD.color(0xFFFF00); |
ajorgih3 | 9:d09b96b6c39c | 508 | uLCD.printf("HELPFUL ITEMS++"); |
ajorgih3 | 9:d09b96b6c39c | 509 | |
ajorgih3 | 9:d09b96b6c39c | 510 | uLCD.text_width(1); |
ajorgih3 | 9:d09b96b6c39c | 511 | uLCD.text_height(1); |
ajorgih3 | 9:d09b96b6c39c | 512 | uLCD.locate(4, 4); |
ajorgih3 | 9:d09b96b6c39c | 513 | uLCD.color(0xFFFFFF); |
ajorgih3 | 9:d09b96b6c39c | 514 | uLCD.printf("Extra Life!"); |
ajorgih3 | 9:d09b96b6c39c | 515 | |
ajorgih3 | 9:d09b96b6c39c | 516 | draw_life(u, v); |
ajorgih3 | 9:d09b96b6c39c | 517 | |
ajorgih3 | 9:d09b96b6c39c | 518 | uLCD.textbackground_color(BLACK); |
ajorgih3 | 9:d09b96b6c39c | 519 | uLCD.color(0xFFFFFF); |
ajorgih3 | 9:d09b96b6c39c | 520 | uLCD.text_width(1); |
ajorgih3 | 9:d09b96b6c39c | 521 | uLCD.text_height(1); |
ajorgih3 | 9:d09b96b6c39c | 522 | uLCD.locate(4, 10); |
ajorgih3 | 9:d09b96b6c39c | 523 | uLCD.printf("Press 'B2'\n"); |
ajorgih3 | 9:d09b96b6c39c | 524 | uLCD.locate(4, 11); |
ajorgih3 | 9:d09b96b6c39c | 525 | uLCD.printf("to go back!\n"); |
ajorgih3 | 9:d09b96b6c39c | 526 | |
ajorgih3 | 9:d09b96b6c39c | 527 | do { |
ajorgih3 | 9:d09b96b6c39c | 528 | input = read_inputs(); |
ajorgih3 | 9:d09b96b6c39c | 529 | } while(input.b2); |
ajorgih3 | 9:d09b96b6c39c | 530 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 9:d09b96b6c39c | 531 | additional_info(); |
ajorgih3 | 9:d09b96b6c39c | 532 | } |
ajorgih3 | 9:d09b96b6c39c | 533 | |
ajorgih3 | 9:d09b96b6c39c | 534 | |
ajorgih3 | 5:5953ca12205d | 535 | void harmful_items2() { |
ajorgih3 | 6:fbaee888e5ea | 536 | int u = 58; |
ajorgih3 | 5:5953ca12205d | 537 | int v = 56; |
ajorgih3 | 5:5953ca12205d | 538 | |
ajorgih3 | 6:fbaee888e5ea | 539 | uLCD.filled_rectangle(0, 9, 127, 14, 0xD2691E); // Top |
ajorgih3 | 6:fbaee888e5ea | 540 | uLCD.filled_rectangle(0, 13, 2, 114, 0xD2691E); // Left |
ajorgih3 | 6:fbaee888e5ea | 541 | uLCD.filled_rectangle(0, 114, 127, 117, 0xD2691E); // Bottom |
ajorgih3 | 6:fbaee888e5ea | 542 | uLCD.filled_rectangle(124, 14, 127, 117, 0xD2691E); // Right |
ajorgih3 | 5:5953ca12205d | 543 | |
ajorgih3 | 6:fbaee888e5ea | 544 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 545 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 546 | uLCD.locate(2, 3); |
ajorgih3 | 6:fbaee888e5ea | 547 | uLCD.color(0xFFA500); |
ajorgih3 | 6:fbaee888e5ea | 548 | uLCD.printf("HARMFUL ITEMS++"); |
ajorgih3 | 5:5953ca12205d | 549 | |
ajorgih3 | 6:fbaee888e5ea | 550 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 551 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 552 | uLCD.locate(4, 4); |
ajorgih3 | 6:fbaee888e5ea | 553 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 554 | uLCD.printf("SLOWFLAKES"); |
ajorgih3 | 5:5953ca12205d | 555 | |
ajorgih3 | 6:fbaee888e5ea | 556 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 557 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 558 | uLCD.locate(4, 5); |
ajorgih3 | 6:fbaee888e5ea | 559 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 560 | uLCD.printf("LIFETAKER"); |
ajorgih3 | 5:5953ca12205d | 561 | |
ajorgih3 | 6:fbaee888e5ea | 562 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 563 | uLCD.text_height(1); |
ajorgih3 | 6:fbaee888e5ea | 564 | uLCD.locate(4, 6); |
ajorgih3 | 6:fbaee888e5ea | 565 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 566 | uLCD.printf("LIGHTSPEED"); |
ajorgih3 | 5:5953ca12205d | 567 | |
ajorgih3 | 6:fbaee888e5ea | 568 | draw_snowflake(u-22, v+11); |
ajorgih3 | 6:fbaee888e5ea | 569 | draw_sword(u, v+11); |
ajorgih3 | 6:fbaee888e5ea | 570 | draw_lightspeed(u+22, v+11); |
ajorgih3 | 5:5953ca12205d | 571 | |
ajorgih3 | 6:fbaee888e5ea | 572 | uLCD.textbackground_color(BLACK); |
ajorgih3 | 6:fbaee888e5ea | 573 | uLCD.color(0xFFFFFF); |
ajorgih3 | 6:fbaee888e5ea | 574 | uLCD.text_width(1); |
ajorgih3 | 6:fbaee888e5ea | 575 | uLCD.text_height(1); |
ajorgih3 | 9:d09b96b6c39c | 576 | uLCD.locate(4, 11); |
ajorgih3 | 6:fbaee888e5ea | 577 | uLCD.printf("Press 'B2'\n"); |
ajorgih3 | 9:d09b96b6c39c | 578 | uLCD.locate(4, 12); |
ajorgih3 | 6:fbaee888e5ea | 579 | uLCD.printf("to continue!\n"); |
ajorgih3 | 5:5953ca12205d | 580 | |
ajorgih3 | 6:fbaee888e5ea | 581 | do { |
ajorgih3 | 6:fbaee888e5ea | 582 | input = read_inputs(); |
ajorgih3 | 6:fbaee888e5ea | 583 | } while(input.b2); |
ajorgih3 | 6:fbaee888e5ea | 584 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 9:d09b96b6c39c | 585 | helpful_items2(); |
ajorgih3 | 5:5953ca12205d | 586 | } |
ajorgih3 | 5:5953ca12205d | 587 | |
ajorgih3 | 7:7ab2f4b09196 | 588 | void additional_info() { |
ajorgih3 | 9:d09b96b6c39c | 589 | |
ajorgih3 | 9:d09b96b6c39c | 590 | int u = 58; |
ajorgih3 | 9:d09b96b6c39c | 591 | int v = 56; |
ajorgih3 | 9:d09b96b6c39c | 592 | |
ajorgih3 | 9:d09b96b6c39c | 593 | draw_shield(u+22, v+22); |
ajorgih3 | 9:d09b96b6c39c | 594 | draw_blue_potion(u-22, v+22); |
ajorgih3 | 9:d09b96b6c39c | 595 | draw_red_potion(u-22, v+33); |
ajorgih3 | 9:d09b96b6c39c | 596 | draw_reverse(u+22, v+33); |
ajorgih3 | 9:d09b96b6c39c | 597 | |
ajorgih3 | 9:d09b96b6c39c | 598 | uLCD.filled_rectangle(0, 9, 127, 14, RED); // Top |
ajorgih3 | 9:d09b96b6c39c | 599 | uLCD.filled_rectangle(0, 13, 2, 114, GREEN); // Left |
ajorgih3 | 9:d09b96b6c39c | 600 | uLCD.filled_rectangle(0, 114, 127, 117, 0x0000FF); // Bottom |
ajorgih3 | 9:d09b96b6c39c | 601 | uLCD.filled_rectangle(124, 14, 127, 117, 0xFFFF00); // Right |
ajorgih3 | 7:7ab2f4b09196 | 602 | |
ajorgih3 | 7:7ab2f4b09196 | 603 | uLCD.text_width(1); |
ajorgih3 | 7:7ab2f4b09196 | 604 | uLCD.text_height(1); |
ajorgih3 | 7:7ab2f4b09196 | 605 | uLCD.locate(1, 3); |
ajorgih3 | 7:7ab2f4b09196 | 606 | uLCD.color(0xFFFFFF); |
ajorgih3 | 7:7ab2f4b09196 | 607 | uLCD.printf("B1: OTHER ITEMS!"); |
ajorgih3 | 7:7ab2f4b09196 | 608 | |
ajorgih3 | 7:7ab2f4b09196 | 609 | uLCD.text_width(1); |
ajorgih3 | 7:7ab2f4b09196 | 610 | uLCD.text_height(1); |
ajorgih3 | 9:d09b96b6c39c | 611 | uLCD.locate(4, 5); |
ajorgih3 | 7:7ab2f4b09196 | 612 | uLCD.color(0xFFFFFF); |
ajorgih3 | 9:d09b96b6c39c | 613 | uLCD.printf("B2: MAPS!"); |
ajorgih3 | 7:7ab2f4b09196 | 614 | |
ajorgih3 | 9:d09b96b6c39c | 615 | uLCD.text_width(1); |
ajorgih3 | 9:d09b96b6c39c | 616 | uLCD.text_height(1); |
ajorgih3 | 9:d09b96b6c39c | 617 | uLCD.locate(4, 7); |
ajorgih3 | 9:d09b96b6c39c | 618 | uLCD.color(0xFFFFFF); |
ajorgih3 | 9:d09b96b6c39c | 619 | uLCD.printf("B3: START!"); |
ajorgih3 | 7:7ab2f4b09196 | 620 | |
ajorgih3 | 7:7ab2f4b09196 | 621 | do { |
ajorgih3 | 9:d09b96b6c39c | 622 | input = read_inputs(); |
ajorgih3 | 9:d09b96b6c39c | 623 | } while (input.b1 && input.b2 && input.b3); |
ajorgih3 | 7:7ab2f4b09196 | 624 | |
ajorgih3 | 9:d09b96b6c39c | 625 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 9:d09b96b6c39c | 626 | if (!input.b1) { |
ajorgih3 | 9:d09b96b6c39c | 627 | harmful_items2(); |
ajorgih3 | 9:d09b96b6c39c | 628 | } |
ajorgih3 | 9:d09b96b6c39c | 629 | |
ajorgih3 | 7:7ab2f4b09196 | 630 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 9:d09b96b6c39c | 631 | if (!input.b2) { |
ajorgih3 | 9:d09b96b6c39c | 632 | main2(); |
ajorgih3 | 9:d09b96b6c39c | 633 | } |
ajorgih3 | 9:d09b96b6c39c | 634 | |
ajorgih3 | 9:d09b96b6c39c | 635 | if (!input.b3) { |
ajorgih3 | 9:d09b96b6c39c | 636 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 9:d09b96b6c39c | 637 | return; |
ajorgih3 | 9:d09b96b6c39c | 638 | } |
ajorgih3 | 9:d09b96b6c39c | 639 | |
ajorgih3 | 9:d09b96b6c39c | 640 | } |
ajorgih3 | 9:d09b96b6c39c | 641 | |
ajorgih3 | 9:d09b96b6c39c | 642 | void bruh() { |
ajorgih3 | 9:d09b96b6c39c | 643 | return; |
ajorgih3 | 7:7ab2f4b09196 | 644 | } |
ajorgih3 | 7:7ab2f4b09196 | 645 | |
ajorgih3 | 5:5953ca12205d | 646 | |
DCchico | 1:10330bce85cb | 647 | /** |
DCchico | 1:10330bce85cb | 648 | * Initialize the main world map. Add walls around the edges, interior chambers, |
DCchico | 1:10330bce85cb | 649 | * and plants in the background so you can see motion. |
DCchico | 1:10330bce85cb | 650 | */ |
DCchico | 1:10330bce85cb | 651 | void init_main_map() |
ajorgih3 | 3:bb6f73642f01 | 652 | { |
DCchico | 1:10330bce85cb | 653 | // "Random" plants |
ajorgih3 | 6:fbaee888e5ea | 654 | Map* map = set_active_map(0); |
ajorgih3 | 6:fbaee888e5ea | 655 | pc.printf("plants\r\n"); |
ajorgih3 | 9:d09b96b6c39c | 656 | |
ajorgih3 | 9:d09b96b6c39c | 657 | add_portal(7, 5); |
ajorgih3 | 9:d09b96b6c39c | 658 | |
ajorgih3 | 9:d09b96b6c39c | 659 | for (int i = 0; i < 20; i++) { |
ajorgih3 | 9:d09b96b6c39c | 660 | int goodieRandX = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 661 | int goodieRandY = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 662 | add_goodie(goodieRandX, goodieRandY); |
ajorgih3 | 9:d09b96b6c39c | 663 | } |
ajorgih3 | 9:d09b96b6c39c | 664 | |
ajorgih3 | 9:d09b96b6c39c | 665 | for (int i = 0; i < 30; i++) { |
ajorgih3 | 9:d09b96b6c39c | 666 | int goodieRandX = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 667 | int goodieRandY = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 668 | add_goodie(goodieRandX, goodieRandY); |
ajorgih3 | 9:d09b96b6c39c | 669 | } |
ajorgih3 | 7:7ab2f4b09196 | 670 | |
ajorgih3 | 9:d09b96b6c39c | 671 | for (int i = 0; i < 10; i++) { |
ajorgih3 | 9:d09b96b6c39c | 672 | int redRandX = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 673 | int redRandY = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 674 | add_red_potion(redRandX, redRandY); |
ajorgih3 | 9:d09b96b6c39c | 675 | } |
ajorgih3 | 9:d09b96b6c39c | 676 | // |
ajorgih3 | 9:d09b96b6c39c | 677 | for (int i = 0; i < 10; i++) { |
ajorgih3 | 9:d09b96b6c39c | 678 | int swordRandX = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 679 | int swordRandY = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 680 | add_sword(swordRandX, swordRandY); |
ajorgih3 | 9:d09b96b6c39c | 681 | } |
ajorgih3 | 9:d09b96b6c39c | 682 | // |
ajorgih3 | 9:d09b96b6c39c | 683 | for (int i = 0; i < 5; i++) { |
ajorgih3 | 9:d09b96b6c39c | 684 | int lifeRandX = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 685 | int lifeRandY = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 686 | add_life(lifeRandX, lifeRandY); |
ajorgih3 | 9:d09b96b6c39c | 687 | } |
ajorgih3 | 9:d09b96b6c39c | 688 | // |
ajorgih3 | 9:d09b96b6c39c | 689 | for (int i = 0; i < 5; i++) { |
ajorgih3 | 9:d09b96b6c39c | 690 | int blueRandX = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 691 | int blueRandY = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 692 | add_blue_potion(blueRandX, blueRandY); |
ajorgih3 | 9:d09b96b6c39c | 693 | } |
ajorgih3 | 9:d09b96b6c39c | 694 | // |
ajorgih3 | 9:d09b96b6c39c | 695 | for (int i = 0; i < 5; i++) { |
ajorgih3 | 9:d09b96b6c39c | 696 | int shieldRandX = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 697 | int shieldRandY = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 698 | add_shield(shieldRandX, shieldRandY); |
ajorgih3 | 9:d09b96b6c39c | 699 | } |
ajorgih3 | 7:7ab2f4b09196 | 700 | |
ajorgih3 | 9:d09b96b6c39c | 701 | for (int i = 0; i < 10; i++) { |
ajorgih3 | 9:d09b96b6c39c | 702 | int reverseRandX = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 703 | int reverseRandY = rand() % 50; |
ajorgih3 | 9:d09b96b6c39c | 704 | add_reverse(reverseRandX, reverseRandY); |
ajorgih3 | 9:d09b96b6c39c | 705 | } |
ajorgih3 | 7:7ab2f4b09196 | 706 | |
ajorgih3 | 6:fbaee888e5ea | 707 | pc.printf("Adding walls!\r\n"); |
ajorgih3 | 6:fbaee888e5ea | 708 | add_wall(0, 0, HORIZONTAL, map_width()); |
ajorgih3 | 6:fbaee888e5ea | 709 | add_wall(0, map_height()-1, HORIZONTAL, map_width()); |
ajorgih3 | 6:fbaee888e5ea | 710 | add_wall(0, 0, VERTICAL, map_height()); |
ajorgih3 | 6:fbaee888e5ea | 711 | add_wall(map_width()-1, 0, VERTICAL, map_height()); |
ajorgih3 | 6:fbaee888e5ea | 712 | pc.printf("Walls done!\r\n"); |
DCchico | 1:10330bce85cb | 713 | |
ajorgih3 | 6:fbaee888e5ea | 714 | add_snake_head(snake.locations[0].x, snake.locations[0].y); |
ajorgih3 | 6:fbaee888e5ea | 715 | add_snake_body(snake.locations[1].x, snake.locations[1].y); |
ajorgih3 | 6:fbaee888e5ea | 716 | add_snake_tail(snake.locations[2].x, snake.locations[2].y); |
DCchico | 1:10330bce85cb | 717 | |
ajorgih3 | 9:d09b96b6c39c | 718 | // pc.printf("Add extra chamber\r\n"); |
ajorgih3 | 9:d09b96b6c39c | 719 | // add_wall(30, 0, VERTICAL, 10); |
ajorgih3 | 9:d09b96b6c39c | 720 | // add_wall(30, 10, HORIZONTAL, 10); |
ajorgih3 | 9:d09b96b6c39c | 721 | // add_wall(39, 0, VERTICAL, 10); |
ajorgih3 | 9:d09b96b6c39c | 722 | // pc.printf("Added!\r\n"); |
ajorgih3 | 3:bb6f73642f01 | 723 | |
ajorgih3 | 3:bb6f73642f01 | 724 | |
DCchico | 1:10330bce85cb | 725 | |
DCchico | 1:10330bce85cb | 726 | |
DCchico | 1:10330bce85cb | 727 | // Add stairs to chamber (map 1) |
DCchico | 1:10330bce85cb | 728 | //add_stairs(15, 5, 1, 5, 5); |
DCchico | 1:10330bce85cb | 729 | |
DCchico | 1:10330bce85cb | 730 | // profile_hashtable(); |
ajorgih3 | 6:fbaee888e5ea | 731 | print_map(); |
DCchico | 1:10330bce85cb | 732 | } |
DCchico | 1:10330bce85cb | 733 | |
ajorgih3 | 5:5953ca12205d | 734 | void init_map_2() { |
ajorgih3 | 5:5953ca12205d | 735 | |
ajorgih3 | 6:fbaee888e5ea | 736 | Map* map = set_active_map(0); |
ajorgih3 | 5:5953ca12205d | 737 | |
ajorgih3 | 6:fbaee888e5ea | 738 | pc.printf("Adding walls!\r\n"); |
ajorgih3 | 6:fbaee888e5ea | 739 | add_blue_wall(0, 0, HORIZONTAL, map_width()); |
ajorgih3 | 6:fbaee888e5ea | 740 | add_blue_wall(0, map_height()-1, HORIZONTAL, map_width()); |
ajorgih3 | 6:fbaee888e5ea | 741 | add_blue_wall(0, 0, VERTICAL, map_height()); |
ajorgih3 | 6:fbaee888e5ea | 742 | add_blue_wall(map_width()-1, 0, VERTICAL, map_height()); |
ajorgih3 | 9:d09b96b6c39c | 743 | pc.printf("Walls done!\r\n"); |
ajorgih3 | 9:d09b96b6c39c | 744 | print_map(); |
ajorgih3 | 5:5953ca12205d | 745 | |
ajorgih3 | 3:bb6f73642f01 | 746 | } |
ajorgih3 | 3:bb6f73642f01 | 747 | |
ajorgih3 | 5:5953ca12205d | 748 | void go_right2() { |
ajorgih3 | 6:fbaee888e5ea | 749 | add_nothing(snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 750 | // previous coordinate of the snake head which will be used by the body |
ajorgih3 | 6:fbaee888e5ea | 751 | int previousX = snake.head_x; |
ajorgih3 | 6:fbaee888e5ea | 752 | int previousY = snake.head_y; |
ajorgih3 | 5:5953ca12205d | 753 | //int tempPreviousX = previousX; |
ajorgih3 | 5:5953ca12205d | 754 | //int tempPreviousY = previousY; |
ajorgih3 | 6:fbaee888e5ea | 755 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 3:bb6f73642f01 | 756 | |
ajorgih3 | 5:5953ca12205d | 757 | // try this |
ajorgih3 | 6:fbaee888e5ea | 758 | for (int i = 0; i < bodyLength; i++) { |
ajorgih3 | 6:fbaee888e5ea | 759 | pc.printf("Loop Number: %d\n", i); |
ajorgih3 | 3:bb6f73642f01 | 760 | |
ajorgih3 | 6:fbaee888e5ea | 761 | add_snake_body(previousX, previousY); // adds snake body to the head //7, 5 |
ajorgih3 | 6:fbaee888e5ea | 762 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 3:bb6f73642f01 | 763 | |
ajorgih3 | 6:fbaee888e5ea | 764 | snake.body_x = previousX; // updates the coordinates of the snake body with the previous head |
ajorgih3 | 6:fbaee888e5ea | 765 | snake.body_y = previousY; // snake body is now 7, 5 |
ajorgih3 | 4:697e1120f821 | 766 | |
ajorgih3 | 6:fbaee888e5ea | 767 | pc.printf("snake_body_x: %d, snake_body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 768 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].x: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 4:697e1120f821 | 769 | |
ajorgih3 | 6:fbaee888e5ea | 770 | previousX = snake.locations[i].x; // previous location of the body to previousX |
ajorgih3 | 6:fbaee888e5ea | 771 | previousY = snake.locations[i].y; // and previousY //6,5 |
ajorgih3 | 5:5953ca12205d | 772 | |
ajorgih3 | 6:fbaee888e5ea | 773 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 5:5953ca12205d | 774 | |
ajorgih3 | 6:fbaee888e5ea | 775 | snake.locations[i].x = snake.body_x; // updates the snake locations with the new values |
ajorgih3 | 6:fbaee888e5ea | 776 | snake.locations[i].y = snake.body_y; |
ajorgih3 | 4:697e1120f821 | 777 | |
ajorgih3 | 6:fbaee888e5ea | 778 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].x: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 779 | } |
ajorgih3 | 5:5953ca12205d | 780 | |
ajorgih3 | 6:fbaee888e5ea | 781 | snake.tail_x = previousX; |
ajorgih3 | 6:fbaee888e5ea | 782 | snake.tail_y = previousY; |
ajorgih3 | 6:fbaee888e5ea | 783 | add_snake_tail(snake.tail_x, snake.tail_y); |
ajorgih3 | 4:697e1120f821 | 784 | |
ajorgih3 | 5:5953ca12205d | 785 | // update the head |
ajorgih3 | 6:fbaee888e5ea | 786 | snake.head_x = snake.head_x + 1; |
ajorgih3 | 6:fbaee888e5ea | 787 | snake.head_y = snake.head_y + 0; |
ajorgih3 | 6:fbaee888e5ea | 788 | add_snake_head(snake.head_x, snake.head_y); // correct |
ajorgih3 | 6:fbaee888e5ea | 789 | |
ajorgih3 | 6:fbaee888e5ea | 790 | if (speedCounter <= 50 && speedCounter != 0) { |
ajorgih3 | 6:fbaee888e5ea | 791 | speedCounter--; |
ajorgih3 | 6:fbaee888e5ea | 792 | return; |
ajorgih3 | 6:fbaee888e5ea | 793 | } |
ajorgih3 | 7:7ab2f4b09196 | 794 | if (slowflakeCounter <= 20 && slowflakeCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 795 | slowflakeCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 796 | wait(1); |
ajorgih3 | 7:7ab2f4b09196 | 797 | return; |
ajorgih3 | 7:7ab2f4b09196 | 798 | } |
ajorgih3 | 3:bb6f73642f01 | 799 | |
ajorgih3 | 6:fbaee888e5ea | 800 | wait(0.2); |
ajorgih3 | 3:bb6f73642f01 | 801 | } |
ajorgih3 | 3:bb6f73642f01 | 802 | |
ajorgih3 | 5:5953ca12205d | 803 | void go_up2() { |
ajorgih3 | 6:fbaee888e5ea | 804 | add_nothing(snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 805 | // previous coordinate of the snake head which will be used by the body |
ajorgih3 | 6:fbaee888e5ea | 806 | int previousX = snake.head_x; |
ajorgih3 | 6:fbaee888e5ea | 807 | int previousY = snake.head_y; |
ajorgih3 | 5:5953ca12205d | 808 | //int tempPreviousX = previousX; |
ajorgih3 | 5:5953ca12205d | 809 | //int tempPreviousY = previousY; |
ajorgih3 | 6:fbaee888e5ea | 810 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 4:697e1120f821 | 811 | |
ajorgih3 | 5:5953ca12205d | 812 | // try this |
ajorgih3 | 6:fbaee888e5ea | 813 | for (int i = 0; i < bodyLength; i++) { |
ajorgih3 | 6:fbaee888e5ea | 814 | pc.printf("Loop Number: %d\n", i); |
ajorgih3 | 5:5953ca12205d | 815 | |
ajorgih3 | 6:fbaee888e5ea | 816 | add_snake_body(previousX, previousY); // adds snake body to the head //7, 5 |
ajorgih3 | 6:fbaee888e5ea | 817 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 5:5953ca12205d | 818 | |
ajorgih3 | 6:fbaee888e5ea | 819 | snake.body_x = previousX; // updates the coordinates of the snake body with the previous head |
ajorgih3 | 6:fbaee888e5ea | 820 | snake.body_y = previousY; // snake body is now 7, 5 |
ajorgih3 | 5:5953ca12205d | 821 | |
ajorgih3 | 6:fbaee888e5ea | 822 | pc.printf("snake_body_x: %d, snake_body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 823 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].x: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 5:5953ca12205d | 824 | |
ajorgih3 | 6:fbaee888e5ea | 825 | previousX = snake.locations[i].x; // previous location of the body to previousX |
ajorgih3 | 6:fbaee888e5ea | 826 | previousY = snake.locations[i].y; // and previousY //6,5 |
ajorgih3 | 5:5953ca12205d | 827 | |
ajorgih3 | 6:fbaee888e5ea | 828 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 5:5953ca12205d | 829 | |
ajorgih3 | 6:fbaee888e5ea | 830 | snake.locations[i].x = snake.body_x; // updates the snake locations with the new values |
ajorgih3 | 6:fbaee888e5ea | 831 | snake.locations[i].y = snake.body_y; |
ajorgih3 | 5:5953ca12205d | 832 | |
ajorgih3 | 6:fbaee888e5ea | 833 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].x: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 834 | } |
ajorgih3 | 5:5953ca12205d | 835 | |
ajorgih3 | 6:fbaee888e5ea | 836 | snake.tail_x = previousX; |
ajorgih3 | 6:fbaee888e5ea | 837 | snake.tail_y = previousY; |
ajorgih3 | 6:fbaee888e5ea | 838 | add_snake_tail(snake.tail_x, snake.tail_y); |
ajorgih3 | 4:697e1120f821 | 839 | |
ajorgih3 | 5:5953ca12205d | 840 | // update the head |
ajorgih3 | 6:fbaee888e5ea | 841 | snake.head_x = snake.head_x + 0; |
ajorgih3 | 6:fbaee888e5ea | 842 | snake.head_y = snake.head_y - 1; |
ajorgih3 | 6:fbaee888e5ea | 843 | add_snake_head(snake.head_x, snake.head_y); // correct |
ajorgih3 | 6:fbaee888e5ea | 844 | |
ajorgih3 | 6:fbaee888e5ea | 845 | if (speedCounter <= 50 && speedCounter != 0) { |
ajorgih3 | 6:fbaee888e5ea | 846 | speedCounter--; |
ajorgih3 | 6:fbaee888e5ea | 847 | return; |
ajorgih3 | 6:fbaee888e5ea | 848 | } |
ajorgih3 | 7:7ab2f4b09196 | 849 | if (slowflakeCounter <= 20 && slowflakeCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 850 | slowflakeCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 851 | wait(1); |
ajorgih3 | 7:7ab2f4b09196 | 852 | return; |
ajorgih3 | 7:7ab2f4b09196 | 853 | } |
ajorgih3 | 5:5953ca12205d | 854 | |
ajorgih3 | 6:fbaee888e5ea | 855 | wait(0.2); |
ajorgih3 | 4:697e1120f821 | 856 | } |
ajorgih3 | 4:697e1120f821 | 857 | |
ajorgih3 | 5:5953ca12205d | 858 | void go_down2() { |
ajorgih3 | 6:fbaee888e5ea | 859 | add_nothing(snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 860 | // previous coordinate of the snake head which will be used by the body |
ajorgih3 | 6:fbaee888e5ea | 861 | int previousX = snake.head_x; |
ajorgih3 | 6:fbaee888e5ea | 862 | int previousY = snake.head_y; |
ajorgih3 | 5:5953ca12205d | 863 | //int tempPreviousX = previousX; |
ajorgih3 | 5:5953ca12205d | 864 | //int tempPreviousY = previousY; |
ajorgih3 | 6:fbaee888e5ea | 865 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 4:697e1120f821 | 866 | |
ajorgih3 | 5:5953ca12205d | 867 | // try this |
ajorgih3 | 6:fbaee888e5ea | 868 | for (int i = 0; i < bodyLength; i++) { |
ajorgih3 | 6:fbaee888e5ea | 869 | pc.printf("Loop Number: %d\n", i); |
ajorgih3 | 5:5953ca12205d | 870 | |
ajorgih3 | 6:fbaee888e5ea | 871 | add_snake_body(previousX, previousY); // adds snake body to the head //7, 5 |
ajorgih3 | 6:fbaee888e5ea | 872 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 5:5953ca12205d | 873 | |
ajorgih3 | 6:fbaee888e5ea | 874 | snake.body_x = previousX; // updates the coordinates of the snake body with the previous head |
ajorgih3 | 6:fbaee888e5ea | 875 | snake.body_y = previousY; // snake body is now 7, 5 |
ajorgih3 | 5:5953ca12205d | 876 | |
ajorgih3 | 6:fbaee888e5ea | 877 | pc.printf("snake_body_x: %d, snake_body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 878 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].x: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 5:5953ca12205d | 879 | |
ajorgih3 | 6:fbaee888e5ea | 880 | previousX = snake.locations[i].x; // previous location of the body to previousX |
ajorgih3 | 6:fbaee888e5ea | 881 | previousY = snake.locations[i].y; // and previousY //6,5 |
ajorgih3 | 4:697e1120f821 | 882 | |
ajorgih3 | 6:fbaee888e5ea | 883 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 5:5953ca12205d | 884 | |
ajorgih3 | 6:fbaee888e5ea | 885 | snake.locations[i].x = snake.body_x; // updates the snake locations with the new values |
ajorgih3 | 6:fbaee888e5ea | 886 | snake.locations[i].y = snake.body_y; |
ajorgih3 | 5:5953ca12205d | 887 | |
ajorgih3 | 6:fbaee888e5ea | 888 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].x: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 889 | } |
ajorgih3 | 5:5953ca12205d | 890 | |
ajorgih3 | 6:fbaee888e5ea | 891 | snake.tail_x = previousX; |
ajorgih3 | 6:fbaee888e5ea | 892 | snake.tail_y = previousY; |
ajorgih3 | 6:fbaee888e5ea | 893 | add_snake_tail(snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 894 | |
ajorgih3 | 5:5953ca12205d | 895 | // update the head |
ajorgih3 | 6:fbaee888e5ea | 896 | snake.head_x = snake.head_x + 0; |
ajorgih3 | 6:fbaee888e5ea | 897 | snake.head_y = snake.head_y + 1; |
ajorgih3 | 6:fbaee888e5ea | 898 | add_snake_head(snake.head_x, snake.head_y); // correct |
ajorgih3 | 6:fbaee888e5ea | 899 | |
ajorgih3 | 6:fbaee888e5ea | 900 | if (speedCounter <= 50 && speedCounter != 0) { |
ajorgih3 | 6:fbaee888e5ea | 901 | speedCounter--; |
ajorgih3 | 6:fbaee888e5ea | 902 | return; |
ajorgih3 | 6:fbaee888e5ea | 903 | } |
ajorgih3 | 7:7ab2f4b09196 | 904 | |
ajorgih3 | 7:7ab2f4b09196 | 905 | if (slowflakeCounter <= 20 && slowflakeCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 906 | slowflakeCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 907 | wait(1); |
ajorgih3 | 7:7ab2f4b09196 | 908 | return; |
ajorgih3 | 7:7ab2f4b09196 | 909 | } |
ajorgih3 | 5:5953ca12205d | 910 | |
ajorgih3 | 6:fbaee888e5ea | 911 | wait(0.2); |
ajorgih3 | 4:697e1120f821 | 912 | } |
ajorgih3 | 4:697e1120f821 | 913 | |
ajorgih3 | 5:5953ca12205d | 914 | void go_left2() { |
ajorgih3 | 7:7ab2f4b09196 | 915 | |
ajorgih3 | 8:34fd253d0fa5 | 916 | if (!(get_here(snake.head_x - 1, snake.head_y)->walkable)) { |
ajorgih3 | 8:34fd253d0fa5 | 917 | pc.printf("SUCCESS!\n\n"); |
ajorgih3 | 7:7ab2f4b09196 | 918 | return; |
ajorgih3 | 7:7ab2f4b09196 | 919 | } |
ajorgih3 | 7:7ab2f4b09196 | 920 | |
ajorgih3 | 6:fbaee888e5ea | 921 | add_nothing(snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 922 | // previous coordinate of the snake head which will be used by the body |
ajorgih3 | 6:fbaee888e5ea | 923 | int previousX = snake.head_x; |
ajorgih3 | 6:fbaee888e5ea | 924 | int previousY = snake.head_y; |
ajorgih3 | 5:5953ca12205d | 925 | //int tempPreviousX = previousX; |
ajorgih3 | 5:5953ca12205d | 926 | //int tempPreviousY = previousY; |
ajorgih3 | 6:fbaee888e5ea | 927 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 4:697e1120f821 | 928 | |
ajorgih3 | 5:5953ca12205d | 929 | // try this |
ajorgih3 | 6:fbaee888e5ea | 930 | for (int i = 0; i < bodyLength; i++) { |
ajorgih3 | 6:fbaee888e5ea | 931 | pc.printf("Loop Number: %d\n", i); |
ajorgih3 | 5:5953ca12205d | 932 | |
ajorgih3 | 6:fbaee888e5ea | 933 | add_snake_body(previousX, previousY); // adds snake body to the head //7, 5 |
ajorgih3 | 6:fbaee888e5ea | 934 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 5:5953ca12205d | 935 | |
ajorgih3 | 6:fbaee888e5ea | 936 | snake.body_x = previousX; // updates the coordinates of the snake body with the previous head |
ajorgih3 | 6:fbaee888e5ea | 937 | snake.body_y = previousY; // snake body is now 7, 5 |
ajorgih3 | 5:5953ca12205d | 938 | |
ajorgih3 | 6:fbaee888e5ea | 939 | pc.printf("snake_body_x: %d, snake_body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 940 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].x: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 5:5953ca12205d | 941 | |
ajorgih3 | 6:fbaee888e5ea | 942 | previousX = snake.locations[i].x; // previous location of the body to previousX |
ajorgih3 | 6:fbaee888e5ea | 943 | previousY = snake.locations[i].y; // and previousY //6,5 |
ajorgih3 | 5:5953ca12205d | 944 | |
ajorgih3 | 6:fbaee888e5ea | 945 | pc.printf("previousX: %d, previousY: %d\n", previousX, previousY); |
ajorgih3 | 5:5953ca12205d | 946 | |
ajorgih3 | 6:fbaee888e5ea | 947 | snake.locations[i].x = snake.body_x; // updates the snake locations with the new values |
ajorgih3 | 6:fbaee888e5ea | 948 | snake.locations[i].y = snake.body_y; |
ajorgih3 | 5:5953ca12205d | 949 | |
ajorgih3 | 6:fbaee888e5ea | 950 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].x: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 951 | } |
ajorgih3 | 5:5953ca12205d | 952 | |
ajorgih3 | 6:fbaee888e5ea | 953 | snake.tail_x = previousX; |
ajorgih3 | 6:fbaee888e5ea | 954 | snake.tail_y = previousY; |
ajorgih3 | 6:fbaee888e5ea | 955 | add_snake_tail(snake.tail_x, snake.tail_y); |
ajorgih3 | 4:697e1120f821 | 956 | |
ajorgih3 | 5:5953ca12205d | 957 | // update the head |
ajorgih3 | 6:fbaee888e5ea | 958 | snake.head_x = snake.head_x - 1; |
ajorgih3 | 6:fbaee888e5ea | 959 | snake.head_y = snake.head_y + 0; |
ajorgih3 | 6:fbaee888e5ea | 960 | add_snake_head(snake.head_x, snake.head_y); // correct |
ajorgih3 | 6:fbaee888e5ea | 961 | |
ajorgih3 | 6:fbaee888e5ea | 962 | if (speedCounter <= 50 && speedCounter != 0) { |
ajorgih3 | 6:fbaee888e5ea | 963 | speedCounter--; |
ajorgih3 | 6:fbaee888e5ea | 964 | return; |
ajorgih3 | 6:fbaee888e5ea | 965 | } |
ajorgih3 | 7:7ab2f4b09196 | 966 | |
ajorgih3 | 7:7ab2f4b09196 | 967 | if (slowflakeCounter <= 20 && slowflakeCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 968 | slowflakeCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 969 | wait(1); |
ajorgih3 | 7:7ab2f4b09196 | 970 | return; |
ajorgih3 | 7:7ab2f4b09196 | 971 | } |
ajorgih3 | 4:697e1120f821 | 972 | |
ajorgih3 | 6:fbaee888e5ea | 973 | wait(0.2); |
ajorgih3 | 4:697e1120f821 | 974 | |
ajorgih3 | 3:bb6f73642f01 | 975 | } |
ajorgih3 | 3:bb6f73642f01 | 976 | |
ajorgih3 | 3:bb6f73642f01 | 977 | |
ajorgih3 | 3:bb6f73642f01 | 978 | int update_game(int action) |
ajorgih3 | 3:bb6f73642f01 | 979 | { |
ajorgih3 | 6:fbaee888e5ea | 980 | snake.head_px = snake.head_x; |
ajorgih3 | 6:fbaee888e5ea | 981 | snake.body_px = snake.body_x; |
ajorgih3 | 6:fbaee888e5ea | 982 | snake.tail_px = snake.tail_x; |
ajorgih3 | 6:fbaee888e5ea | 983 | snake.head_py = snake.head_y; |
ajorgih3 | 6:fbaee888e5ea | 984 | snake.body_py = snake.body_y; |
ajorgih3 | 6:fbaee888e5ea | 985 | snake.tail_py = snake.tail_y; |
ajorgih3 | 5:5953ca12205d | 986 | |
ajorgih3 | 5:5953ca12205d | 987 | //snake.locations[0].x = snake.body_x; |
ajorgih3 | 5:5953ca12205d | 988 | //snake.locations[0].y = snake.body_y; |
ajorgih3 | 3:bb6f73642f01 | 989 | |
ajorgih3 | 7:7ab2f4b09196 | 990 | if (score == 20) { |
ajorgih3 | 7:7ab2f4b09196 | 991 | draw_game(WIN_GAME); |
ajorgih3 | 7:7ab2f4b09196 | 992 | } |
ajorgih3 | 7:7ab2f4b09196 | 993 | |
ajorgih3 | 8:34fd253d0fa5 | 994 | uLCD.filled_rectangle(0, 9, 127, 14, 0xFFFFFF); // Top |
ajorgih3 | 8:34fd253d0fa5 | 995 | uLCD.filled_rectangle(0, 13, 2, 114, 0xFFFFFF); // Left |
ajorgih3 | 8:34fd253d0fa5 | 996 | uLCD.filled_rectangle(0, 114, 127, 117, 0xFFFFFF); // Bottom |
ajorgih3 | 8:34fd253d0fa5 | 997 | uLCD.filled_rectangle(124, 14, 127, 117, 0xFFFFFF); // Right |
ajorgih3 | 8:34fd253d0fa5 | 998 | draw_nothing(102, 100); |
ajorgih3 | 9:d09b96b6c39c | 999 | |
ajorgih3 | 7:7ab2f4b09196 | 1000 | |
ajorgih3 | 7:7ab2f4b09196 | 1001 | //pc.printf("Shield Counter: %d\n", shieldCounter); |
ajorgih3 | 6:fbaee888e5ea | 1002 | switch(action) { |
ajorgih3 | 3:bb6f73642f01 | 1003 | |
ajorgih3 | 6:fbaee888e5ea | 1004 | case GO_RIGHT: |
ajorgih3 | 6:fbaee888e5ea | 1005 | nextHead = get_east(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1006 | pc.printf("GO RIGHT\n"); |
ajorgih3 | 9:d09b96b6c39c | 1007 | if (nextHead->walkable && nextHead->type != LIFE && nextHead->type != GOODIE && nextHead->type != SWORD && nextHead->type != REVERSE && nextHead->type != LIGHTSPEED && nextHead->type != SHIELD && nextHead->type != SNOWFLAKE && nextHead->type != BLUEPOTION && nextHead->type !=REDPOTION && nextHead->type != BLUEPOTION && nextHead->type != PORTAL) { |
ajorgih3 | 6:fbaee888e5ea | 1008 | pc.printf("Before:\n"); |
ajorgih3 | 6:fbaee888e5ea | 1009 | pc.printf("head_x: %d, head_y: %d\n", snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1010 | pc.printf("body_x: %d, body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1011 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1012 | pc.printf("reverseCounter: %d\n\n", reverseCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1013 | pc.printf("speedCounter: %d\n\n", speedCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1014 | pc.printf("shieldCounter: %d\n\n", shieldCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1015 | pc.printf("slowflakeCounter: %d", slowflakeCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1016 | pc.printf("blueCounter: %d\n", blueCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1017 | pc.printf("redCounter: %d", redCounter); |
ajorgih3 | 6:fbaee888e5ea | 1018 | if (reverseCounter == 0) { |
ajorgih3 | 8:34fd253d0fa5 | 1019 | go_right2(); |
ajorgih3 | 8:34fd253d0fa5 | 1020 | draw_arrow_right(113, 100); |
ajorgih3 | 6:fbaee888e5ea | 1021 | } |
ajorgih3 | 6:fbaee888e5ea | 1022 | if (reverseCounter <= 20 && reverseCounter != 0) { |
ajorgih3 | 6:fbaee888e5ea | 1023 | go_left2(); |
ajorgih3 | 8:34fd253d0fa5 | 1024 | draw_arrow_left(113, 100); |
ajorgih3 | 7:7ab2f4b09196 | 1025 | pc.printf("reverseCounter: %d", reverseCounter); |
ajorgih3 | 6:fbaee888e5ea | 1026 | reverseCounter--; |
ajorgih3 | 6:fbaee888e5ea | 1027 | } |
ajorgih3 | 5:5953ca12205d | 1028 | //draw_snake_head(snake.head_pi, snake.head_pj); |
ajorgih3 | 5:5953ca12205d | 1029 | //draw_snake_body(snake.body_pi, snake.body_pj); |
ajorgih3 | 5:5953ca12205d | 1030 | //draw_snake_tail(snake.tail_pi, snake.tail_pj); |
ajorgih3 | 6:fbaee888e5ea | 1031 | updateY(); |
ajorgih3 | 6:fbaee888e5ea | 1032 | pc.printf("After:\n"); |
ajorgih3 | 6:fbaee888e5ea | 1033 | pc.printf("head_x: %d, head_y: %d\n", snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1034 | pc.printf("body_x: %d, body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1035 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1036 | if (shieldCounter <= 15 && shieldCounter != 0) { |
ajorgih3 | 6:fbaee888e5ea | 1037 | shieldCounter--; |
ajorgih3 | 6:fbaee888e5ea | 1038 | } |
ajorgih3 | 7:7ab2f4b09196 | 1039 | if (blueCounter <= 20 && blueCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1040 | blueCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 1041 | } |
ajorgih3 | 7:7ab2f4b09196 | 1042 | if (redCounter <= 20 && redCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1043 | redCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 1044 | } |
ajorgih3 | 6:fbaee888e5ea | 1045 | } |
ajorgih3 | 4:697e1120f821 | 1046 | |
ajorgih3 | 6:fbaee888e5ea | 1047 | if (!nextHead->walkable && invincibility == false) { |
ajorgih3 | 6:fbaee888e5ea | 1048 | if (shieldCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1049 | if (lives == 0) { |
ajorgih3 | 6:fbaee888e5ea | 1050 | draw_game(GAME_OVER); |
ajorgih3 | 4:697e1120f821 | 1051 | } |
ajorgih3 | 4:697e1120f821 | 1052 | else { |
ajorgih3 | 6:fbaee888e5ea | 1053 | lives--; |
ajorgih3 | 6:fbaee888e5ea | 1054 | } |
ajorgih3 | 4:697e1120f821 | 1055 | } |
ajorgih3 | 6:fbaee888e5ea | 1056 | } |
ajorgih3 | 6:fbaee888e5ea | 1057 | |
ajorgih3 | 6:fbaee888e5ea | 1058 | if (nextHead->type == LIFE) { |
ajorgih3 | 5:5953ca12205d | 1059 | lives += 1; |
ajorgih3 | 5:5953ca12205d | 1060 | add_nothing(snake.head_x + 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1061 | } |
ajorgih3 | 4:697e1120f821 | 1062 | |
ajorgih3 | 6:fbaee888e5ea | 1063 | if (nextHead->type == GOODIE) { |
ajorgih3 | 7:7ab2f4b09196 | 1064 | if (redCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1065 | score++; |
ajorgih3 | 7:7ab2f4b09196 | 1066 | } |
ajorgih3 | 7:7ab2f4b09196 | 1067 | |
ajorgih3 | 4:697e1120f821 | 1068 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 5:5953ca12205d | 1069 | add_nothing(snake.head_x + 1, snake.head_y); |
ajorgih3 | 5:5953ca12205d | 1070 | |
ajorgih3 | 7:7ab2f4b09196 | 1071 | if (blueCounter == 0) { |
ajorgih3 | 5:5953ca12205d | 1072 | // if the snake is straight right |
ajorgih3 | 5:5953ca12205d | 1073 | if ((snake.body_x - 1) == (snake.tail_x)) { |
ajorgih3 | 6:fbaee888e5ea | 1074 | add_snake_body(snake.body_x - 1, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1075 | add_snake_tail(snake.tail_x - 1, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1076 | } |
ajorgih3 | 5:5953ca12205d | 1077 | |
ajorgih3 | 5:5953ca12205d | 1078 | // if the snake's tail is on top of the body |
ajorgih3 | 5:5953ca12205d | 1079 | if ((snake.body_y - 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1080 | add_snake_body(snake.body_x, snake.body_y - 1); |
ajorgih3 | 6:fbaee888e5ea | 1081 | add_snake_tail(snake.tail_x, snake.tail_y - 1); |
ajorgih3 | 5:5953ca12205d | 1082 | } |
ajorgih3 | 5:5953ca12205d | 1083 | |
ajorgih3 | 5:5953ca12205d | 1084 | // if the snake's tail is below the body |
ajorgih3 | 5:5953ca12205d | 1085 | if ((snake.body_y + 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1086 | add_snake_body(snake.body_x, snake.body_y + 1); |
ajorgih3 | 6:fbaee888e5ea | 1087 | add_snake_tail(snake.tail_x, snake.tail_y + 1); |
ajorgih3 | 5:5953ca12205d | 1088 | } |
ajorgih3 | 5:5953ca12205d | 1089 | |
ajorgih3 | 5:5953ca12205d | 1090 | // this places a new body coordinate before the main body, this is go right function |
ajorgih3 | 5:5953ca12205d | 1091 | for (int i = 0; i < SNAKE_MAX_LENGTH; i++) { |
ajorgih3 | 6:fbaee888e5ea | 1092 | if (snake.locations[i].x == 0 && snake.locations[i].y == 0) { |
ajorgih3 | 5:5953ca12205d | 1093 | |
ajorgih3 | 5:5953ca12205d | 1094 | // assuming that the snake is all the way to the right |
ajorgih3 | 6:fbaee888e5ea | 1095 | if ((snake.body_x - 1) == snake.tail_x) { |
ajorgih3 | 6:fbaee888e5ea | 1096 | snake.locations[i].x = snake.body_x - 1; |
ajorgih3 | 6:fbaee888e5ea | 1097 | snake.locations[i].y = snake.body_y; |
ajorgih3 | 6:fbaee888e5ea | 1098 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1099 | bodyLength++; |
ajorgih3 | 6:fbaee888e5ea | 1100 | pc.printf("body length: %d\n", bodyLength); |
ajorgih3 | 6:fbaee888e5ea | 1101 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1102 | snake.tail_x = snake.tail_x - 1; |
ajorgih3 | 6:fbaee888e5ea | 1103 | snake.tail_y = snake.tail_y; |
ajorgih3 | 6:fbaee888e5ea | 1104 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1105 | } |
ajorgih3 | 5:5953ca12205d | 1106 | |
ajorgih3 | 5:5953ca12205d | 1107 | // tail is over the body |
ajorgih3 | 6:fbaee888e5ea | 1108 | if ((snake.body_y - 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1109 | snake.locations[i].x = snake.body_x; |
ajorgih3 | 6:fbaee888e5ea | 1110 | snake.locations[i].y = snake.body_y - 1; |
ajorgih3 | 6:fbaee888e5ea | 1111 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1112 | bodyLength++; |
ajorgih3 | 6:fbaee888e5ea | 1113 | pc.printf("body length: %d\n", bodyLength); |
ajorgih3 | 6:fbaee888e5ea | 1114 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1115 | snake.tail_x = snake.tail_x; |
ajorgih3 | 6:fbaee888e5ea | 1116 | snake.tail_y = snake.tail_y - 1; |
ajorgih3 | 6:fbaee888e5ea | 1117 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1118 | } |
ajorgih3 | 5:5953ca12205d | 1119 | |
ajorgih3 | 5:5953ca12205d | 1120 | //assuming that the body is on top of the tail |
ajorgih3 | 6:fbaee888e5ea | 1121 | if ((snake.body_y + 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1122 | snake.locations[i].x = snake.body_x; |
ajorgih3 | 6:fbaee888e5ea | 1123 | snake.locations[i].y = snake.body_y + 1; |
ajorgih3 | 6:fbaee888e5ea | 1124 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1125 | bodyLength++; |
ajorgih3 | 6:fbaee888e5ea | 1126 | pc.printf("body length: %d\n", bodyLength); |
ajorgih3 | 6:fbaee888e5ea | 1127 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1128 | snake.tail_x = snake.tail_x; |
ajorgih3 | 6:fbaee888e5ea | 1129 | snake.tail_y = snake.tail_y + 1; |
ajorgih3 | 6:fbaee888e5ea | 1130 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1131 | } |
ajorgih3 | 5:5953ca12205d | 1132 | |
ajorgih3 | 6:fbaee888e5ea | 1133 | break; |
ajorgih3 | 6:fbaee888e5ea | 1134 | } |
ajorgih3 | 6:fbaee888e5ea | 1135 | pc.printf("i: %d\n", i); |
ajorgih3 | 5:5953ca12205d | 1136 | } |
ajorgih3 | 6:fbaee888e5ea | 1137 | } |
ajorgih3 | 7:7ab2f4b09196 | 1138 | } |
ajorgih3 | 4:697e1120f821 | 1139 | |
ajorgih3 | 6:fbaee888e5ea | 1140 | if (nextHead->type == SNOWFLAKE) { |
ajorgih3 | 7:7ab2f4b09196 | 1141 | slowflakeCounter = 20; |
ajorgih3 | 4:697e1120f821 | 1142 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1143 | add_nothing(snake.head_x + 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1144 | } |
ajorgih3 | 4:697e1120f821 | 1145 | |
ajorgih3 | 6:fbaee888e5ea | 1146 | if (nextHead->type == SWORD) { |
ajorgih3 | 7:7ab2f4b09196 | 1147 | if (lives == 0 && shieldCounter == 0) { |
ajorgih3 | 6:fbaee888e5ea | 1148 | draw_game(GAME_OVER); |
ajorgih3 | 4:697e1120f821 | 1149 | } |
ajorgih3 | 4:697e1120f821 | 1150 | else { |
ajorgih3 | 7:7ab2f4b09196 | 1151 | if (shieldCounter == 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1152 | lives--; |
ajorgih3 | 7:7ab2f4b09196 | 1153 | } |
ajorgih3 | 4:697e1120f821 | 1154 | } |
ajorgih3 | 4:697e1120f821 | 1155 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1156 | add_nothing(snake.head_x + 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1157 | } |
ajorgih3 | 6:fbaee888e5ea | 1158 | |
ajorgih3 | 6:fbaee888e5ea | 1159 | if (nextHead->type == REVERSE) { |
ajorgih3 | 6:fbaee888e5ea | 1160 | reverseCounter = 20; |
ajorgih3 | 4:697e1120f821 | 1161 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1162 | add_nothing(snake.head_x + 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1163 | } |
ajorgih3 | 6:fbaee888e5ea | 1164 | |
ajorgih3 | 6:fbaee888e5ea | 1165 | if (nextHead->type == LIGHTSPEED) { |
ajorgih3 | 6:fbaee888e5ea | 1166 | speedCounter = 50; |
ajorgih3 | 4:697e1120f821 | 1167 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1168 | add_nothing(snake.head_x + 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1169 | } |
ajorgih3 | 6:fbaee888e5ea | 1170 | |
ajorgih3 | 6:fbaee888e5ea | 1171 | if (nextHead->type == SHIELD) { |
ajorgih3 | 6:fbaee888e5ea | 1172 | shieldCounter = 15; |
ajorgih3 | 6:fbaee888e5ea | 1173 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1174 | add_nothing(snake.head_x + 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1175 | } |
ajorgih3 | 7:7ab2f4b09196 | 1176 | |
ajorgih3 | 7:7ab2f4b09196 | 1177 | if (nextHead->type == REDPOTION) { |
ajorgih3 | 7:7ab2f4b09196 | 1178 | redCounter = 20; |
ajorgih3 | 7:7ab2f4b09196 | 1179 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1180 | add_nothing(snake.head_x + 1, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1181 | } |
ajorgih3 | 7:7ab2f4b09196 | 1182 | |
ajorgih3 | 7:7ab2f4b09196 | 1183 | if (nextHead->type == BLUEPOTION) { |
ajorgih3 | 7:7ab2f4b09196 | 1184 | blueCounter = 20; |
ajorgih3 | 7:7ab2f4b09196 | 1185 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1186 | add_nothing(snake.head_x + 1, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1187 | } |
ajorgih3 | 7:7ab2f4b09196 | 1188 | |
ajorgih3 | 9:d09b96b6c39c | 1189 | if (nextHead->type == PORTAL) { |
ajorgih3 | 9:d09b96b6c39c | 1190 | main2(); |
ajorgih3 | 9:d09b96b6c39c | 1191 | } |
ajorgih3 | 9:d09b96b6c39c | 1192 | |
ajorgih3 | 6:fbaee888e5ea | 1193 | break; |
ajorgih3 | 4:697e1120f821 | 1194 | |
ajorgih3 | 6:fbaee888e5ea | 1195 | case GO_LEFT: |
ajorgih3 | 6:fbaee888e5ea | 1196 | nextHead = get_west(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1197 | pc.printf("GO LEFT\n"); |
ajorgih3 | 7:7ab2f4b09196 | 1198 | if (nextHead->walkable && nextHead->type != LIFE && nextHead->type != GOODIE && nextHead->type != SWORD && nextHead->type != REVERSE && nextHead->type != LIGHTSPEED && nextHead->type != SHIELD && nextHead->type != SNOWFLAKE && nextHead->type != BLUEPOTION && nextHead->type != REDPOTION) { |
ajorgih3 | 6:fbaee888e5ea | 1199 | pc.printf("Before:\n"); |
ajorgih3 | 6:fbaee888e5ea | 1200 | pc.printf("head_x: %d, head_y: %d\n", snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1201 | pc.printf("body_x: %d, body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1202 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 7:7ab2f4b09196 | 1203 | pc.printf("reverseCounter: %d\n\n", reverseCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1204 | pc.printf("speedCounter: %d\n\n", speedCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1205 | pc.printf("shieldCounter: %d\n\n", shieldCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1206 | pc.printf("slowflakeCounter: %d", slowflakeCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1207 | pc.printf("blueCounter: %d", blueCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1208 | pc.printf("redCounter: %d", redCounter); |
ajorgih3 | 9:d09b96b6c39c | 1209 | if (reverseCounter == 0 && nextHead->walkable) { |
ajorgih3 | 6:fbaee888e5ea | 1210 | go_left2(); |
ajorgih3 | 8:34fd253d0fa5 | 1211 | draw_arrow_left(113, 100); |
ajorgih3 | 6:fbaee888e5ea | 1212 | } |
ajorgih3 | 6:fbaee888e5ea | 1213 | if (reverseCounter <= 20 && reverseCounter != 0) { |
ajorgih3 | 8:34fd253d0fa5 | 1214 | go_right2(); |
ajorgih3 | 8:34fd253d0fa5 | 1215 | draw_arrow_right(113, 100); |
ajorgih3 | 7:7ab2f4b09196 | 1216 | pc.printf("reverseCounter: %d", reverseCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1217 | reverseCounter--; |
ajorgih3 | 6:fbaee888e5ea | 1218 | } |
ajorgih3 | 5:5953ca12205d | 1219 | //draw_snake_head(snake.head_pi, snake.head_pj); |
ajorgih3 | 5:5953ca12205d | 1220 | //draw_snake_body(snake.body_pi, snake.body_pj); |
ajorgih3 | 5:5953ca12205d | 1221 | //draw_snake_tail(snake.tail_pi, snake.tail_pj); |
ajorgih3 | 6:fbaee888e5ea | 1222 | updateY(); |
ajorgih3 | 6:fbaee888e5ea | 1223 | pc.printf("After:\n"); |
ajorgih3 | 6:fbaee888e5ea | 1224 | pc.printf("head_x: %d, head_y: %d\n", snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1225 | pc.printf("body_x: %d, body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1226 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1227 | if (shieldCounter <= 15 && shieldCounter != 0) { |
ajorgih3 | 6:fbaee888e5ea | 1228 | shieldCounter--; |
ajorgih3 | 6:fbaee888e5ea | 1229 | } |
ajorgih3 | 7:7ab2f4b09196 | 1230 | if (blueCounter <= 20 && blueCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1231 | blueCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 1232 | } |
ajorgih3 | 7:7ab2f4b09196 | 1233 | if (redCounter <= 20 && redCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1234 | redCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 1235 | } |
ajorgih3 | 6:fbaee888e5ea | 1236 | } |
ajorgih3 | 4:697e1120f821 | 1237 | |
ajorgih3 | 6:fbaee888e5ea | 1238 | if (!nextHead->walkable && invincibility == false) { |
ajorgih3 | 6:fbaee888e5ea | 1239 | if (shieldCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1240 | if (lives == 0) { |
ajorgih3 | 6:fbaee888e5ea | 1241 | draw_game(GAME_OVER); |
ajorgih3 | 4:697e1120f821 | 1242 | } |
ajorgih3 | 4:697e1120f821 | 1243 | else { |
ajorgih3 | 6:fbaee888e5ea | 1244 | lives--; |
ajorgih3 | 6:fbaee888e5ea | 1245 | } |
ajorgih3 | 4:697e1120f821 | 1246 | } |
ajorgih3 | 6:fbaee888e5ea | 1247 | } |
ajorgih3 | 6:fbaee888e5ea | 1248 | |
ajorgih3 | 6:fbaee888e5ea | 1249 | if (nextHead->type == LIFE) { |
ajorgih3 | 4:697e1120f821 | 1250 | lives++; |
ajorgih3 | 4:697e1120f821 | 1251 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1252 | add_nothing(snake.head_x-1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1253 | } |
ajorgih3 | 4:697e1120f821 | 1254 | |
ajorgih3 | 6:fbaee888e5ea | 1255 | if (nextHead->type == GOODIE) { |
ajorgih3 | 7:7ab2f4b09196 | 1256 | if (redCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1257 | score++; |
ajorgih3 | 7:7ab2f4b09196 | 1258 | } |
ajorgih3 | 7:7ab2f4b09196 | 1259 | |
ajorgih3 | 4:697e1120f821 | 1260 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1261 | add_nothing(snake.head_x - 1, snake.head_y); // eat the goodie |
ajorgih3 | 5:5953ca12205d | 1262 | |
ajorgih3 | 7:7ab2f4b09196 | 1263 | if (blueCounter == 0) { |
ajorgih3 | 5:5953ca12205d | 1264 | if ((snake.body_x + 1) == (snake.tail_x)) { |
ajorgih3 | 6:fbaee888e5ea | 1265 | add_nothing(snake.head_x - 1, snake.head_y); // eat the goodie |
ajorgih3 | 6:fbaee888e5ea | 1266 | add_snake_body(snake.body_x + 1, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1267 | add_snake_tail(snake.tail_x + 1, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1268 | } |
ajorgih3 | 5:5953ca12205d | 1269 | |
ajorgih3 | 5:5953ca12205d | 1270 | if ((snake.body_y - 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1271 | add_nothing(snake.head_x - 1, snake.head_y); // eat the goodie |
ajorgih3 | 6:fbaee888e5ea | 1272 | add_snake_body(snake.body_x, snake.body_y - 1); |
ajorgih3 | 6:fbaee888e5ea | 1273 | add_snake_tail(snake.tail_x, snake.tail_y - 1); |
ajorgih3 | 5:5953ca12205d | 1274 | } |
ajorgih3 | 5:5953ca12205d | 1275 | |
ajorgih3 | 5:5953ca12205d | 1276 | if ((snake.body_y + 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1277 | add_nothing(snake.head_x - 1, snake.head_y); // eat the goodie |
ajorgih3 | 6:fbaee888e5ea | 1278 | add_snake_body(snake.body_x, snake.body_y + 1); |
ajorgih3 | 6:fbaee888e5ea | 1279 | add_snake_tail(snake.tail_x, snake.tail_y + 1); |
ajorgih3 | 5:5953ca12205d | 1280 | } |
ajorgih3 | 5:5953ca12205d | 1281 | |
ajorgih3 | 5:5953ca12205d | 1282 | // this places a new body coordinate before the main body, this is go right function |
ajorgih3 | 5:5953ca12205d | 1283 | for (int i = 0; i < SNAKE_MAX_LENGTH; i++) { |
ajorgih3 | 6:fbaee888e5ea | 1284 | if (snake.locations[i].x == 0 && snake.locations[i].y == 0) { |
ajorgih3 | 5:5953ca12205d | 1285 | |
ajorgih3 | 6:fbaee888e5ea | 1286 | if ((snake.body_x + 1) == snake.tail_x) { |
ajorgih3 | 6:fbaee888e5ea | 1287 | snake.locations[i].x = snake.body_x + 1; |
ajorgih3 | 6:fbaee888e5ea | 1288 | snake.locations[i].y = snake.body_y; |
ajorgih3 | 6:fbaee888e5ea | 1289 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1290 | bodyLength++; |
ajorgih3 | 6:fbaee888e5ea | 1291 | pc.printf("body length: %d\n", bodyLength); |
ajorgih3 | 6:fbaee888e5ea | 1292 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1293 | snake.tail_x = snake.tail_x + 1; |
ajorgih3 | 6:fbaee888e5ea | 1294 | snake.tail_y = snake.tail_y; |
ajorgih3 | 6:fbaee888e5ea | 1295 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1296 | } |
ajorgih3 | 5:5953ca12205d | 1297 | |
ajorgih3 | 6:fbaee888e5ea | 1298 | if ((snake.body_y - 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1299 | snake.locations[i].x = snake.body_x; |
ajorgih3 | 6:fbaee888e5ea | 1300 | snake.locations[i].y = snake.body_y - 1; |
ajorgih3 | 6:fbaee888e5ea | 1301 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1302 | bodyLength++; |
ajorgih3 | 6:fbaee888e5ea | 1303 | pc.printf("body length: %d\n", bodyLength); |
ajorgih3 | 6:fbaee888e5ea | 1304 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1305 | snake.tail_x = snake.tail_x; |
ajorgih3 | 6:fbaee888e5ea | 1306 | snake.tail_y = snake.tail_y - 1; |
ajorgih3 | 6:fbaee888e5ea | 1307 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1308 | } |
ajorgih3 | 5:5953ca12205d | 1309 | |
ajorgih3 | 6:fbaee888e5ea | 1310 | if ((snake.body_y + 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1311 | snake.locations[i].x = snake.body_x; |
ajorgih3 | 6:fbaee888e5ea | 1312 | snake.locations[i].y = snake.body_y + 1; |
ajorgih3 | 6:fbaee888e5ea | 1313 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1314 | bodyLength++; |
ajorgih3 | 6:fbaee888e5ea | 1315 | pc.printf("body length: %d\n", bodyLength); |
ajorgih3 | 6:fbaee888e5ea | 1316 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1317 | snake.tail_x = snake.tail_x; |
ajorgih3 | 6:fbaee888e5ea | 1318 | snake.tail_y = snake.tail_y + 1; |
ajorgih3 | 6:fbaee888e5ea | 1319 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1320 | } |
ajorgih3 | 5:5953ca12205d | 1321 | |
ajorgih3 | 6:fbaee888e5ea | 1322 | break; |
ajorgih3 | 6:fbaee888e5ea | 1323 | } |
ajorgih3 | 6:fbaee888e5ea | 1324 | pc.printf("i: %d\n", i); |
ajorgih3 | 5:5953ca12205d | 1325 | } |
ajorgih3 | 6:fbaee888e5ea | 1326 | } |
ajorgih3 | 7:7ab2f4b09196 | 1327 | } |
ajorgih3 | 7:7ab2f4b09196 | 1328 | |
ajorgih3 | 4:697e1120f821 | 1329 | |
ajorgih3 | 6:fbaee888e5ea | 1330 | if (nextHead->type == SNOWFLAKE) { |
ajorgih3 | 7:7ab2f4b09196 | 1331 | slowflakeCounter = 20; |
ajorgih3 | 4:697e1120f821 | 1332 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1333 | add_nothing(snake.head_x - 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1334 | } |
ajorgih3 | 4:697e1120f821 | 1335 | |
ajorgih3 | 7:7ab2f4b09196 | 1336 | if (nextHead->type == SWORD && shieldCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1337 | if (lives == 0) { |
ajorgih3 | 6:fbaee888e5ea | 1338 | draw_game(GAME_OVER); |
ajorgih3 | 4:697e1120f821 | 1339 | } |
ajorgih3 | 4:697e1120f821 | 1340 | else { |
ajorgih3 | 7:7ab2f4b09196 | 1341 | if (shieldCounter == 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1342 | lives--; |
ajorgih3 | 7:7ab2f4b09196 | 1343 | } |
ajorgih3 | 4:697e1120f821 | 1344 | } |
ajorgih3 | 4:697e1120f821 | 1345 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1346 | add_nothing(snake.head_x-1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1347 | } |
ajorgih3 | 6:fbaee888e5ea | 1348 | |
ajorgih3 | 6:fbaee888e5ea | 1349 | if (nextHead->type == REVERSE) { |
ajorgih3 | 6:fbaee888e5ea | 1350 | reverseCounter = 20; |
ajorgih3 | 4:697e1120f821 | 1351 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1352 | add_nothing(snake.head_x - 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1353 | } |
ajorgih3 | 6:fbaee888e5ea | 1354 | |
ajorgih3 | 6:fbaee888e5ea | 1355 | if (nextHead->type == LIGHTSPEED) { |
ajorgih3 | 6:fbaee888e5ea | 1356 | speedCounter = 50; |
ajorgih3 | 4:697e1120f821 | 1357 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1358 | add_nothing(snake.head_x - 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1359 | } |
ajorgih3 | 6:fbaee888e5ea | 1360 | |
ajorgih3 | 6:fbaee888e5ea | 1361 | if (nextHead->type == SHIELD) { |
ajorgih3 | 6:fbaee888e5ea | 1362 | shieldCounter = 15; |
ajorgih3 | 6:fbaee888e5ea | 1363 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1364 | add_nothing(snake.head_x - 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1365 | } |
ajorgih3 | 6:fbaee888e5ea | 1366 | |
ajorgih3 | 7:7ab2f4b09196 | 1367 | if (nextHead->type == REDPOTION) { |
ajorgih3 | 7:7ab2f4b09196 | 1368 | redCounter = 20; |
ajorgih3 | 7:7ab2f4b09196 | 1369 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1370 | add_nothing(snake.head_x - 1, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1371 | } |
ajorgih3 | 7:7ab2f4b09196 | 1372 | |
ajorgih3 | 7:7ab2f4b09196 | 1373 | if (nextHead->type == BLUEPOTION) { |
ajorgih3 | 7:7ab2f4b09196 | 1374 | blueCounter = 20; |
ajorgih3 | 7:7ab2f4b09196 | 1375 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1376 | add_nothing(snake.head_x - 1, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1377 | } |
ajorgih3 | 6:fbaee888e5ea | 1378 | break; |
ajorgih3 | 3:bb6f73642f01 | 1379 | |
ajorgih3 | 3:bb6f73642f01 | 1380 | |
ajorgih3 | 6:fbaee888e5ea | 1381 | case GO_UP: |
ajorgih3 | 6:fbaee888e5ea | 1382 | nextHead = get_north(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1383 | pc.printf("GO UP\n"); |
ajorgih3 | 7:7ab2f4b09196 | 1384 | if (nextHead->walkable && nextHead->type != LIFE && nextHead->type != GOODIE && nextHead->type != SWORD && nextHead->type != REVERSE && nextHead->type != LIGHTSPEED && nextHead->type != SHIELD && nextHead->type != SNOWFLAKE && nextHead->type != BLUEPOTION && nextHead->type != REDPOTION) { |
ajorgih3 | 6:fbaee888e5ea | 1385 | pc.printf("Before:\n"); |
ajorgih3 | 6:fbaee888e5ea | 1386 | pc.printf("head_x: %d, head_y: %d\n", snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1387 | pc.printf("body_x: %d, body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1388 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 7:7ab2f4b09196 | 1389 | pc.printf("reverseCounter: %d\n\n", reverseCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1390 | pc.printf("speedCounter: %d\n\n", speedCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1391 | pc.printf("shieldCounter: %d\n\n", shieldCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1392 | pc.printf("slowflakeCounter: %d", slowflakeCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1393 | pc.printf("blueCounter: %d", blueCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1394 | pc.printf("redCounter: %d", redCounter); |
ajorgih3 | 6:fbaee888e5ea | 1395 | // reverse direction |
ajorgih3 | 6:fbaee888e5ea | 1396 | if (reverseCounter == 0) { |
ajorgih3 | 6:fbaee888e5ea | 1397 | go_up2(); |
ajorgih3 | 8:34fd253d0fa5 | 1398 | draw_arrow_up(113, 100); |
ajorgih3 | 6:fbaee888e5ea | 1399 | } |
ajorgih3 | 6:fbaee888e5ea | 1400 | if (reverseCounter <= 20 && reverseCounter != 0) { |
ajorgih3 | 8:34fd253d0fa5 | 1401 | go_down2(); |
ajorgih3 | 8:34fd253d0fa5 | 1402 | draw_arrow_down(113, 100); |
ajorgih3 | 7:7ab2f4b09196 | 1403 | pc.printf("reverseCounter: %d", reverseCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1404 | reverseCounter--; |
ajorgih3 | 6:fbaee888e5ea | 1405 | } |
ajorgih3 | 5:5953ca12205d | 1406 | //draw_snake_head(snake.head_pi, snake.head_pj); |
ajorgih3 | 5:5953ca12205d | 1407 | //draw_snake_body(snake.body_pi, snake.body_pj); |
ajorgih3 | 5:5953ca12205d | 1408 | //draw_snake_tail(snake.tail_pi, snake.tail_pj); |
ajorgih3 | 6:fbaee888e5ea | 1409 | updateY(); |
ajorgih3 | 6:fbaee888e5ea | 1410 | pc.printf("After:\n"); |
ajorgih3 | 6:fbaee888e5ea | 1411 | pc.printf("head_x: %d, head_y: %d\n", snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1412 | pc.printf("body_x: %d, body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1413 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1414 | if (shieldCounter <= 15 && shieldCounter != 0) { |
ajorgih3 | 6:fbaee888e5ea | 1415 | shieldCounter--; |
ajorgih3 | 6:fbaee888e5ea | 1416 | } |
ajorgih3 | 7:7ab2f4b09196 | 1417 | if (blueCounter <= 20 && blueCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1418 | blueCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 1419 | } |
ajorgih3 | 7:7ab2f4b09196 | 1420 | if (redCounter <= 20 && redCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1421 | redCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 1422 | } |
ajorgih3 | 6:fbaee888e5ea | 1423 | } |
ajorgih3 | 3:bb6f73642f01 | 1424 | |
ajorgih3 | 6:fbaee888e5ea | 1425 | if (!nextHead->walkable && invincibility == false) { |
ajorgih3 | 6:fbaee888e5ea | 1426 | if (shieldCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1427 | if (lives == 0) { |
ajorgih3 | 6:fbaee888e5ea | 1428 | draw_game(GAME_OVER); |
ajorgih3 | 4:697e1120f821 | 1429 | } |
ajorgih3 | 4:697e1120f821 | 1430 | else { |
ajorgih3 | 6:fbaee888e5ea | 1431 | lives--; |
ajorgih3 | 6:fbaee888e5ea | 1432 | } |
ajorgih3 | 4:697e1120f821 | 1433 | } |
ajorgih3 | 6:fbaee888e5ea | 1434 | } |
ajorgih3 | 6:fbaee888e5ea | 1435 | |
ajorgih3 | 6:fbaee888e5ea | 1436 | if (nextHead->type == LIFE) { |
ajorgih3 | 4:697e1120f821 | 1437 | lives++; |
ajorgih3 | 4:697e1120f821 | 1438 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1439 | add_nothing(snake.head_x, snake.head_y - 1); |
ajorgih3 | 6:fbaee888e5ea | 1440 | } |
ajorgih3 | 4:697e1120f821 | 1441 | |
ajorgih3 | 6:fbaee888e5ea | 1442 | if (nextHead->type == GOODIE) { |
ajorgih3 | 7:7ab2f4b09196 | 1443 | |
ajorgih3 | 7:7ab2f4b09196 | 1444 | if (redCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1445 | score++; |
ajorgih3 | 7:7ab2f4b09196 | 1446 | } |
ajorgih3 | 7:7ab2f4b09196 | 1447 | |
ajorgih3 | 4:697e1120f821 | 1448 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 5:5953ca12205d | 1449 | add_nothing(snake.head_x, snake.head_y - 1); // eat the goodie |
ajorgih3 | 5:5953ca12205d | 1450 | |
ajorgih3 | 7:7ab2f4b09196 | 1451 | if (blueCounter == 0) { |
ajorgih3 | 5:5953ca12205d | 1452 | if ((snake.body_x - 1) == snake.tail_x) { |
ajorgih3 | 6:fbaee888e5ea | 1453 | add_snake_body(snake.body_x - 1, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1454 | add_snake_tail(snake.tail_x - 1, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1455 | } |
ajorgih3 | 5:5953ca12205d | 1456 | |
ajorgih3 | 5:5953ca12205d | 1457 | if ((snake.body_x + 1) == snake.tail_x) { |
ajorgih3 | 6:fbaee888e5ea | 1458 | add_snake_body(snake.body_x + 1, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1459 | add_snake_tail(snake.tail_x + 1, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1460 | } |
ajorgih3 | 5:5953ca12205d | 1461 | |
ajorgih3 | 5:5953ca12205d | 1462 | if ((snake.body_y + 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1463 | add_snake_body(snake.body_x, snake.body_y + 1); |
ajorgih3 | 6:fbaee888e5ea | 1464 | add_snake_tail(snake.tail_x, snake.tail_y + 1); |
ajorgih3 | 5:5953ca12205d | 1465 | } |
ajorgih3 | 5:5953ca12205d | 1466 | |
ajorgih3 | 7:7ab2f4b09196 | 1467 | |
ajorgih3 | 5:5953ca12205d | 1468 | // this places a new body coordinate before the main body, this is go right function |
ajorgih3 | 5:5953ca12205d | 1469 | for (int i = 0; i < SNAKE_MAX_LENGTH; i++) { |
ajorgih3 | 6:fbaee888e5ea | 1470 | if (snake.locations[i].x == 0 && snake.locations[i].y == 0) { |
ajorgih3 | 5:5953ca12205d | 1471 | |
ajorgih3 | 5:5953ca12205d | 1472 | // if snake is upright |
ajorgih3 | 6:fbaee888e5ea | 1473 | if ((snake.body_y + 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1474 | snake.locations[i].x = snake.body_x; |
ajorgih3 | 6:fbaee888e5ea | 1475 | snake.locations[i].y = snake.body_y + 1; // this stores the snake new body location into a non-filled array |
ajorgih3 | 5:5953ca12205d | 1476 | |
ajorgih3 | 6:fbaee888e5ea | 1477 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1478 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1479 | |
ajorgih3 | 6:fbaee888e5ea | 1480 | snake.tail_x = snake.tail_x; |
ajorgih3 | 6:fbaee888e5ea | 1481 | snake.tail_y = snake.tail_y + 1; // this updates the new tail location |
ajorgih3 | 6:fbaee888e5ea | 1482 | } |
ajorgih3 | 5:5953ca12205d | 1483 | |
ajorgih3 | 6:fbaee888e5ea | 1484 | if ((snake.body_x + 1) == snake.tail_x) { |
ajorgih3 | 6:fbaee888e5ea | 1485 | snake.locations[i].x = snake.body_x + 1; |
ajorgih3 | 6:fbaee888e5ea | 1486 | snake.locations[i].y = snake.body_y; // this stores the snake new body location into a non-filled array |
ajorgih3 | 5:5953ca12205d | 1487 | |
ajorgih3 | 6:fbaee888e5ea | 1488 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1489 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1490 | |
ajorgih3 | 6:fbaee888e5ea | 1491 | snake.tail_x = snake.tail_x + 1; |
ajorgih3 | 6:fbaee888e5ea | 1492 | snake.tail_y = snake.tail_y; // this updates the new tail location |
ajorgih3 | 6:fbaee888e5ea | 1493 | } |
ajorgih3 | 5:5953ca12205d | 1494 | |
ajorgih3 | 6:fbaee888e5ea | 1495 | if ((snake.body_x - 1) == snake.tail_x) { |
ajorgih3 | 6:fbaee888e5ea | 1496 | snake.locations[i].x = snake.body_x - 1; |
ajorgih3 | 6:fbaee888e5ea | 1497 | snake.locations[i].y = snake.body_y; // this stores the snake new body location into a non-filled array |
ajorgih3 | 5:5953ca12205d | 1498 | |
ajorgih3 | 6:fbaee888e5ea | 1499 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1500 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1501 | |
ajorgih3 | 6:fbaee888e5ea | 1502 | snake.tail_x = snake.tail_x - 1; |
ajorgih3 | 6:fbaee888e5ea | 1503 | snake.tail_y = snake.tail_y; // this updates the new tail location |
ajorgih3 | 6:fbaee888e5ea | 1504 | } |
ajorgih3 | 5:5953ca12205d | 1505 | |
ajorgih3 | 5:5953ca12205d | 1506 | |
ajorgih3 | 6:fbaee888e5ea | 1507 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1508 | |
ajorgih3 | 6:fbaee888e5ea | 1509 | bodyLength++; |
ajorgih3 | 5:5953ca12205d | 1510 | |
ajorgih3 | 6:fbaee888e5ea | 1511 | pc.printf("body length: %d\n", bodyLength); |
ajorgih3 | 6:fbaee888e5ea | 1512 | break; |
ajorgih3 | 6:fbaee888e5ea | 1513 | } |
ajorgih3 | 6:fbaee888e5ea | 1514 | pc.printf("i: %d\n", i); |
ajorgih3 | 5:5953ca12205d | 1515 | } |
ajorgih3 | 6:fbaee888e5ea | 1516 | } |
ajorgih3 | 7:7ab2f4b09196 | 1517 | } |
ajorgih3 | 4:697e1120f821 | 1518 | |
ajorgih3 | 6:fbaee888e5ea | 1519 | if (nextHead->type == SNOWFLAKE) { |
ajorgih3 | 7:7ab2f4b09196 | 1520 | slowflakeCounter = 20; |
ajorgih3 | 4:697e1120f821 | 1521 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1522 | add_nothing(snake.head_x - 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1523 | } |
ajorgih3 | 4:697e1120f821 | 1524 | |
ajorgih3 | 7:7ab2f4b09196 | 1525 | if (nextHead->type == SWORD && shieldCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1526 | if (lives == 0) { |
ajorgih3 | 6:fbaee888e5ea | 1527 | draw_game(GAME_OVER); |
ajorgih3 | 4:697e1120f821 | 1528 | } |
ajorgih3 | 4:697e1120f821 | 1529 | else { |
ajorgih3 | 7:7ab2f4b09196 | 1530 | if (shieldCounter == 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1531 | lives--; |
ajorgih3 | 7:7ab2f4b09196 | 1532 | } |
ajorgih3 | 4:697e1120f821 | 1533 | } |
ajorgih3 | 4:697e1120f821 | 1534 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 4:697e1120f821 | 1535 | add_nothing(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1536 | } |
ajorgih3 | 4:697e1120f821 | 1537 | |
ajorgih3 | 6:fbaee888e5ea | 1538 | if (nextHead->type == REVERSE) { |
ajorgih3 | 6:fbaee888e5ea | 1539 | reverseCounter = 20; |
ajorgih3 | 6:fbaee888e5ea | 1540 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1541 | add_nothing(snake.head_x, snake.head_y - 1); |
ajorgih3 | 6:fbaee888e5ea | 1542 | } |
ajorgih3 | 6:fbaee888e5ea | 1543 | |
ajorgih3 | 6:fbaee888e5ea | 1544 | if (nextHead->type == LIGHTSPEED) { |
ajorgih3 | 6:fbaee888e5ea | 1545 | speedCounter = 50; |
ajorgih3 | 4:697e1120f821 | 1546 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1547 | add_nothing(snake.head_x, snake.head_y - 1); |
ajorgih3 | 6:fbaee888e5ea | 1548 | } |
ajorgih3 | 6:fbaee888e5ea | 1549 | |
ajorgih3 | 7:7ab2f4b09196 | 1550 | if (nextHead->type == SHIELD) { |
ajorgih3 | 6:fbaee888e5ea | 1551 | shieldCounter = 15; |
ajorgih3 | 4:697e1120f821 | 1552 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1553 | add_nothing(snake.head_x, snake.head_y - 1); |
ajorgih3 | 6:fbaee888e5ea | 1554 | } |
ajorgih3 | 7:7ab2f4b09196 | 1555 | |
ajorgih3 | 7:7ab2f4b09196 | 1556 | if (nextHead->type == BLUEPOTION) { |
ajorgih3 | 7:7ab2f4b09196 | 1557 | blueCounter = 20; |
ajorgih3 | 7:7ab2f4b09196 | 1558 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1559 | add_nothing(snake.head_x, snake.head_y - 1); |
ajorgih3 | 7:7ab2f4b09196 | 1560 | } |
ajorgih3 | 7:7ab2f4b09196 | 1561 | if (nextHead->type == REDPOTION) { |
ajorgih3 | 7:7ab2f4b09196 | 1562 | redCounter = 20; |
ajorgih3 | 7:7ab2f4b09196 | 1563 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1564 | add_nothing(snake.head_x, snake.head_y - 1); |
ajorgih3 | 7:7ab2f4b09196 | 1565 | } |
ajorgih3 | 6:fbaee888e5ea | 1566 | break; |
ajorgih3 | 3:bb6f73642f01 | 1567 | |
ajorgih3 | 3:bb6f73642f01 | 1568 | |
ajorgih3 | 6:fbaee888e5ea | 1569 | case GO_DOWN: |
ajorgih3 | 6:fbaee888e5ea | 1570 | nextHead = get_south(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1571 | pc.printf("GO DOWN\n"); |
ajorgih3 | 7:7ab2f4b09196 | 1572 | if (nextHead->walkable && nextHead->type != LIFE && nextHead->type != GOODIE && nextHead->type != SWORD && nextHead->type != REVERSE && nextHead->type != LIGHTSPEED && nextHead->type != SHIELD && nextHead->type != SNOWFLAKE && nextHead->type != BLUEPOTION && nextHead->type != REDPOTION) { |
ajorgih3 | 5:5953ca12205d | 1573 | pc.printf("Before:\n"); |
ajorgih3 | 6:fbaee888e5ea | 1574 | pc.printf("head_x: %d, head_y: %d\n", snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1575 | pc.printf("body_x: %d, body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1576 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 7:7ab2f4b09196 | 1577 | pc.printf("reverseCounter: %d\n\n", reverseCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1578 | pc.printf("speedCounter: %d\n\n", speedCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1579 | pc.printf("shieldCounter: %d\n\n", shieldCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1580 | pc.printf("slowflakeCounter: %d", slowflakeCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1581 | pc.printf("blueCounter: %d", blueCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1582 | pc.printf("redCounter: %d", redCounter); |
ajorgih3 | 6:fbaee888e5ea | 1583 | if (reverseCounter == 0) { |
ajorgih3 | 5:5953ca12205d | 1584 | go_down2(); |
ajorgih3 | 8:34fd253d0fa5 | 1585 | draw_arrow_down(113, 100); |
ajorgih3 | 6:fbaee888e5ea | 1586 | } |
ajorgih3 | 6:fbaee888e5ea | 1587 | if (reverseCounter <= 20 && reverseCounter !=0) { |
ajorgih3 | 6:fbaee888e5ea | 1588 | go_up2(); |
ajorgih3 | 8:34fd253d0fa5 | 1589 | draw_arrow_up(113, 100); |
ajorgih3 | 7:7ab2f4b09196 | 1590 | pc.printf("reverseCounter: %d", reverseCounter); |
ajorgih3 | 7:7ab2f4b09196 | 1591 | reverseCounter--; |
ajorgih3 | 6:fbaee888e5ea | 1592 | } |
ajorgih3 | 5:5953ca12205d | 1593 | //draw_snake_head(snake.head_pi, snake.head_pj); |
ajorgih3 | 5:5953ca12205d | 1594 | //draw_snake_body(snake.body_pi, snake.body_pj); |
ajorgih3 | 5:5953ca12205d | 1595 | //draw_snake_tail(snake.tail_pi, snake.tail_pj); |
ajorgih3 | 6:fbaee888e5ea | 1596 | updateY(); |
ajorgih3 | 5:5953ca12205d | 1597 | pc.printf("After:\n"); |
ajorgih3 | 6:fbaee888e5ea | 1598 | pc.printf("head_x: %d, head_y: %d\n", snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1599 | pc.printf("body_x: %d, body_y: %d\n", snake.body_x, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1600 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 6:fbaee888e5ea | 1601 | if (shieldCounter <= 15 && shieldCounter != 0) { |
ajorgih3 | 6:fbaee888e5ea | 1602 | shieldCounter--; |
ajorgih3 | 6:fbaee888e5ea | 1603 | } |
ajorgih3 | 7:7ab2f4b09196 | 1604 | if (blueCounter <= 20 && blueCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1605 | blueCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 1606 | } |
ajorgih3 | 7:7ab2f4b09196 | 1607 | if (redCounter <= 20 && redCounter != 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1608 | redCounter--; |
ajorgih3 | 7:7ab2f4b09196 | 1609 | } |
ajorgih3 | 6:fbaee888e5ea | 1610 | } |
ajorgih3 | 6:fbaee888e5ea | 1611 | |
ajorgih3 | 6:fbaee888e5ea | 1612 | if (!nextHead->walkable && invincibility == false) { |
ajorgih3 | 6:fbaee888e5ea | 1613 | if (shieldCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1614 | if (lives == 0) { |
ajorgih3 | 6:fbaee888e5ea | 1615 | draw_game(GAME_OVER); |
ajorgih3 | 4:697e1120f821 | 1616 | } |
ajorgih3 | 4:697e1120f821 | 1617 | else { |
ajorgih3 | 6:fbaee888e5ea | 1618 | lives--; |
ajorgih3 | 6:fbaee888e5ea | 1619 | } |
ajorgih3 | 4:697e1120f821 | 1620 | } |
ajorgih3 | 6:fbaee888e5ea | 1621 | } |
ajorgih3 | 6:fbaee888e5ea | 1622 | |
ajorgih3 | 6:fbaee888e5ea | 1623 | if (nextHead->type == LIFE) { |
ajorgih3 | 4:697e1120f821 | 1624 | lives++; |
ajorgih3 | 4:697e1120f821 | 1625 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1626 | add_nothing(snake.head_x, snake.head_y+1); |
ajorgih3 | 6:fbaee888e5ea | 1627 | } |
ajorgih3 | 4:697e1120f821 | 1628 | |
ajorgih3 | 6:fbaee888e5ea | 1629 | if (nextHead->type == GOODIE) { |
ajorgih3 | 7:7ab2f4b09196 | 1630 | |
ajorgih3 | 7:7ab2f4b09196 | 1631 | if (redCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1632 | score++; |
ajorgih3 | 7:7ab2f4b09196 | 1633 | } |
ajorgih3 | 7:7ab2f4b09196 | 1634 | |
ajorgih3 | 4:697e1120f821 | 1635 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 5:5953ca12205d | 1636 | add_nothing(snake.head_x, snake.head_y + 1); // eat the goodie |
ajorgih3 | 5:5953ca12205d | 1637 | |
ajorgih3 | 7:7ab2f4b09196 | 1638 | if (blueCounter == 0) { |
ajorgih3 | 5:5953ca12205d | 1639 | // if the tail is to the left of the body |
ajorgih3 | 5:5953ca12205d | 1640 | if ((snake.body_x - 1) == snake.tail_x) { |
ajorgih3 | 6:fbaee888e5ea | 1641 | add_snake_body(snake.body_x - 1, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1642 | add_snake_tail(snake.tail_x - 1, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1643 | } |
ajorgih3 | 5:5953ca12205d | 1644 | |
ajorgih3 | 5:5953ca12205d | 1645 | // if the tail is to the right of the body |
ajorgih3 | 5:5953ca12205d | 1646 | if ((snake.body_x + 1) == snake.tail_x) { |
ajorgih3 | 6:fbaee888e5ea | 1647 | add_snake_body(snake.body_x + 1, snake.body_y); |
ajorgih3 | 6:fbaee888e5ea | 1648 | add_snake_tail(snake.tail_x + 1, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1649 | } |
ajorgih3 | 5:5953ca12205d | 1650 | |
ajorgih3 | 5:5953ca12205d | 1651 | // if the snake is upright |
ajorgih3 | 5:5953ca12205d | 1652 | if ((snake.body_y - 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1653 | add_snake_body(snake.body_x, snake.body_y + 1); |
ajorgih3 | 6:fbaee888e5ea | 1654 | add_snake_tail(snake.tail_x, snake.tail_y + 1); |
ajorgih3 | 5:5953ca12205d | 1655 | } |
ajorgih3 | 5:5953ca12205d | 1656 | |
ajorgih3 | 5:5953ca12205d | 1657 | // this places a new body coordinate before the main body, this is go right function |
ajorgih3 | 5:5953ca12205d | 1658 | for (int i = 0; i < SNAKE_MAX_LENGTH; i++) { |
ajorgih3 | 6:fbaee888e5ea | 1659 | if (snake.locations[i].x == 0 && snake.locations[i].y == 0) { |
ajorgih3 | 5:5953ca12205d | 1660 | |
ajorgih3 | 5:5953ca12205d | 1661 | // if snake is upright |
ajorgih3 | 6:fbaee888e5ea | 1662 | if ((snake.body_y - 1) == snake.tail_y) { |
ajorgih3 | 6:fbaee888e5ea | 1663 | snake.locations[i].x = snake.body_x; |
ajorgih3 | 6:fbaee888e5ea | 1664 | snake.locations[i].y = snake.body_y - 1; // this stores the snake new body location into a non-filled array |
ajorgih3 | 5:5953ca12205d | 1665 | |
ajorgih3 | 6:fbaee888e5ea | 1666 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1667 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1668 | |
ajorgih3 | 6:fbaee888e5ea | 1669 | snake.tail_x = snake.tail_x; |
ajorgih3 | 6:fbaee888e5ea | 1670 | snake.tail_y = snake.tail_y - 1; // this updates the new tail location |
ajorgih3 | 6:fbaee888e5ea | 1671 | } |
ajorgih3 | 5:5953ca12205d | 1672 | |
ajorgih3 | 6:fbaee888e5ea | 1673 | if ((snake.body_x + 1) == snake.tail_x) { |
ajorgih3 | 6:fbaee888e5ea | 1674 | snake.locations[i].x = snake.body_x + 1; |
ajorgih3 | 6:fbaee888e5ea | 1675 | snake.locations[i].y = snake.body_y; // this stores the snake new body location into a non-filled array |
ajorgih3 | 5:5953ca12205d | 1676 | |
ajorgih3 | 6:fbaee888e5ea | 1677 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1678 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1679 | |
ajorgih3 | 6:fbaee888e5ea | 1680 | snake.tail_x = snake.tail_x + 1; |
ajorgih3 | 6:fbaee888e5ea | 1681 | snake.tail_y = snake.tail_y; // this updates the new tail location |
ajorgih3 | 6:fbaee888e5ea | 1682 | } |
ajorgih3 | 5:5953ca12205d | 1683 | |
ajorgih3 | 6:fbaee888e5ea | 1684 | if ((snake.body_x - 1) == snake.tail_x) { |
ajorgih3 | 6:fbaee888e5ea | 1685 | snake.locations[i].x = snake.body_x - 1; |
ajorgih3 | 6:fbaee888e5ea | 1686 | snake.locations[i].y = snake.body_y; // this stores the snake new body location into a non-filled array |
ajorgih3 | 5:5953ca12205d | 1687 | |
ajorgih3 | 6:fbaee888e5ea | 1688 | pc.printf("snake.locations[%d].x: %d, snake.locations[%d].y: %d\n", i, snake.locations[i].x, i, snake.locations[i].y); |
ajorgih3 | 6:fbaee888e5ea | 1689 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1690 | |
ajorgih3 | 6:fbaee888e5ea | 1691 | snake.tail_x = snake.tail_x - 1; |
ajorgih3 | 6:fbaee888e5ea | 1692 | snake.tail_y = snake.tail_y; // this updates the new tail location |
ajorgih3 | 6:fbaee888e5ea | 1693 | } |
ajorgih3 | 5:5953ca12205d | 1694 | |
ajorgih3 | 5:5953ca12205d | 1695 | |
ajorgih3 | 6:fbaee888e5ea | 1696 | pc.printf("tail_x: %d, tail_y: %d\n", snake.tail_x, snake.tail_y); |
ajorgih3 | 5:5953ca12205d | 1697 | |
ajorgih3 | 6:fbaee888e5ea | 1698 | bodyLength++; |
ajorgih3 | 5:5953ca12205d | 1699 | |
ajorgih3 | 6:fbaee888e5ea | 1700 | pc.printf("body length: %d\n", bodyLength); |
ajorgih3 | 6:fbaee888e5ea | 1701 | break; |
ajorgih3 | 6:fbaee888e5ea | 1702 | } |
ajorgih3 | 6:fbaee888e5ea | 1703 | pc.printf("i: %d\n", i); |
ajorgih3 | 5:5953ca12205d | 1704 | } |
ajorgih3 | 7:7ab2f4b09196 | 1705 | } |
ajorgih3 | 7:7ab2f4b09196 | 1706 | } |
ajorgih3 | 4:697e1120f821 | 1707 | |
ajorgih3 | 6:fbaee888e5ea | 1708 | if (nextHead->type == SNOWFLAKE) { |
ajorgih3 | 7:7ab2f4b09196 | 1709 | slowflakeCounter = 20; |
ajorgih3 | 4:697e1120f821 | 1710 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1711 | add_nothing(snake.head_x - 1, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1712 | } |
ajorgih3 | 4:697e1120f821 | 1713 | |
ajorgih3 | 7:7ab2f4b09196 | 1714 | if (nextHead->type == SWORD && shieldCounter == 0) { |
ajorgih3 | 4:697e1120f821 | 1715 | if (lives == 0) { |
ajorgih3 | 6:fbaee888e5ea | 1716 | draw_game(GAME_OVER); |
ajorgih3 | 4:697e1120f821 | 1717 | } |
ajorgih3 | 4:697e1120f821 | 1718 | else { |
ajorgih3 | 7:7ab2f4b09196 | 1719 | if (shieldCounter == 0) { |
ajorgih3 | 7:7ab2f4b09196 | 1720 | lives--; |
ajorgih3 | 7:7ab2f4b09196 | 1721 | } |
ajorgih3 | 4:697e1120f821 | 1722 | } |
ajorgih3 | 4:697e1120f821 | 1723 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1724 | add_nothing(snake.head_x, snake.head_y+1); |
ajorgih3 | 6:fbaee888e5ea | 1725 | } |
ajorgih3 | 6:fbaee888e5ea | 1726 | |
ajorgih3 | 6:fbaee888e5ea | 1727 | if (nextHead->type == REVERSE) { |
ajorgih3 | 6:fbaee888e5ea | 1728 | reverseCounter = 20; |
ajorgih3 | 4:697e1120f821 | 1729 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1730 | add_nothing(snake.head_x, snake.head_y + 1); |
ajorgih3 | 6:fbaee888e5ea | 1731 | } |
ajorgih3 | 6:fbaee888e5ea | 1732 | |
ajorgih3 | 6:fbaee888e5ea | 1733 | if (nextHead->type == LIGHTSPEED) { |
ajorgih3 | 6:fbaee888e5ea | 1734 | speedCounter = 50; |
ajorgih3 | 4:697e1120f821 | 1735 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1736 | add_nothing(snake.head_x, snake.head_y + 1); |
ajorgih3 | 6:fbaee888e5ea | 1737 | } |
ajorgih3 | 6:fbaee888e5ea | 1738 | |
ajorgih3 | 7:7ab2f4b09196 | 1739 | if (nextHead->type == SHIELD) { |
ajorgih3 | 6:fbaee888e5ea | 1740 | shieldCounter = 15; |
ajorgih3 | 6:fbaee888e5ea | 1741 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 6:fbaee888e5ea | 1742 | add_nothing(snake.head_x, snake.head_y + 1); |
ajorgih3 | 6:fbaee888e5ea | 1743 | } |
ajorgih3 | 6:fbaee888e5ea | 1744 | |
ajorgih3 | 7:7ab2f4b09196 | 1745 | if (nextHead->type == REDPOTION) { |
ajorgih3 | 7:7ab2f4b09196 | 1746 | redCounter = 20; |
ajorgih3 | 7:7ab2f4b09196 | 1747 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1748 | add_nothing(snake.head_x, snake.head_y + 1); |
ajorgih3 | 7:7ab2f4b09196 | 1749 | } |
ajorgih3 | 7:7ab2f4b09196 | 1750 | |
ajorgih3 | 7:7ab2f4b09196 | 1751 | if (nextHead->type == BLUEPOTION) { |
ajorgih3 | 7:7ab2f4b09196 | 1752 | blueCounter = 20; |
ajorgih3 | 7:7ab2f4b09196 | 1753 | map_erase(snake.head_x, snake.head_y); |
ajorgih3 | 7:7ab2f4b09196 | 1754 | add_nothing(snake.head_x, snake.head_y + 1); |
ajorgih3 | 7:7ab2f4b09196 | 1755 | } |
ajorgih3 | 7:7ab2f4b09196 | 1756 | |
ajorgih3 | 6:fbaee888e5ea | 1757 | break; |
ajorgih3 | 3:bb6f73642f01 | 1758 | |
ajorgih3 | 6:fbaee888e5ea | 1759 | case HAX: |
ajorgih3 | 6:fbaee888e5ea | 1760 | invincibility = true; |
ajorgih3 | 6:fbaee888e5ea | 1761 | break; |
ajorgih3 | 8:34fd253d0fa5 | 1762 | |
ajorgih3 | 8:34fd253d0fa5 | 1763 | case PAUSE: |
ajorgih3 | 8:34fd253d0fa5 | 1764 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 8:34fd253d0fa5 | 1765 | uLCD.filled_rectangle(0, 9, 127, 14, 0xFFFFFF); // Top |
ajorgih3 | 8:34fd253d0fa5 | 1766 | uLCD.filled_rectangle(0, 13, 2, 114, 0xFFFFFF); // Left |
ajorgih3 | 8:34fd253d0fa5 | 1767 | uLCD.filled_rectangle(0, 114, 127, 117, 0xFFFFFF); // Bottom |
ajorgih3 | 8:34fd253d0fa5 | 1768 | uLCD.filled_rectangle(124, 14, 127, 117, 0xFFFFFF); // Right(); |
ajorgih3 | 8:34fd253d0fa5 | 1769 | |
ajorgih3 | 8:34fd253d0fa5 | 1770 | int u = 58; |
ajorgih3 | 8:34fd253d0fa5 | 1771 | int v = 56; |
ajorgih3 | 8:34fd253d0fa5 | 1772 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 8:34fd253d0fa5 | 1773 | uLCD.text_width(1); |
ajorgih3 | 8:34fd253d0fa5 | 1774 | uLCD.text_height(1); |
ajorgih3 | 8:34fd253d0fa5 | 1775 | uLCD.locate(5,7); |
ajorgih3 | 8:34fd253d0fa5 | 1776 | uLCD.color(RED); |
ajorgih3 | 8:34fd253d0fa5 | 1777 | uLCD.printf("PAUSING...\n"); |
ajorgih3 | 8:34fd253d0fa5 | 1778 | draw_snake_head(u+11, v+11); |
ajorgih3 | 8:34fd253d0fa5 | 1779 | draw_snake_body(u, v+11); |
ajorgih3 | 8:34fd253d0fa5 | 1780 | draw_snake_tail(u-11, v+11); |
ajorgih3 | 8:34fd253d0fa5 | 1781 | |
ajorgih3 | 8:34fd253d0fa5 | 1782 | uLCD.textbackground_color(BLACK); |
ajorgih3 | 8:34fd253d0fa5 | 1783 | uLCD.color(0xFFFFFF); |
ajorgih3 | 8:34fd253d0fa5 | 1784 | uLCD.text_width(1); |
ajorgih3 | 8:34fd253d0fa5 | 1785 | uLCD.text_height(1); |
ajorgih3 | 8:34fd253d0fa5 | 1786 | uLCD.locate(4, 10); |
ajorgih3 | 8:34fd253d0fa5 | 1787 | uLCD.printf("Press 'B2'\n"); |
ajorgih3 | 8:34fd253d0fa5 | 1788 | uLCD.locate(5, 11); |
ajorgih3 | 8:34fd253d0fa5 | 1789 | uLCD.printf("to unpause!\n"); |
ajorgih3 | 9:d09b96b6c39c | 1790 | uLCD.locate(0, 0); |
ajorgih3 | 9:d09b96b6c39c | 1791 | uLCD.color(0xFFFFFF); |
ajorgih3 | 9:d09b96b6c39c | 1792 | uLCD.printf("STATUS:"); |
ajorgih3 | 9:d09b96b6c39c | 1793 | |
ajorgih3 | 9:d09b96b6c39c | 1794 | if (shieldCounter == 0) { |
ajorgih3 | 9:d09b96b6c39c | 1795 | draw_nothing(0, 11); |
ajorgih3 | 9:d09b96b6c39c | 1796 | } |
ajorgih3 | 9:d09b96b6c39c | 1797 | else { |
ajorgih3 | 9:d09b96b6c39c | 1798 | draw_shield(0, 11); |
ajorgih3 | 9:d09b96b6c39c | 1799 | } |
ajorgih3 | 9:d09b96b6c39c | 1800 | |
ajorgih3 | 9:d09b96b6c39c | 1801 | if (speedCounter == 0) { |
ajorgih3 | 9:d09b96b6c39c | 1802 | draw_nothing(11, 11); |
ajorgih3 | 9:d09b96b6c39c | 1803 | } |
ajorgih3 | 9:d09b96b6c39c | 1804 | else { |
ajorgih3 | 9:d09b96b6c39c | 1805 | draw_lightspeed(11, 11); |
ajorgih3 | 9:d09b96b6c39c | 1806 | } |
ajorgih3 | 9:d09b96b6c39c | 1807 | |
ajorgih3 | 9:d09b96b6c39c | 1808 | if (redCounter == 0) { |
ajorgih3 | 9:d09b96b6c39c | 1809 | draw_nothing(22, 11); |
ajorgih3 | 9:d09b96b6c39c | 1810 | } |
ajorgih3 | 9:d09b96b6c39c | 1811 | else { |
ajorgih3 | 9:d09b96b6c39c | 1812 | draw_red_potion(22, 11); |
ajorgih3 | 9:d09b96b6c39c | 1813 | } |
ajorgih3 | 9:d09b96b6c39c | 1814 | |
ajorgih3 | 9:d09b96b6c39c | 1815 | if (blueCounter == 0) { |
ajorgih3 | 9:d09b96b6c39c | 1816 | draw_nothing(33, 11); |
ajorgih3 | 9:d09b96b6c39c | 1817 | } |
ajorgih3 | 9:d09b96b6c39c | 1818 | else { |
ajorgih3 | 9:d09b96b6c39c | 1819 | draw_blue_potion(33, 11); |
ajorgih3 | 9:d09b96b6c39c | 1820 | } |
ajorgih3 | 9:d09b96b6c39c | 1821 | |
ajorgih3 | 9:d09b96b6c39c | 1822 | if (slowflakeCounter == 0) { |
ajorgih3 | 9:d09b96b6c39c | 1823 | draw_nothing(44, 11); |
ajorgih3 | 9:d09b96b6c39c | 1824 | } |
ajorgih3 | 9:d09b96b6c39c | 1825 | else { |
ajorgih3 | 9:d09b96b6c39c | 1826 | draw_snowflake(44, 11); |
ajorgih3 | 9:d09b96b6c39c | 1827 | } |
ajorgih3 | 8:34fd253d0fa5 | 1828 | |
ajorgih3 | 8:34fd253d0fa5 | 1829 | do { |
ajorgih3 | 8:34fd253d0fa5 | 1830 | input = read_inputs(); |
ajorgih3 | 8:34fd253d0fa5 | 1831 | } while(input.b2); |
ajorgih3 | 8:34fd253d0fa5 | 1832 | |
ajorgih3 | 8:34fd253d0fa5 | 1833 | uLCD.filled_rectangle(0, 9, 127, 14, 0xFFFFFF); // Top |
ajorgih3 | 8:34fd253d0fa5 | 1834 | uLCD.filled_rectangle(0, 13, 2, 114, 0xFFFFFF); // Left |
ajorgih3 | 8:34fd253d0fa5 | 1835 | uLCD.filled_rectangle(0, 114, 127, 117, 0xFFFFFF); // Bottom |
ajorgih3 | 8:34fd253d0fa5 | 1836 | uLCD.filled_rectangle(124, 14, 127, 117, 0xFFFFFF); // Right |
ajorgih3 | 8:34fd253d0fa5 | 1837 | uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 8:34fd253d0fa5 | 1838 | break; |
ajorgih3 | 3:bb6f73642f01 | 1839 | |
ajorgih3 | 6:fbaee888e5ea | 1840 | default: |
ajorgih3 | 6:fbaee888e5ea | 1841 | break; |
ajorgih3 | 6:fbaee888e5ea | 1842 | } |
ajorgih3 | 3:bb6f73642f01 | 1843 | |
ajorgih3 | 3:bb6f73642f01 | 1844 | |
ajorgih3 | 3:bb6f73642f01 | 1845 | |
ajorgih3 | 6:fbaee888e5ea | 1846 | return NO_RESULT; |
ajorgih3 | 3:bb6f73642f01 | 1847 | } |
ajorgih3 | 3:bb6f73642f01 | 1848 | |
ajorgih3 | 3:bb6f73642f01 | 1849 | |
DCchico | 1:10330bce85cb | 1850 | /** |
DCchico | 1:10330bce85cb | 1851 | * Program entry point! This is where it all begins. |
DCchico | 1:10330bce85cb | 1852 | * This function or all the parts of the game. Most of your |
DCchico | 1:10330bce85cb | 1853 | * implementation should be elsewhere - this holds the game loop, and should |
DCchico | 1:10330bce85cb | 1854 | * read like a road map for the rest of the code. |
DCchico | 1:10330bce85cb | 1855 | */ |
DCchico | 1:10330bce85cb | 1856 | int main() |
DCchico | 1:10330bce85cb | 1857 | { |
DCchico | 1:10330bce85cb | 1858 | // First things first: initialize hardware |
ajorgih3 | 6:fbaee888e5ea | 1859 | ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!"); |
ajorgih3 | 3:bb6f73642f01 | 1860 | |
ajorgih3 | 5:5953ca12205d | 1861 | //start_game(); |
ajorgih3 | 5:5953ca12205d | 1862 | //title_page(); |
ajorgih3 | 5:5953ca12205d | 1863 | //helpful_items(); |
ajorgih3 | 5:5953ca12205d | 1864 | //harmful_items(); |
ajorgih3 | 7:7ab2f4b09196 | 1865 | //additional_info(); |
ajorgih3 | 3:bb6f73642f01 | 1866 | |
ajorgih3 | 3:bb6f73642f01 | 1867 | // loading screen |
ajorgih3 | 3:bb6f73642f01 | 1868 | //uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 3:bb6f73642f01 | 1869 | //uLCD.textbackground_color(BLACK); |
ajorgih3 | 3:bb6f73642f01 | 1870 | //uLCD.color(0xFFFFFF); |
ajorgih3 | 3:bb6f73642f01 | 1871 | //uLCD.locate(4,7); |
ajorgih3 | 3:bb6f73642f01 | 1872 | //uLCD.printf("GOOD LUCK!"); |
ajorgih3 | 3:bb6f73642f01 | 1873 | //uLCD.locate(4,8); |
ajorgih3 | 3:bb6f73642f01 | 1874 | //uLCD.printf("Loading..."); |
ajorgih3 | 3:bb6f73642f01 | 1875 | //wait(4); |
ajorgih3 | 3:bb6f73642f01 | 1876 | //uLCD.filled_rectangle(0, 0, 255, 255, BLACK); |
ajorgih3 | 3:bb6f73642f01 | 1877 | |
ajorgih3 | 6:fbaee888e5ea | 1878 | snake_init(&snake); |
DCchico | 2:4947d6a82971 | 1879 | // 0. Initialize the maps -- implement this function: |
ajorgih3 | 6:fbaee888e5ea | 1880 | maps_init(); |
ajorgih3 | 5:5953ca12205d | 1881 | |
ajorgih3 | 5:5953ca12205d | 1882 | |
ajorgih3 | 5:5953ca12205d | 1883 | |
ajorgih3 | 6:fbaee888e5ea | 1884 | init_main_map(); |
ajorgih3 | 5:5953ca12205d | 1885 | //init_map_2(); |
ajorgih3 | 5:5953ca12205d | 1886 | |
DCchico | 1:10330bce85cb | 1887 | |
DCchico | 1:10330bce85cb | 1888 | // Initialize game state |
ajorgih3 | 6:fbaee888e5ea | 1889 | set_active_map(0); |
ajorgih3 | 6:fbaee888e5ea | 1890 | snake.head_x = snake.head_y = 5; |
ajorgih3 | 6:fbaee888e5ea | 1891 | snake.body_x = 4; |
ajorgih3 | 6:fbaee888e5ea | 1892 | snake.body_y = 5; |
ajorgih3 | 6:fbaee888e5ea | 1893 | snake.tail_x = 3; |
ajorgih3 | 6:fbaee888e5ea | 1894 | snake.tail_y = 5; |
DCchico | 1:10330bce85cb | 1895 | // Initial drawing |
ajorgih3 | 6:fbaee888e5ea | 1896 | draw_game(FULL_DRAW); |
DCchico | 1:10330bce85cb | 1897 | // Main game loop |
ajorgih3 | 6:fbaee888e5ea | 1898 | while(1) { |
DCchico | 1:10330bce85cb | 1899 | // Timer to measure game update speed |
ajorgih3 | 6:fbaee888e5ea | 1900 | Timer t; |
ajorgih3 | 6:fbaee888e5ea | 1901 | t.start(); |
ajorgih3 | 6:fbaee888e5ea | 1902 | |
DCchico | 2:4947d6a82971 | 1903 | // 1. Read inputs -- implement this function: |
ajorgih3 | 6:fbaee888e5ea | 1904 | GameInputs inputs = read_inputs(); |
DCchico | 2:4947d6a82971 | 1905 | |
DCchico | 2:4947d6a82971 | 1906 | // 2. Determine action (move, act, menu, etc.) -- implement this function: |
ajorgih3 | 6:fbaee888e5ea | 1907 | int action = get_action(inputs); |
DCchico | 2:4947d6a82971 | 1908 | |
DCchico | 2:4947d6a82971 | 1909 | // 3. Update game -- implement this function: |
ajorgih3 | 6:fbaee888e5ea | 1910 | int result = update_game(action); |
DCchico | 2:4947d6a82971 | 1911 | |
DCchico | 2:4947d6a82971 | 1912 | // 3b. Check for game over based on result |
DCchico | 2:4947d6a82971 | 1913 | // and if so, handle game over -- implement this. |
DCchico | 2:4947d6a82971 | 1914 | |
DCchico | 2:4947d6a82971 | 1915 | // 4. Draw screen -- provided: |
ajorgih3 | 6:fbaee888e5ea | 1916 | draw_game(result); |
DCchico | 2:4947d6a82971 | 1917 | |
DCchico | 1:10330bce85cb | 1918 | // Compute update time |
ajorgih3 | 6:fbaee888e5ea | 1919 | t.stop(); |
ajorgih3 | 6:fbaee888e5ea | 1920 | int dt = t.read_ms(); |
ajorgih3 | 6:fbaee888e5ea | 1921 | |
DCchico | 1:10330bce85cb | 1922 | // Display and wait |
DCchico | 1:10330bce85cb | 1923 | // NOTE: Text is 8 pixels tall |
ajorgih3 | 6:fbaee888e5ea | 1924 | if (dt < 100) wait_ms(100 - dt); |
ajorgih3 | 6:fbaee888e5ea | 1925 | } |
DCchico | 1:10330bce85cb | 1926 | } |
DCchico | 1:10330bce85cb | 1927 | |
ajorgih3 | 3:bb6f73642f01 | 1928 | int main2() { |
ajorgih3 | 7:7ab2f4b09196 | 1929 | // First things first: initialize hardware |
ajorgih3 | 7:7ab2f4b09196 | 1930 | ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!"); |
ajorgih3 | 7:7ab2f4b09196 | 1931 | |
ajorgih3 | 7:7ab2f4b09196 | 1932 | snake_init(&snake); |
ajorgih3 | 3:bb6f73642f01 | 1933 | // 0. Initialize the maps -- implement this function: |
ajorgih3 | 7:7ab2f4b09196 | 1934 | maps_init(); |
ajorgih3 | 7:7ab2f4b09196 | 1935 | |
ajorgih3 | 7:7ab2f4b09196 | 1936 | |
ajorgih3 | 7:7ab2f4b09196 | 1937 | |
ajorgih3 | 9:d09b96b6c39c | 1938 | //init_main_map(); |
ajorgih3 | 9:d09b96b6c39c | 1939 | init_map_2(); |
ajorgih3 | 7:7ab2f4b09196 | 1940 | |
ajorgih3 | 3:bb6f73642f01 | 1941 | |
ajorgih3 | 3:bb6f73642f01 | 1942 | // Initialize game state |
ajorgih3 | 6:fbaee888e5ea | 1943 | set_active_map(0); |
ajorgih3 | 6:fbaee888e5ea | 1944 | snake.head_x = snake.head_y = 5; |
ajorgih3 | 6:fbaee888e5ea | 1945 | snake.body_x = 4; |
ajorgih3 | 6:fbaee888e5ea | 1946 | snake.body_y = 5; |
ajorgih3 | 6:fbaee888e5ea | 1947 | snake.tail_x = 3; |
ajorgih3 | 6:fbaee888e5ea | 1948 | snake.tail_y = 5; |
ajorgih3 | 9:d09b96b6c39c | 1949 | //snake.length = bodyLength; |
ajorgih3 | 3:bb6f73642f01 | 1950 | // Initial drawing |
ajorgih3 | 6:fbaee888e5ea | 1951 | draw_game(FULL_DRAW); |
ajorgih3 | 3:bb6f73642f01 | 1952 | // Main game loop |
ajorgih3 | 6:fbaee888e5ea | 1953 | while(1) { |
ajorgih3 | 3:bb6f73642f01 | 1954 | // Timer to measure game update speed |
ajorgih3 | 6:fbaee888e5ea | 1955 | Timer t; |
ajorgih3 | 6:fbaee888e5ea | 1956 | t.start(); |
ajorgih3 | 6:fbaee888e5ea | 1957 | |
ajorgih3 | 3:bb6f73642f01 | 1958 | // 1. Read inputs -- implement this function: |
ajorgih3 | 6:fbaee888e5ea | 1959 | GameInputs inputs = read_inputs(); |
ajorgih3 | 3:bb6f73642f01 | 1960 | |
ajorgih3 | 3:bb6f73642f01 | 1961 | // 2. Determine action (move, act, menu, etc.) -- implement this function: |
ajorgih3 | 6:fbaee888e5ea | 1962 | int action = get_action(inputs); |
ajorgih3 | 3:bb6f73642f01 | 1963 | |
ajorgih3 | 3:bb6f73642f01 | 1964 | // 3. Update game -- implement this function: |
ajorgih3 | 6:fbaee888e5ea | 1965 | int result = update_game(action); |
ajorgih3 | 3:bb6f73642f01 | 1966 | |
ajorgih3 | 3:bb6f73642f01 | 1967 | // 3b. Check for game over based on result |
ajorgih3 | 3:bb6f73642f01 | 1968 | // and if so, handle game over -- implement this. |
ajorgih3 | 3:bb6f73642f01 | 1969 | |
ajorgih3 | 3:bb6f73642f01 | 1970 | // 4. Draw screen -- provided: |
ajorgih3 | 6:fbaee888e5ea | 1971 | draw_game(result); |
ajorgih3 | 3:bb6f73642f01 | 1972 | |
ajorgih3 | 3:bb6f73642f01 | 1973 | // Compute update time |
ajorgih3 | 6:fbaee888e5ea | 1974 | t.stop(); |
ajorgih3 | 6:fbaee888e5ea | 1975 | int dt = t.read_ms(); |
ajorgih3 | 6:fbaee888e5ea | 1976 | |
ajorgih3 | 3:bb6f73642f01 | 1977 | // Display and wait |
ajorgih3 | 3:bb6f73642f01 | 1978 | // NOTE: Text is 8 pixels tall |
ajorgih3 | 6:fbaee888e5ea | 1979 | if (dt < 100) wait_ms(100 - dt); |
ajorgih3 | 6:fbaee888e5ea | 1980 | } |
ajorgih3 | 7:7ab2f4b09196 | 1981 | |
ajorgih3 | 3:bb6f73642f01 | 1982 | } |
ajorgih3 | 3:bb6f73642f01 | 1983 | |
DCchico | 1:10330bce85cb | 1984 | // Plays a wavfile |
DCchico | 1:10330bce85cb | 1985 | void playSound(char* wav) |
DCchico | 1:10330bce85cb | 1986 | { |
DCchico | 1:10330bce85cb | 1987 | |
DCchico | 1:10330bce85cb | 1988 | } |