
Final Commit
Dependencies: mbed
Diff: SnakeEngine/SnakeEngine.cpp
- Revision:
- 26:23301f48c1ed
- Parent:
- 25:f03439ee32c6
--- a/SnakeEngine/SnakeEngine.cpp Tue May 08 10:52:12 2018 +0000 +++ b/SnakeEngine/SnakeEngine.cpp Tue May 08 11:51:03 2018 +0000 @@ -50,15 +50,14 @@ void SnakeEngine::update(Gamepad &pad) { bool food_col; - //bool wall_collsion; int food_spawn_time; ++g_engine_fc; increase_speed(5, 1.1); - food_spawn_time = food_spawning_time(5); + food_spawn_time = food_spawning_time(3); _snake.update(_in, _cur); - //_n_frames = 150; - //printf("Spawn time %i \n", food_spawn_time); + printf("Spawn time %i \n", food_spawn_time); + // printf("Frame Time %i \n", g_ft); _food.update(_collision, food_spawn_time); food_col = detect_food_collision(pad); @@ -74,14 +73,21 @@ void SnakeEngine::draw(N5110 &lcd) { - // puts fram around the game area + // puts frame around the game area lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); lcd.setContrast(0.5); - //_food.update(_collision); + // draws food to lcd + _food.draw(lcd); + + // draws snake head to lcd + _snake.draw(lcd); + + // draws snake tail to lcd + draw_tail(lcd); } @@ -318,10 +324,17 @@ { int c = 0; + + // c is equal to the tail length - an incrementer such that c is never more + // than 0 and n = frame decremtner away from 0 such that the logic + // c == 0 works + c = g_tl - g_n; //printf("C = %i", c); + // the frame periodity must be more than 100 to ensure the game reamains playable + if((c == 0) && (g_ft > 100)) { g_n = g_n + frame_decrementer;