![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Doxygen comments added
Dependencies: mbed Gamepad N5110
FlappyBirdEngine/Scoring.cpp@9:b7a3ec1c7217, 2019-05-07 (annotated)
- Committer:
- rafeh
- Date:
- Tue May 07 22:39:48 2019 +0000
- Revision:
- 9:b7a3ec1c7217
- Parent:
- FlappyBirdEngine/FlappyBirdEngine.cpp@8:d91564c0f337
scoring class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rafeh | 9:b7a3ec1c7217 | 1 | #include "Scoring.h" |
rafeh | 7:05f433e196d6 | 2 | |
rafeh | 7:05f433e196d6 | 3 | |
rafeh | 7:05f433e196d6 | 4 | |
rafeh | 9:b7a3ec1c7217 | 5 | void Scoring::get_score(int score) { |
rafeh | 7:05f433e196d6 | 6 | _score=score; |
rafeh | 7:05f433e196d6 | 7 | } |
rafeh | 9:b7a3ec1c7217 | 8 | bool Scoring::check_for_highscore(int highscore) { |
rafeh | 7:05f433e196d6 | 9 | _highscore=highscore; |
rafeh | 7:05f433e196d6 | 10 | if (_score>_highscore) |
rafeh | 7:05f433e196d6 | 11 | return true; |
rafeh | 7:05f433e196d6 | 12 | else |
rafeh | 7:05f433e196d6 | 13 | return false; |
rafeh | 7:05f433e196d6 | 14 | } |
rafeh | 9:b7a3ec1c7217 | 15 | void Scoring::update_highscore(int highscore) { |
rafeh | 7:05f433e196d6 | 16 | _highscore=highscore; |
rafeh | 7:05f433e196d6 | 17 | } |
rafeh | 7:05f433e196d6 | 18 | |
rafeh | 9:b7a3ec1c7217 | 19 | int Scoring::add_score(int score, int pipe_x,int bird_x,int pipe_width) { |
rafeh | 8:d91564c0f337 | 20 | //_score=score; |
rafeh | 8:d91564c0f337 | 21 | if(pipe_x<(bird_x+pipe_width) && pipe_x>(bird_x+pipe_width-2)) { |
rafeh | 8:d91564c0f337 | 22 | _score=_score+1; |
rafeh | 8:d91564c0f337 | 23 | } |
rafeh | 8:d91564c0f337 | 24 | return _score; |
rafeh | 8:d91564c0f337 | 25 | } |
rafeh | 8:d91564c0f337 | 26 | |
rafeh | 9:b7a3ec1c7217 | 27 | void Scoring::display_score(N5110 &lcd, Gamepad &pad) { |
rafeh | 7:05f433e196d6 | 28 | lcd.clear(); |
rafeh | 7:05f433e196d6 | 29 | char score_display[16]; |
rafeh | 7:05f433e196d6 | 30 | char highscore_display[20]; |
rafeh | 7:05f433e196d6 | 31 | sprintf(score_display,"Score : %d",_score); |
rafeh | 7:05f433e196d6 | 32 | lcd.printString(score_display,0,0); |
rafeh | 7:05f433e196d6 | 33 | sprintf(highscore_display,"High Score : %d",_highscore); |
rafeh | 7:05f433e196d6 | 34 | lcd.printString(highscore_display,1,1); |
rafeh | 7:05f433e196d6 | 35 | while ( pad.check_event(Gamepad::A_PRESSED) == false) { |
rafeh | 7:05f433e196d6 | 36 | pad.leds_on(); |
rafeh | 7:05f433e196d6 | 37 | wait(0.1); |
rafeh | 7:05f433e196d6 | 38 | pad.leds_off(); |
rafeh | 7:05f433e196d6 | 39 | wait(0.1); |
rafeh | 7:05f433e196d6 | 40 | lcd.refresh(); |
rafeh | 7:05f433e196d6 | 41 | } |
rafeh | 7:05f433e196d6 | 42 | } |