Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Gamepad N5110 Joystick
Diff: Game_engine/Game_engine.cpp
- Revision:
- 4:0fc3441556e1
- Parent:
- 3:660de4311976
- Child:
- 5:23a85b16ee54
--- a/Game_engine/Game_engine.cpp Thu May 09 00:19:35 2019 +0000 +++ b/Game_engine/Game_engine.cpp Thu May 09 07:26:07 2019 +0000 @@ -12,6 +12,7 @@ snake.init(); snake.set_food_posX((rand()%(19) + 1) * 4); snake.set_food_posY((rand()%(11) + 1) * 4 - 2); + _body_seg = 1; } void GameEngine::draw(N5110 &lcd) { lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); // Draws screen limits @@ -50,5 +51,15 @@ if(snake.get_snake_posX() == snake.get_food_posX() && snake.get_snake_posY() == snake.get_food_posY()) { snake.set_food_posX((rand()%(19) + 1) * 4); snake.set_food_posY((rand()%(11) + 1) * 4 - 2); + _body_seg = _body_seg + 1; } } +void GameEngine::snake_body(N5110 &lcd) { + _body_posX[0] = snake.get_snake_posX(); + _body_posY[0] = snake.get_snake_posY(); + for (int j = _body_seg; j > 0; j--) { + lcd.drawRect(_body_posX[j],_body_posY[j],4,4,FILL_BLACK); + _body_posX[j] = _body_posX[j-1]; + _body_posY[j] = _body_posY[j-1]; + } +}