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:
- 12:d3eef5ea3f43
- Parent:
- 11:b25874e7efe4
- Child:
- 13:81573be8fac6
--- a/Engine/Engine.cpp Mon May 07 00:10:25 2018 +0000 +++ b/Engine/Engine.cpp Mon May 07 18:06:50 2018 +0000 @@ -12,9 +12,100 @@ void Engine::init() // initialise the game parameters { + _solid.init(10,15); + _noodles.init(10,10); + _gameOver = false; + lvlTwo() ; +} +void Engine::setLvl(int _levelToSet) +{ + _lvl = _levelToSet; +} + +void Engine::loadLvl() +{ + if (_lvl == 1) { + lvlOne(); + } + else if (_lvl == 2) { + lvlTwo(); + } + else if (_lvl == 3) { + lvlThree(); + } +} + +void Engine::lvlOne() +{ memset(_grid, 0, sizeof(_grid)); - _solid.init(5,15); - _noodles.init(10,10); +} + +void Engine::lvlTwo() +{ + int _newGrid[22][22] = { + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0}, + {0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0}, + {0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0}, + {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} + }; + + for(int i = 0; i < 22; i++) { + for (int j = 0; j < 22; j++) { + _grid[i][j] = _newGrid[i][j]; + } + } +} + +void Engine::lvlThree() +{ + int _newGrid[22][22] = { + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0}, + {0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0}, + {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} + }; + + for(int i = 0; i < 22; i++) { + for (int j = 0; j < 22; j++) { + _grid[i][j] = _newGrid[i][j]; + } + } } void Engine::read_input(Gamepad &pad) @@ -42,22 +133,22 @@ char buffer1[21]; sprintf(buffer1,"%3d",_score); lcd.printString(buffer1,50,1); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits - - if (_gameOver) { - for (int i = 0; i < 22; i++) { - for (int j = 0; j < 22; j++) { - lcd.drawRect((2 * i) + 3,(2 * j) + 3,2,2,FILL_BLACK); - wait(0.01); - lcd.refresh(); - } +} + +void Engine::gameOverScreen(N5110 &lcd) +{ + for (int i = 0; i < 22; i++) { + for (int j = 0; j < 22; j++) { + lcd.drawRect((2 * i) + 2,(2 * j) + 2,2,2,FILL_BLACK); + wait(0.01); + lcd.refresh(); } } - } void Engine::update(Gamepad &pad) { - memset(_grid, 0, sizeof(_grid)); + loadLvl(); _solid.update(_d); @@ -97,7 +188,14 @@ } } -int Engine::getScore(){ +int Engine::getScore() +{ return _score; - } +} + +bool Engine::getGameOver() +{ + return _gameOver; +} +