Doxygen comments added
Dependencies: mbed Gamepad N5110
Scoring/Scoring.cpp
- Committer:
- rafeh
- Date:
- 2019-05-09
- Revision:
- 16:95e3706790e5
- Parent:
- 15:fc6b40fceb4f
File content as of revision 16:95e3706790e5:
#include "Scoring.h" Scoring::Scoring() { } Scoring::~Scoring() { } void Scoring::set_score(int score) { _score=score; } bool Scoring::check_for_highscore(int score,int highscore) { //checks if the score is higher than the highscore _score=score; _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<29)&&((bird_y<(pipe_height)) || ((bird_y+5)>(pipe_height+24))) || (bird_y>43)) { //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); lcd.printString("Press A",0,4); lcd.printString("To Play Again",0,5); while ( pad.check_event(Gamepad::A_PRESSED) == false) { pad.leds_on(); wait(0.1); pad.leds_off(); wait(0.1); lcd.refresh(); } }