Adam Baker 201166301

Dependencies:   mbed Gamepad N5110

Committer:
adambakerwa
Date:
Wed May 08 16:28:13 2019 +0000
Revision:
42:0dad7c359fa5
Parent:
38:51ed5820ffe5
Child:
44:03059810630d
Safety commit before change

Who changed what in which revision?

UserRevisionLine numberNew 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 42:0dad7c359fa5 17
adambakerwa 42:0dad7c359fa5 18 //intialise all variables for new game
adambakerwa 42:0dad7c359fa5 19 void BlockheadEngine::init()
adambakerwa 26:3319ddd5111d 20 {
adambakerwa 38:51ed5820ffe5 21 _blockhead.init(); //intialise variables in blockhead class
adambakerwa 38:51ed5820ffe5 22 _pos = _lev.init(_pos); //intialise variables in level class and _pos struct
adambakerwa 28:934bb0da48ab 23
adambakerwa 27:c0fa8e41743b 24
adambakerwa 26:3319ddd5111d 25 }
adambakerwa 26:3319ddd5111d 26
adambakerwa 42:0dad7c359fa5 27
adambakerwa 42:0dad7c359fa5 28 //intialise all variables for continue game
adambakerwa 42:0dad7c359fa5 29 void BlockheadEngine::continueInit()
adambakerwa 31:bf765e3961f1 30 {
adambakerwa 38:51ed5820ffe5 31 _blockhead.continue_init(); //level not intialised and x/y cordinate of blockhead differs dpending on what level you are on
adambakerwa 38:51ed5820ffe5 32 _pos = _lev.init(_pos); //initialise variables in level class and _pos struct
adambakerwa 31:bf765e3961f1 33
adambakerwa 31:bf765e3961f1 34
adambakerwa 31:bf765e3961f1 35 }
adambakerwa 31:bf765e3961f1 36
adambakerwa 42:0dad7c359fa5 37
adambakerwa 42:0dad7c359fa5 38 //runs the game 'blockhead'
adambakerwa 42:0dad7c359fa5 39 int BlockheadEngine::playgame(N5110 &lcd, Gamepad &pad)
adambakerwa 25:230e4163cb6b 40 {
adambakerwa 38:51ed5820ffe5 41 lcd.clear(); //clear lcd first
adambakerwa 36:6f452777b9ce 42
adambakerwa 38:51ed5820ffe5 43 _level = _blockhead.next_level(); //returns what level blockhead is on
adambakerwa 38:51ed5820ffe5 44 _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 45 _blockhead.blockhead(_pos, lcd, pad); //controlls blcokhead depending on position in game,
adambakerwa 38:51ed5820ffe5 46 _gameover = _blockhead.gameover_flag(pad); //_gameover = 1 once blockhead dies
adambakerwa 36:6f452777b9ce 47
adambakerwa 38:51ed5820ffe5 48 lcd.refresh(); //updates screen
adambakerwa 25:230e4163cb6b 49
adambakerwa 38:51ed5820ffe5 50 return _gameover; //returns _gameover
adambakerwa 25:230e4163cb6b 51 }
adambakerwa 25:230e4163cb6b 52
adambakerwa 42:0dad7c359fa5 53
adambakerwa 42:0dad7c359fa5 54 //returns highscore (the highest level reached by user)
adambakerwa 36:6f452777b9ce 55 int BlockheadEngine::highscore()
adambakerwa 36:6f452777b9ce 56 {
adambakerwa 38:51ed5820ffe5 57 if (_level >= _highscore) { //if level reached is higher than current highscore
adambakerwa 38:51ed5820ffe5 58 _highscore = _level; //then _highscore = _level
adambakerwa 36:6f452777b9ce 59 }
adambakerwa 36:6f452777b9ce 60
adambakerwa 38:51ed5820ffe5 61 return _highscore; //returns _highscore
adambakerwa 36:6f452777b9ce 62 }
adambakerwa 36:6f452777b9ce 63