
Final Commit
Dependencies: mbed
SnakeEngine/SnakeEngine.cpp@25:f03439ee32c6, 2018-05-08 (annotated)
- Committer:
- JRM1986
- Date:
- Tue May 08 10:52:12 2018 +0000
- Revision:
- 25:f03439ee32c6
- Parent:
- 24:4b180348826e
- Child:
- 26:23301f48c1ed
Tidying up 1;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JRM1986 | 2:ea90cec2489a | 1 | #include "SnakeEngine.h" |
JRM1986 | 2:ea90cec2489a | 2 | |
JRM1986 | 25:f03439ee32c6 | 3 | ///////////////// constructor/destructor ///////////////// |
JRM1986 | 2:ea90cec2489a | 4 | |
JRM1986 | 2:ea90cec2489a | 5 | SnakeEngine::SnakeEngine() |
JRM1986 | 2:ea90cec2489a | 6 | { |
JRM1986 | 2:ea90cec2489a | 7 | |
JRM1986 | 2:ea90cec2489a | 8 | } |
JRM1986 | 2:ea90cec2489a | 9 | |
JRM1986 | 2:ea90cec2489a | 10 | SnakeEngine::~SnakeEngine() |
JRM1986 | 2:ea90cec2489a | 11 | { |
JRM1986 | 2:ea90cec2489a | 12 | |
JRM1986 | 7:c38800a428a6 | 13 | } |
JRM1986 | 23:3081be418c89 | 14 | ///////////////// global methods ///////////////// |
JRM1986 | 17:94dd8a691d4a | 15 | |
JRM1986 | 16:85ca9feccf3f | 16 | int g_tail_length() |
JRM1986 | 16:85ca9feccf3f | 17 | { |
JRM1986 | 16:85ca9feccf3f | 18 | |
JRM1986 | 16:85ca9feccf3f | 19 | extern int g_tl; |
JRM1986 | 16:85ca9feccf3f | 20 | |
JRM1986 | 16:85ca9feccf3f | 21 | return g_tl; |
JRM1986 | 16:85ca9feccf3f | 22 | |
JRM1986 | 16:85ca9feccf3f | 23 | } |
JRM1986 | 16:85ca9feccf3f | 24 | |
JRM1986 | 25:f03439ee32c6 | 25 | void g_frame_time(int frame_time) |
JRM1986 | 25:f03439ee32c6 | 26 | { |
JRM1986 | 25:f03439ee32c6 | 27 | |
JRM1986 | 25:f03439ee32c6 | 28 | g_ft = frame_time; |
JRM1986 | 25:f03439ee32c6 | 29 | |
JRM1986 | 25:f03439ee32c6 | 30 | } |
JRM1986 | 25:f03439ee32c6 | 31 | |
JRM1986 | 17:94dd8a691d4a | 32 | |
JRM1986 | 24:4b180348826e | 33 | ///////////////// public methods ///////////////// |
JRM1986 | 24:4b180348826e | 34 | |
JRM1986 | 25:f03439ee32c6 | 35 | void SnakeEngine::init(Direction in, Direction cur, int snake_pos_x, int snake_pos_y, int n_frames) |
JRM1986 | 7:c38800a428a6 | 36 | { |
JRM1986 | 20:277e88a8185f | 37 | _snake_pos_x = snake_pos_x; |
JRM1986 | 20:277e88a8185f | 38 | _snake_pos_y = snake_pos_y; |
JRM1986 | 20:277e88a8185f | 39 | _in = in; |
JRM1986 | 20:277e88a8185f | 40 | _cur = cur; |
JRM1986 | 25:f03439ee32c6 | 41 | _n_frames = n_frames; |
JRM1986 | 25:f03439ee32c6 | 42 | g_frame_time(_n_frames); |
JRM1986 | 18:406fc298a7c4 | 43 | |
JRM1986 | 20:277e88a8185f | 44 | _snake.init(_in, _cur, _snake_pos_x, _snake_pos_y); |
JRM1986 | 20:277e88a8185f | 45 | |
JRM1986 | 18:406fc298a7c4 | 46 | _food.init(true); |
JRM1986 | 9:561e5681b7a6 | 47 | |
JRM1986 | 8:a2b431b9b3f7 | 48 | } |
JRM1986 | 8:a2b431b9b3f7 | 49 | |
JRM1986 | 10:62d8cb7742c3 | 50 | void SnakeEngine::update(Gamepad &pad) |
JRM1986 | 10:62d8cb7742c3 | 51 | { |
JRM1986 | 16:85ca9feccf3f | 52 | bool food_col; |
JRM1986 | 25:f03439ee32c6 | 53 | //bool wall_collsion; |
JRM1986 | 25:f03439ee32c6 | 54 | int food_spawn_time; |
JRM1986 | 17:94dd8a691d4a | 55 | ++g_engine_fc; |
JRM1986 | 17:94dd8a691d4a | 56 | |
JRM1986 | 25:f03439ee32c6 | 57 | increase_speed(5, 1.1); |
JRM1986 | 25:f03439ee32c6 | 58 | food_spawn_time = food_spawning_time(5); |
JRM1986 | 25:f03439ee32c6 | 59 | _snake.update(_in, _cur); |
JRM1986 | 25:f03439ee32c6 | 60 | //_n_frames = 150; |
JRM1986 | 25:f03439ee32c6 | 61 | //printf("Spawn time %i \n", food_spawn_time); |
JRM1986 | 10:62d8cb7742c3 | 62 | |
JRM1986 | 25:f03439ee32c6 | 63 | _food.update(_collision, food_spawn_time); |
JRM1986 | 16:85ca9feccf3f | 64 | food_col = detect_food_collision(pad); |
JRM1986 | 18:406fc298a7c4 | 65 | _collision = food_col; |
JRM1986 | 16:85ca9feccf3f | 66 | set_tail_length(food_col); |
JRM1986 | 17:94dd8a691d4a | 67 | set_tail_array(pad); |
JRM1986 | 25:f03439ee32c6 | 68 | g_wall = detect_wall_collision(pad); |
JRM1986 | 25:f03439ee32c6 | 69 | //printf("%i%", g_wall); |
JRM1986 | 10:62d8cb7742c3 | 70 | |
JRM1986 | 10:62d8cb7742c3 | 71 | } |
JRM1986 | 10:62d8cb7742c3 | 72 | |
JRM1986 | 10:62d8cb7742c3 | 73 | |
JRM1986 | 8:a2b431b9b3f7 | 74 | void SnakeEngine::draw(N5110 &lcd) |
JRM1986 | 8:a2b431b9b3f7 | 75 | { |
JRM1986 | 8:a2b431b9b3f7 | 76 | |
JRM1986 | 24:4b180348826e | 77 | // puts fram around the game area |
JRM1986 | 24:4b180348826e | 78 | |
JRM1986 | 8:a2b431b9b3f7 | 79 | lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); |
JRM1986 | 8:a2b431b9b3f7 | 80 | lcd.setContrast(0.5); |
JRM1986 | 24:4b180348826e | 81 | |
JRM1986 | 25:f03439ee32c6 | 82 | //_food.update(_collision); |
JRM1986 | 8:a2b431b9b3f7 | 83 | _food.draw(lcd); |
JRM1986 | 10:62d8cb7742c3 | 84 | _snake.draw(lcd); |
JRM1986 | 17:94dd8a691d4a | 85 | draw_tail(lcd); |
JRM1986 | 9:561e5681b7a6 | 86 | |
JRM1986 | 16:85ca9feccf3f | 87 | } |
JRM1986 | 16:85ca9feccf3f | 88 | |
JRM1986 | 24:4b180348826e | 89 | |
JRM1986 | 24:4b180348826e | 90 | void SnakeEngine::draw_tail(N5110 &lcd) |
JRM1986 | 24:4b180348826e | 91 | { |
JRM1986 | 24:4b180348826e | 92 | int length = g_tl; |
JRM1986 | 24:4b180348826e | 93 | int c; |
JRM1986 | 24:4b180348826e | 94 | c = g_engine_fc % 2; |
JRM1986 | 24:4b180348826e | 95 | int i; |
JRM1986 | 24:4b180348826e | 96 | int x; |
JRM1986 | 24:4b180348826e | 97 | int y; |
JRM1986 | 24:4b180348826e | 98 | |
JRM1986 | 24:4b180348826e | 99 | //printf("Odd/Even %i \n", c); |
JRM1986 | 24:4b180348826e | 100 | |
JRM1986 | 24:4b180348826e | 101 | // runs through each segment in the tail and draws to the lcd |
JRM1986 | 24:4b180348826e | 102 | |
JRM1986 | 24:4b180348826e | 103 | for(i=0; i<=length; ++i) { |
JRM1986 | 24:4b180348826e | 104 | |
JRM1986 | 24:4b180348826e | 105 | // when odd draw odd array |
JRM1986 | 24:4b180348826e | 106 | |
JRM1986 | 24:4b180348826e | 107 | if(c == 1) { |
JRM1986 | 24:4b180348826e | 108 | |
JRM1986 | 24:4b180348826e | 109 | x = g_odd_array_x[i]; |
JRM1986 | 24:4b180348826e | 110 | y = g_odd_array_y[i]; |
JRM1986 | 24:4b180348826e | 111 | |
JRM1986 | 24:4b180348826e | 112 | lcd.setPixel(x,y,true); |
JRM1986 | 24:4b180348826e | 113 | |
JRM1986 | 24:4b180348826e | 114 | } |
JRM1986 | 24:4b180348826e | 115 | |
JRM1986 | 24:4b180348826e | 116 | // when even draw the even array |
JRM1986 | 24:4b180348826e | 117 | |
JRM1986 | 24:4b180348826e | 118 | else if (c == 0) { |
JRM1986 | 24:4b180348826e | 119 | |
JRM1986 | 24:4b180348826e | 120 | x = g_even_array_x[i]; |
JRM1986 | 24:4b180348826e | 121 | y = g_even_array_y[i]; |
JRM1986 | 24:4b180348826e | 122 | |
JRM1986 | 24:4b180348826e | 123 | lcd.setPixel(x,y,true); |
JRM1986 | 24:4b180348826e | 124 | |
JRM1986 | 24:4b180348826e | 125 | } |
JRM1986 | 24:4b180348826e | 126 | |
JRM1986 | 24:4b180348826e | 127 | } |
JRM1986 | 24:4b180348826e | 128 | } |
JRM1986 | 24:4b180348826e | 129 | |
JRM1986 | 24:4b180348826e | 130 | |
JRM1986 | 24:4b180348826e | 131 | void SnakeEngine::get_input(Gamepad &pad) |
JRM1986 | 24:4b180348826e | 132 | { |
JRM1986 | 24:4b180348826e | 133 | |
JRM1986 | 24:4b180348826e | 134 | _in = pad.get_direction(); |
JRM1986 | 24:4b180348826e | 135 | |
JRM1986 | 24:4b180348826e | 136 | } |
JRM1986 | 24:4b180348826e | 137 | |
JRM1986 | 16:85ca9feccf3f | 138 | bool SnakeEngine::detect_food_collision(Gamepad &pad) |
JRM1986 | 16:85ca9feccf3f | 139 | { |
JRM1986 | 16:85ca9feccf3f | 140 | Vector2D snake_pos = _snake.get_snake_position(); |
JRM1986 | 16:85ca9feccf3f | 141 | Vector2D food_pos = _food.get_food_position(); |
JRM1986 | 16:85ca9feccf3f | 142 | |
JRM1986 | 16:85ca9feccf3f | 143 | bool success_flag = false; |
JRM1986 | 16:85ca9feccf3f | 144 | |
JRM1986 | 24:4b180348826e | 145 | // when the position of the head and food are the same return true |
JRM1986 | 24:4b180348826e | 146 | |
JRM1986 | 16:85ca9feccf3f | 147 | if((snake_pos.x == food_pos.x) && (snake_pos.y == food_pos.y)) { |
JRM1986 | 16:85ca9feccf3f | 148 | |
JRM1986 | 16:85ca9feccf3f | 149 | success_flag = true; |
JRM1986 | 16:85ca9feccf3f | 150 | |
JRM1986 | 16:85ca9feccf3f | 151 | } |
JRM1986 | 16:85ca9feccf3f | 152 | |
JRM1986 | 16:85ca9feccf3f | 153 | else { |
JRM1986 | 16:85ca9feccf3f | 154 | |
JRM1986 | 16:85ca9feccf3f | 155 | success_flag = false; |
JRM1986 | 16:85ca9feccf3f | 156 | |
JRM1986 | 16:85ca9feccf3f | 157 | } |
JRM1986 | 16:85ca9feccf3f | 158 | |
JRM1986 | 16:85ca9feccf3f | 159 | return success_flag; |
JRM1986 | 16:85ca9feccf3f | 160 | |
JRM1986 | 16:85ca9feccf3f | 161 | } |
JRM1986 | 19:b437806e579b | 162 | bool SnakeEngine::detect_wall_collision(Gamepad &pad) |
JRM1986 | 19:b437806e579b | 163 | { |
JRM1986 | 19:b437806e579b | 164 | |
JRM1986 | 19:b437806e579b | 165 | Vector2D snake_pos = _snake.get_snake_position(); |
JRM1986 | 19:b437806e579b | 166 | |
JRM1986 | 19:b437806e579b | 167 | bool success_flag = false; |
JRM1986 | 19:b437806e579b | 168 | |
JRM1986 | 24:4b180348826e | 169 | // when an snake position is at an edge return true |
JRM1986 | 24:4b180348826e | 170 | |
JRM1986 | 19:b437806e579b | 171 | if((snake_pos.x == (0 || 84)) || (snake_pos.y == (0 || 48))) { |
JRM1986 | 19:b437806e579b | 172 | |
JRM1986 | 19:b437806e579b | 173 | success_flag = true; |
JRM1986 | 19:b437806e579b | 174 | |
JRM1986 | 19:b437806e579b | 175 | } |
JRM1986 | 19:b437806e579b | 176 | |
JRM1986 | 19:b437806e579b | 177 | return success_flag; |
JRM1986 | 19:b437806e579b | 178 | |
JRM1986 | 19:b437806e579b | 179 | } |
JRM1986 | 19:b437806e579b | 180 | |
JRM1986 | 19:b437806e579b | 181 | |
JRM1986 | 16:85ca9feccf3f | 182 | void SnakeEngine::set_tail_length(bool collision_detected) |
JRM1986 | 16:85ca9feccf3f | 183 | { |
JRM1986 | 24:4b180348826e | 184 | // when a collision is detected increment the tail length |
JRM1986 | 16:85ca9feccf3f | 185 | |
JRM1986 | 16:85ca9feccf3f | 186 | if(collision_detected) { |
JRM1986 | 16:85ca9feccf3f | 187 | |
JRM1986 | 16:85ca9feccf3f | 188 | ++g_tl; |
JRM1986 | 16:85ca9feccf3f | 189 | |
JRM1986 | 16:85ca9feccf3f | 190 | } |
JRM1986 | 16:85ca9feccf3f | 191 | |
JRM1986 | 16:85ca9feccf3f | 192 | else { |
JRM1986 | 16:85ca9feccf3f | 193 | |
JRM1986 | 16:85ca9feccf3f | 194 | g_tl = g_tl; |
JRM1986 | 16:85ca9feccf3f | 195 | |
JRM1986 | 16:85ca9feccf3f | 196 | } |
JRM1986 | 16:85ca9feccf3f | 197 | |
JRM1986 | 16:85ca9feccf3f | 198 | } |
JRM1986 | 16:85ca9feccf3f | 199 | |
JRM1986 | 16:85ca9feccf3f | 200 | int SnakeEngine::get_tail_length() |
JRM1986 | 16:85ca9feccf3f | 201 | { |
JRM1986 | 16:85ca9feccf3f | 202 | |
JRM1986 | 16:85ca9feccf3f | 203 | int length = g_tl; |
JRM1986 | 16:85ca9feccf3f | 204 | |
JRM1986 | 16:85ca9feccf3f | 205 | return length; |
JRM1986 | 16:85ca9feccf3f | 206 | |
JRM1986 | 16:85ca9feccf3f | 207 | } |
JRM1986 | 24:4b180348826e | 208 | |
JRM1986 | 24:4b180348826e | 209 | void SnakeEngine::set_odd_array(Gamepad &pad) |
JRM1986 | 24:4b180348826e | 210 | { |
JRM1986 | 24:4b180348826e | 211 | |
JRM1986 | 24:4b180348826e | 212 | int i; |
JRM1986 | 24:4b180348826e | 213 | int length = g_tl; |
JRM1986 | 24:4b180348826e | 214 | |
JRM1986 | 24:4b180348826e | 215 | extern int g_even_array_x[100]; |
JRM1986 | 24:4b180348826e | 216 | extern int g_even_array_y[100]; |
JRM1986 | 24:4b180348826e | 217 | |
JRM1986 | 24:4b180348826e | 218 | Vector2D pos = _snake.get_snake_position(); |
JRM1986 | 24:4b180348826e | 219 | |
JRM1986 | 24:4b180348826e | 220 | // sets the first value in the array to the new position |
JRM1986 | 24:4b180348826e | 221 | |
JRM1986 | 24:4b180348826e | 222 | g_even_array_x[0] = pos.x; |
JRM1986 | 24:4b180348826e | 223 | g_even_array_y[0] = pos.y; |
JRM1986 | 24:4b180348826e | 224 | |
JRM1986 | 24:4b180348826e | 225 | // starting from the last element in the arrays work back to zero |
JRM1986 | 24:4b180348826e | 226 | |
JRM1986 | 24:4b180348826e | 227 | for(i = length; i >= 0; --i) { |
JRM1986 | 24:4b180348826e | 228 | |
JRM1986 | 24:4b180348826e | 229 | // switch positions of the indexes adding the new head position |
JRM1986 | 24:4b180348826e | 230 | |
JRM1986 | 24:4b180348826e | 231 | if(i > 0) { |
JRM1986 | 24:4b180348826e | 232 | |
JRM1986 | 24:4b180348826e | 233 | g_odd_array_x[i] = g_even_array_x[i-1]; |
JRM1986 | 24:4b180348826e | 234 | g_odd_array_y[i] = g_even_array_y[i-1]; |
JRM1986 | 24:4b180348826e | 235 | |
JRM1986 | 24:4b180348826e | 236 | } |
JRM1986 | 24:4b180348826e | 237 | |
JRM1986 | 24:4b180348826e | 238 | // when snake has no length position 0 is the new position |
JRM1986 | 24:4b180348826e | 239 | |
JRM1986 | 24:4b180348826e | 240 | else if(i == 0) { |
JRM1986 | 24:4b180348826e | 241 | |
JRM1986 | 24:4b180348826e | 242 | g_odd_array_x[0] = pos.x; |
JRM1986 | 24:4b180348826e | 243 | g_odd_array_y[0] = pos.y; |
JRM1986 | 24:4b180348826e | 244 | |
JRM1986 | 24:4b180348826e | 245 | } |
JRM1986 | 24:4b180348826e | 246 | |
JRM1986 | 24:4b180348826e | 247 | } |
JRM1986 | 24:4b180348826e | 248 | |
JRM1986 | 24:4b180348826e | 249 | } |
JRM1986 | 24:4b180348826e | 250 | |
JRM1986 | 24:4b180348826e | 251 | void SnakeEngine::set_even_array(Gamepad &pad) |
JRM1986 | 24:4b180348826e | 252 | { |
JRM1986 | 24:4b180348826e | 253 | |
JRM1986 | 24:4b180348826e | 254 | int i; |
JRM1986 | 24:4b180348826e | 255 | int length = g_tl; |
JRM1986 | 24:4b180348826e | 256 | |
JRM1986 | 24:4b180348826e | 257 | extern int g_odd_array_x[100]; |
JRM1986 | 24:4b180348826e | 258 | extern int g_odd_array_y[100]; |
JRM1986 | 24:4b180348826e | 259 | |
JRM1986 | 24:4b180348826e | 260 | Vector2D pos = _snake.get_snake_position(); |
JRM1986 | 24:4b180348826e | 261 | |
JRM1986 | 24:4b180348826e | 262 | // sets the first value in the array to the new position |
JRM1986 | 24:4b180348826e | 263 | |
JRM1986 | 24:4b180348826e | 264 | g_odd_array_x[0] = pos.x; |
JRM1986 | 24:4b180348826e | 265 | g_odd_array_y[0] = pos.y; |
JRM1986 | 24:4b180348826e | 266 | |
JRM1986 | 24:4b180348826e | 267 | // starting from the last element in the arrays work back to zero |
JRM1986 | 24:4b180348826e | 268 | |
JRM1986 | 24:4b180348826e | 269 | for(i = length; i >= 0; --i) { |
JRM1986 | 24:4b180348826e | 270 | |
JRM1986 | 24:4b180348826e | 271 | // switch positions of the indexes adding the new head position |
JRM1986 | 24:4b180348826e | 272 | |
JRM1986 | 24:4b180348826e | 273 | if(i > 0) { |
JRM1986 | 24:4b180348826e | 274 | |
JRM1986 | 24:4b180348826e | 275 | g_even_array_x[i] = g_odd_array_x[i-1]; |
JRM1986 | 24:4b180348826e | 276 | g_even_array_y[i] = g_odd_array_y[i-1]; |
JRM1986 | 24:4b180348826e | 277 | |
JRM1986 | 24:4b180348826e | 278 | } |
JRM1986 | 24:4b180348826e | 279 | |
JRM1986 | 24:4b180348826e | 280 | // when snake has no length position 0 is the new position |
JRM1986 | 24:4b180348826e | 281 | |
JRM1986 | 24:4b180348826e | 282 | else if(i == 0) { |
JRM1986 | 24:4b180348826e | 283 | |
JRM1986 | 24:4b180348826e | 284 | g_even_array_x[0] = pos.x; |
JRM1986 | 24:4b180348826e | 285 | g_even_array_y[0] = pos.y; |
JRM1986 | 24:4b180348826e | 286 | |
JRM1986 | 24:4b180348826e | 287 | } |
JRM1986 | 24:4b180348826e | 288 | |
JRM1986 | 24:4b180348826e | 289 | } |
JRM1986 | 24:4b180348826e | 290 | |
JRM1986 | 24:4b180348826e | 291 | } |
JRM1986 | 24:4b180348826e | 292 | |
JRM1986 | 24:4b180348826e | 293 | |
JRM1986 | 24:4b180348826e | 294 | void SnakeEngine::set_tail_array(Gamepad &pad) |
JRM1986 | 24:4b180348826e | 295 | { |
JRM1986 | 24:4b180348826e | 296 | |
JRM1986 | 24:4b180348826e | 297 | int c = g_engine_fc % 2; |
JRM1986 | 24:4b180348826e | 298 | |
JRM1986 | 24:4b180348826e | 299 | // when the frame counter is odd set odd array |
JRM1986 | 24:4b180348826e | 300 | |
JRM1986 | 24:4b180348826e | 301 | if(c == 1) { |
JRM1986 | 24:4b180348826e | 302 | |
JRM1986 | 24:4b180348826e | 303 | set_odd_array(pad); |
JRM1986 | 24:4b180348826e | 304 | |
JRM1986 | 24:4b180348826e | 305 | } |
JRM1986 | 24:4b180348826e | 306 | |
JRM1986 | 24:4b180348826e | 307 | // when the frame counter is even set even array |
JRM1986 | 24:4b180348826e | 308 | |
JRM1986 | 24:4b180348826e | 309 | else if (c == 0) { |
JRM1986 | 24:4b180348826e | 310 | |
JRM1986 | 24:4b180348826e | 311 | set_even_array(pad); |
JRM1986 | 24:4b180348826e | 312 | |
JRM1986 | 24:4b180348826e | 313 | } |
JRM1986 | 24:4b180348826e | 314 | |
JRM1986 | 24:4b180348826e | 315 | } |
JRM1986 | 24:4b180348826e | 316 | |
JRM1986 | 25:f03439ee32c6 | 317 | int SnakeEngine::food_spawning_time(int frame_decrementer) |
JRM1986 | 25:f03439ee32c6 | 318 | { |
JRM1986 | 25:f03439ee32c6 | 319 | |
JRM1986 | 25:f03439ee32c6 | 320 | int c = 0; |
JRM1986 | 25:f03439ee32c6 | 321 | c = g_tl - g_n; |
JRM1986 | 25:f03439ee32c6 | 322 | |
JRM1986 | 25:f03439ee32c6 | 323 | //printf("C = %i", c); |
JRM1986 | 25:f03439ee32c6 | 324 | |
JRM1986 | 25:f03439ee32c6 | 325 | if((c == 0) && (g_ft > 100)) { |
JRM1986 | 25:f03439ee32c6 | 326 | |
JRM1986 | 25:f03439ee32c6 | 327 | g_n = g_n + frame_decrementer; |
JRM1986 | 25:f03439ee32c6 | 328 | |
JRM1986 | 25:f03439ee32c6 | 329 | g_ft -= 10; |
JRM1986 | 25:f03439ee32c6 | 330 | |
JRM1986 | 25:f03439ee32c6 | 331 | frame_decrementer += frame_decrementer; |
JRM1986 | 25:f03439ee32c6 | 332 | |
JRM1986 | 25:f03439ee32c6 | 333 | } |
JRM1986 | 25:f03439ee32c6 | 334 | |
JRM1986 | 25:f03439ee32c6 | 335 | return g_ft; |
JRM1986 | 25:f03439ee32c6 | 336 | |
JRM1986 | 25:f03439ee32c6 | 337 | } |
JRM1986 | 25:f03439ee32c6 | 338 | |
JRM1986 | 25:f03439ee32c6 | 339 | void SnakeEngine::increase_speed(int resetter, float speed_decrementer) |
JRM1986 | 25:f03439ee32c6 | 340 | { |
JRM1986 | 25:f03439ee32c6 | 341 | |
JRM1986 | 25:f03439ee32c6 | 342 | int c = 0; |
JRM1986 | 25:f03439ee32c6 | 343 | c = g_tl - g_n; |
JRM1986 | 25:f03439ee32c6 | 344 | if(g_tl == 0) { |
JRM1986 | 25:f03439ee32c6 | 345 | |
JRM1986 | 25:f03439ee32c6 | 346 | g_speed = 0.4; |
JRM1986 | 16:85ca9feccf3f | 347 | |
JRM1986 | 25:f03439ee32c6 | 348 | } |
JRM1986 | 25:f03439ee32c6 | 349 | |
JRM1986 | 25:f03439ee32c6 | 350 | if(c == 0) { |
JRM1986 | 25:f03439ee32c6 | 351 | |
JRM1986 | 25:f03439ee32c6 | 352 | g_n = g_n + resetter; |
JRM1986 | 25:f03439ee32c6 | 353 | |
JRM1986 | 25:f03439ee32c6 | 354 | g_speed = g_speed/speed_decrementer; |
JRM1986 | 25:f03439ee32c6 | 355 | |
JRM1986 | 25:f03439ee32c6 | 356 | resetter += resetter; |
JRM1986 | 25:f03439ee32c6 | 357 | |
JRM1986 | 25:f03439ee32c6 | 358 | } |
JRM1986 | 25:f03439ee32c6 | 359 | |
JRM1986 | 25:f03439ee32c6 | 360 | } |
JRM1986 | 25:f03439ee32c6 | 361 |