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.
Diff: Engine/Engine.cpp
- Revision:
- 5:a3a9e0417e04
- Parent:
- 4:6353f829c56c
- Child:
- 6:ed553fd191c2
--- a/Engine/Engine.cpp Sun Apr 29 14:59:14 2018 +0000 +++ b/Engine/Engine.cpp Sun Apr 29 18:03:45 2018 +0000 @@ -13,8 +13,8 @@ void Engine::init() // initialise the game parameters { memset(_grid, 0, sizeof(_grid)); - _solid.init(3,5); + _noodles.init(10,10); } void Engine::read_input(Gamepad &pad) @@ -32,6 +32,20 @@ } } } + + if (_gameOver) { + for (int i = 0; i <= 22; i++) { + for (int j = 0; j <= 22; j++) { + lcd.drawRect((2 * i) + 1,(2 * j) + 1,2,2,FILL_BLACK); + wait(0.01); + lcd.refresh(); + } + } + } + + //lcd.printString("Score",45,44); + + // lcd.printString(convertString(_score),45,38); } void Engine::update(Gamepad &pad) @@ -42,7 +56,20 @@ int _l =_solid.getLength(); - for (int i = _l; i >= 1; i--) { - _grid[_solid.getX(i)][_solid.getY(i)] = 1; + for (int i = 0; i < _l; i++) { + if (_grid[_solid.getX(i)][_solid.getY(i)] != 1) { + _grid[_solid.getX(i)][_solid.getY(i)] = 1; + } else { + _gameOver = true; + } + } + + _grid[_noodles.getY()][_noodles.getY()] = 2; + + if (_grid[_solid.getX(0)][_solid.getY(0)] == 2) { + if (_solid.getLength()<100) { + _solid.grow(); + } } } +