![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Adam Baker 201166301
Dependencies: mbed Gamepad N5110
BlockheadEngine/BlockheadEngine.cpp@38:51ed5820ffe5, 2019-05-06 (annotated)
- Committer:
- adambakerwa
- Date:
- Mon May 06 14:08:31 2019 +0000
- Revision:
- 38:51ed5820ffe5
- Parent:
- 36:6f452777b9ce
- Child:
- 42:0dad7c359fa5
commenting and doxygen work
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adambakerwa | 25:230e4163cb6b | 1 | #include "mbed.h" |
adambakerwa | 25:230e4163cb6b | 2 | #include "Gamepad.h" |
adambakerwa | 25:230e4163cb6b | 3 | #include "N5110.h" |
adambakerwa | 25:230e4163cb6b | 4 | #include "BlockheadEngine.h" |
adambakerwa | 25:230e4163cb6b | 5 | |
adambakerwa | 38:51ed5820ffe5 | 6 | //nothing needed doing in constructor or deconstructor |
adambakerwa | 25:230e4163cb6b | 7 | BlockheadEngine::BlockheadEngine() |
adambakerwa | 25:230e4163cb6b | 8 | { |
adambakerwa | 25:230e4163cb6b | 9 | |
adambakerwa | 25:230e4163cb6b | 10 | } |
adambakerwa | 25:230e4163cb6b | 11 | |
adambakerwa | 25:230e4163cb6b | 12 | BlockheadEngine::~BlockheadEngine() |
adambakerwa | 25:230e4163cb6b | 13 | { |
adambakerwa | 25:230e4163cb6b | 14 | |
adambakerwa | 25:230e4163cb6b | 15 | } |
adambakerwa | 25:230e4163cb6b | 16 | |
adambakerwa | 38:51ed5820ffe5 | 17 | void BlockheadEngine::init() //intialise all variables for new game |
adambakerwa | 26:3319ddd5111d | 18 | { |
adambakerwa | 38:51ed5820ffe5 | 19 | _blockhead.init(); //intialise variables in blockhead class |
adambakerwa | 38:51ed5820ffe5 | 20 | _pos = _lev.init(_pos); //intialise variables in level class and _pos struct |
adambakerwa | 28:934bb0da48ab | 21 | |
adambakerwa | 27:c0fa8e41743b | 22 | |
adambakerwa | 26:3319ddd5111d | 23 | } |
adambakerwa | 26:3319ddd5111d | 24 | |
adambakerwa | 38:51ed5820ffe5 | 25 | void BlockheadEngine::continueInit() //intialise all variables for continue game |
adambakerwa | 31:bf765e3961f1 | 26 | { |
adambakerwa | 38:51ed5820ffe5 | 27 | _blockhead.continue_init(); //level not intialised and x/y cordinate of blockhead differs dpending on what level you are on |
adambakerwa | 38:51ed5820ffe5 | 28 | _pos = _lev.init(_pos); //initialise variables in level class and _pos struct |
adambakerwa | 31:bf765e3961f1 | 29 | |
adambakerwa | 31:bf765e3961f1 | 30 | |
adambakerwa | 31:bf765e3961f1 | 31 | } |
adambakerwa | 31:bf765e3961f1 | 32 | |
adambakerwa | 38:51ed5820ffe5 | 33 | int BlockheadEngine::playgame(N5110 &lcd, Gamepad &pad) //runs the game 'blockhead' |
adambakerwa | 25:230e4163cb6b | 34 | { |
adambakerwa | 38:51ed5820ffe5 | 35 | lcd.clear(); //clear lcd first |
adambakerwa | 36:6f452777b9ce | 36 | |
adambakerwa | 38:51ed5820ffe5 | 37 | _level = _blockhead.next_level(); //returns what level blockhead is on |
adambakerwa | 38:51ed5820ffe5 | 38 | _pos = _lev.whatLevel(lcd, _level); //displays that level on lcd, as well as passes cordinates of moving platforms and spikes to _pos structs |
adambakerwa | 38:51ed5820ffe5 | 39 | _blockhead.blockhead(_pos, lcd, pad); //controlls blcokhead depending on position in game, |
adambakerwa | 38:51ed5820ffe5 | 40 | _gameover = _blockhead.gameover_flag(pad); //_gameover = 1 once blockhead dies |
adambakerwa | 36:6f452777b9ce | 41 | |
adambakerwa | 38:51ed5820ffe5 | 42 | lcd.refresh(); //updates screen |
adambakerwa | 25:230e4163cb6b | 43 | |
adambakerwa | 38:51ed5820ffe5 | 44 | return _gameover; //returns _gameover |
adambakerwa | 25:230e4163cb6b | 45 | } |
adambakerwa | 25:230e4163cb6b | 46 | |
adambakerwa | 36:6f452777b9ce | 47 | int BlockheadEngine::highscore() |
adambakerwa | 36:6f452777b9ce | 48 | { |
adambakerwa | 38:51ed5820ffe5 | 49 | if (_level >= _highscore) { //if level reached is higher than current highscore |
adambakerwa | 38:51ed5820ffe5 | 50 | _highscore = _level; //then _highscore = _level |
adambakerwa | 36:6f452777b9ce | 51 | } |
adambakerwa | 36:6f452777b9ce | 52 | |
adambakerwa | 38:51ed5820ffe5 | 53 | return _highscore; //returns _highscore |
adambakerwa | 36:6f452777b9ce | 54 | } |
adambakerwa | 36:6f452777b9ce | 55 |