Doxygen comments added
Dependencies: mbed Gamepad N5110
Diff: Scoring/Scoring.cpp
- Revision:
- 10:75de0f4da176
- Parent:
- 9:b7a3ec1c7217
- Child:
- 14:9a9ac55616c4
diff -r b7a3ec1c7217 -r 75de0f4da176 Scoring/Scoring.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Scoring/Scoring.cpp Wed May 08 20:59:02 2019 +0000 @@ -0,0 +1,59 @@ +#include "Scoring.h" +Scoring::Scoring() +{ + +} + +Scoring::~Scoring() +{ + +} + + + +void Scoring::set_score(int score) { + _score=score; + } + bool Scoring::check_for_highscore(int highscore) { //checks if the score is higher than the highscore + _highscore=highscore; + if (_score>_highscore) + return true; + else + return false; + } + void Scoring::update_highscore(int highscore) { //updates the highscore + _highscore=highscore; //if a highscore is scored, then a new value for the _highscore is a new value + } + + int Scoring::add_score(int score, int pipe_x,int bird_x,int pipe_width) { //checks if score should be added + if(pipe_x<(bird_x+pipe_width) && pipe_x>(bird_x+pipe_width-2)) { //if the pipes have moved further left of the bird, then score is added + _score=_score+1; + } + return _score; + } + + bool Scoring::check_collisions(int bird_y, int pipe_x, int pipe_height) { //checks for collisions by looking for + if((pipe_x>17 && pipe_x<32)&&((bird_y<(pipe_height-3)) || (bird_y>(pipe_height+26))) || (bird_y>45)) { //overlaps between the bird and the pipe + return true; } //return true if there is a collision + else { + return false; + } + } + + + void Scoring::display_score(N5110 &lcd, Gamepad &pad) { //displays the score and highscore after the player has lost + lcd.clear(); + char score_display[16]; + char highscore_display[20]; + sprintf(score_display,"Score : %d",_score); + lcd.printString(score_display,0,0); + sprintf(highscore_display,"High Score : %d",_highscore); + lcd.printString(highscore_display,1,1); + while ( pad.check_event(Gamepad::A_PRESSED) == false) { + pad.leds_on(); + wait(0.1); + pad.leds_off(); + wait(0.1); + lcd.refresh(); + } + } \ No newline at end of file