ELEC2645 (2018/19) / Mbed 2 deprecated el17apb

Dependencies:   mbed Gamepad N5110

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BlockheadEngine.cpp Source File

BlockheadEngine.cpp

00001 #include "mbed.h"
00002 #include "Gamepad.h"
00003 #include "N5110.h"
00004 #include "BlockheadEngine.h"
00005 
00006 //nothing needed doing in constructor or deconstructor 
00007 BlockheadEngine::BlockheadEngine()
00008 {
00009 
00010 }
00011 
00012 BlockheadEngine::~BlockheadEngine()
00013 {
00014 
00015 }
00016 
00017 
00018 //intialise all variables for new game
00019 void BlockheadEngine::init()                                        
00020 {
00021     _blockhead.init();                                              //intialise variables in blockhead class
00022     _pos = _lev.init(_pos);                                         //intialise variables in level class and _pos struct
00023     
00024 
00025 }
00026 
00027 
00028 //intialise all variables for continue game 
00029 void BlockheadEngine::continue_init()                                
00030 {
00031     _blockhead.continue_init();                                     //level not intialised and x/y cordinate of blockhead differs dpending on what level you are on
00032     _pos = _lev.init(_pos);                                         //initialise variables in level class and _pos struct
00033     
00034 
00035 }
00036 
00037 
00038 //runs the game 'blockhead'
00039 int BlockheadEngine::playgame(N5110 &lcd, Gamepad &pad)             
00040 {
00041     lcd.clear();                                                    //clear lcd first
00042     
00043     _level = _blockhead.next_level();                               //returns what level blockhead is on
00044     _pos = _lev.what_level(lcd, _level);                             //displays that level on lcd, as well as passes cordinates of moving platforms and spikes to _pos structs
00045     _blockhead.blockhead(_pos, lcd, pad);                           //controlls blcokhead depending on position in game,
00046     _gameover = _blockhead.gameover_flag(pad);                      //_gameover = 1 once blockhead dies
00047     
00048     lcd.refresh();                                                  //updates screen
00049 
00050     return _gameover;                                               //returns _gameover
00051 }
00052 
00053 
00054 //returns highscore (the highest level reached by user)
00055 int BlockheadEngine::highscore()
00056 {   
00057     if (_level >= _highscore) {                                     //if level reached is higher than current highscore
00058         _highscore = _level;                                        //then _highscore = _level
00059     }
00060 
00061     return _highscore;                                              //returns _highscore
00062 }
00063