![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Doxygen comments added
Dependencies: mbed Gamepad N5110
Scoring/Scoring.cpp@10:75de0f4da176, 2019-05-08 (annotated)
- Committer:
- rafeh
- Date:
- Wed May 08 20:59:02 2019 +0000
- Revision:
- 10:75de0f4da176
- Parent:
- FlappyBirdEngine/Scoring.cpp@9:b7a3ec1c7217
- Child:
- 14:9a9ac55616c4
doxygen comments added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rafeh | 9:b7a3ec1c7217 | 1 | #include "Scoring.h" |
rafeh | 10:75de0f4da176 | 2 | Scoring::Scoring() |
rafeh | 10:75de0f4da176 | 3 | { |
rafeh | 10:75de0f4da176 | 4 | |
rafeh | 10:75de0f4da176 | 5 | } |
rafeh | 10:75de0f4da176 | 6 | |
rafeh | 10:75de0f4da176 | 7 | Scoring::~Scoring() |
rafeh | 10:75de0f4da176 | 8 | { |
rafeh | 10:75de0f4da176 | 9 | |
rafeh | 10:75de0f4da176 | 10 | } |
rafeh | 7:05f433e196d6 | 11 | |
rafeh | 7:05f433e196d6 | 12 | |
rafeh | 7:05f433e196d6 | 13 | |
rafeh | 10:75de0f4da176 | 14 | void Scoring::set_score(int score) { |
rafeh | 7:05f433e196d6 | 15 | _score=score; |
rafeh | 7:05f433e196d6 | 16 | } |
rafeh | 10:75de0f4da176 | 17 | bool Scoring::check_for_highscore(int highscore) { //checks if the score is higher than the highscore |
rafeh | 7:05f433e196d6 | 18 | _highscore=highscore; |
rafeh | 7:05f433e196d6 | 19 | if (_score>_highscore) |
rafeh | 7:05f433e196d6 | 20 | return true; |
rafeh | 7:05f433e196d6 | 21 | else |
rafeh | 7:05f433e196d6 | 22 | return false; |
rafeh | 7:05f433e196d6 | 23 | } |
rafeh | 10:75de0f4da176 | 24 | void Scoring::update_highscore(int highscore) { //updates the highscore |
rafeh | 10:75de0f4da176 | 25 | _highscore=highscore; //if a highscore is scored, then a new value for the _highscore is a new value |
rafeh | 7:05f433e196d6 | 26 | } |
rafeh | 7:05f433e196d6 | 27 | |
rafeh | 10:75de0f4da176 | 28 | int Scoring::add_score(int score, int pipe_x,int bird_x,int pipe_width) { //checks if score should be added |
rafeh | 10:75de0f4da176 | 29 | 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 |
rafeh | 8:d91564c0f337 | 30 | _score=_score+1; |
rafeh | 8:d91564c0f337 | 31 | } |
rafeh | 8:d91564c0f337 | 32 | return _score; |
rafeh | 8:d91564c0f337 | 33 | } |
rafeh | 10:75de0f4da176 | 34 | |
rafeh | 10:75de0f4da176 | 35 | bool Scoring::check_collisions(int bird_y, int pipe_x, int pipe_height) { //checks for collisions by looking for |
rafeh | 10:75de0f4da176 | 36 | 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 |
rafeh | 10:75de0f4da176 | 37 | return true; } //return true if there is a collision |
rafeh | 10:75de0f4da176 | 38 | else { |
rafeh | 10:75de0f4da176 | 39 | return false; |
rafeh | 10:75de0f4da176 | 40 | } |
rafeh | 10:75de0f4da176 | 41 | } |
rafeh | 10:75de0f4da176 | 42 | |
rafeh | 8:d91564c0f337 | 43 | |
rafeh | 10:75de0f4da176 | 44 | void Scoring::display_score(N5110 &lcd, Gamepad &pad) { //displays the score and highscore after the player has lost |
rafeh | 7:05f433e196d6 | 45 | lcd.clear(); |
rafeh | 7:05f433e196d6 | 46 | char score_display[16]; |
rafeh | 7:05f433e196d6 | 47 | char highscore_display[20]; |
rafeh | 7:05f433e196d6 | 48 | sprintf(score_display,"Score : %d",_score); |
rafeh | 7:05f433e196d6 | 49 | lcd.printString(score_display,0,0); |
rafeh | 7:05f433e196d6 | 50 | sprintf(highscore_display,"High Score : %d",_highscore); |
rafeh | 7:05f433e196d6 | 51 | lcd.printString(highscore_display,1,1); |
rafeh | 7:05f433e196d6 | 52 | while ( pad.check_event(Gamepad::A_PRESSED) == false) { |
rafeh | 7:05f433e196d6 | 53 | pad.leds_on(); |
rafeh | 7:05f433e196d6 | 54 | wait(0.1); |
rafeh | 7:05f433e196d6 | 55 | pad.leds_off(); |
rafeh | 7:05f433e196d6 | 56 | wait(0.1); |
rafeh | 7:05f433e196d6 | 57 | lcd.refresh(); |
rafeh | 7:05f433e196d6 | 58 | } |
rafeh | 7:05f433e196d6 | 59 | } |