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
Diff: Snake_engine/Snake_engine.cpp
- Revision:
- 12:d45bc5d878ad
- Parent:
- 10:946a3835a7c7
--- a/Snake_engine/Snake_engine.cpp Thu May 03 23:53:58 2018 +0000 +++ b/Snake_engine/Snake_engine.cpp Fri May 04 13:25:18 2018 +0000 @@ -0,0 +1,69 @@ +#include "Snake_engine.h" + +snake_engine::snake_engine() +{ + +} + +snake_engine::~snake_engine() +{ + + + +} + +void snakengine::init() +{ + s.init(); + +} + +void snakengine::draw(N5110 &lcd) +{ + lcd.refresh(); + lcd.clear(); + lcd.drawRect(0,8,WIDTH ,HEIGHT -8,FILL_TRANSPARENT); + + s.draw(lcd); + f.draw(lcd); + printscore(lcd); +} + +void snakengine::update(Gamepad &pad, N5110 &lcd) +{ + s.update(_d,_mag); + + if(getfruit(pad)) { + f.update(); + s.add_score(); + + } +} + + +bool snakengine::getftuit(Gamepad &pad) +{ + Vector2D _f_pos = f.get_pos(); + Vector2D _s_pos = s.get_pos(); + if ((_f_pos.y >= _s_pos.y || _f_pos.y == _s_pos.y-1) && + (_f_pos.y <= _s_pos.y || _f_pos.y+1 == _s_pos.y-1) && + (_f_pos.x >= _s_pos.x || _f_pos.x+1 >= _s_pos.x || _f_pos.x+1 >= _s_pos.x ) && + (_f_pos.x <= _s_pos.x || _f_pos.x+1 <= _s_pos.x)) { + return true; + } else { + return false; + } +} + + +void snakengine::print_point(N5110 &lcd) +{ + int print_point = s.get_point(); + char buffer[14]; + sprintf(buffer,"%2d",snakepoint); + lcd.printString(buffer,WIDTH/2 - 40,0); +} + + + +