Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Classic_Engine/ClassicEngine.cpp@31:c95f1b1d6423, 2019-04-27 (annotated)
- Committer:
- JamesCummins
- Date:
- Sat Apr 27 18:57:06 2019 +0000
- Revision:
- 31:c95f1b1d6423
- Parent:
- 29:42651f87522b
- Child:
- 32:eff573ad8e42
Classic: failed menu working.; Girlfriend tried it. Likes it
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JamesCummins | 29:42651f87522b | 1 | #include "ClassicEngine.h" |
JamesCummins | 29:42651f87522b | 2 | |
JamesCummins | 29:42651f87522b | 3 | ClassicEngine::ClassicEngine(){ |
JamesCummins | 29:42651f87522b | 4 | } |
JamesCummins | 29:42651f87522b | 5 | |
JamesCummins | 29:42651f87522b | 6 | ClassicEngine::~ClassicEngine(){ |
JamesCummins | 20:4a39a1a2be51 | 7 | } |
JamesCummins | 20:4a39a1a2be51 | 8 | |
JamesCummins | 29:42651f87522b | 9 | void ClassicEngine::init(Ball &ball, Map &map){ |
JamesCummins | 31:c95f1b1d6423 | 10 | _frames = 0; |
JamesCummins | 29:42651f87522b | 11 | _ball_coord.x = 42; |
JamesCummins | 29:42651f87522b | 12 | _ball_coord.y = 24; |
JamesCummins | 29:42651f87522b | 13 | _map_coord.x = 47; |
JamesCummins | 29:42651f87522b | 14 | _map_coord.y = 25; |
JamesCummins | 29:42651f87522b | 15 | ball.set_position(_ball_coord); |
JamesCummins | 29:42651f87522b | 16 | map.set_map_display(_map_coord); |
JamesCummins | 20:4a39a1a2be51 | 17 | } |
JamesCummins | 29:42651f87522b | 18 | |
JamesCummins | 29:42651f87522b | 19 | void ClassicEngine::classic_update(Ball &ball, FXOS8700CQ &accelerometer, Map &map){ |
JamesCummins | 29:42651f87522b | 20 | map.read_input(accelerometer, ball); |
JamesCummins | 29:42651f87522b | 21 | map.update(); |
JamesCummins | 29:42651f87522b | 22 | ball.set_position(_ball_coord); |
JamesCummins | 31:c95f1b1d6423 | 23 | _frames++; |
JamesCummins | 31:c95f1b1d6423 | 24 | _map_coord = map.get_map_display(); |
JamesCummins | 31:c95f1b1d6423 | 25 | _abs_ball_pos.x = _ball_coord.x + _map_coord.x; |
JamesCummins | 31:c95f1b1d6423 | 26 | _abs_ball_pos.y = _ball_coord.y + _map_coord.y; |
JamesCummins | 29:42651f87522b | 27 | } |
JamesCummins | 29:42651f87522b | 28 | |
JamesCummins | 29:42651f87522b | 29 | void ClassicEngine::classic_draw(N5110 &lcd, Map &map, Ball &ball){ |
JamesCummins | 29:42651f87522b | 30 | map.draw(lcd); |
JamesCummins | 29:42651f87522b | 31 | ball.draw(lcd); |
JamesCummins | 29:42651f87522b | 32 | } |
JamesCummins | 31:c95f1b1d6423 | 33 | |
JamesCummins | 31:c95f1b1d6423 | 34 | bool ClassicEngine::finished(){ |
JamesCummins | 31:c95f1b1d6423 | 35 | bool finished = false; |
JamesCummins | 31:c95f1b1d6423 | 36 | if(_abs_ball_pos.x == 402 && //these are the range of coords the ball |
JamesCummins | 31:c95f1b1d6423 | 37 | _abs_ball_pos.y > 101 && //can have as it crosses the finish line |
JamesCummins | 31:c95f1b1d6423 | 38 | _abs_ball_pos.y < 141 ){ |
JamesCummins | 31:c95f1b1d6423 | 39 | finished = true; |
JamesCummins | 31:c95f1b1d6423 | 40 | } |
JamesCummins | 31:c95f1b1d6423 | 41 | else{ finished = false; } |
JamesCummins | 31:c95f1b1d6423 | 42 | return finished; |
JamesCummins | 31:c95f1b1d6423 | 43 | } |
JamesCummins | 31:c95f1b1d6423 | 44 | |
JamesCummins | 31:c95f1b1d6423 | 45 | void ClassicEngine::mode_complete(N5110 &lcd, Gamepad &gamepad, int fps){ |
JamesCummins | 31:c95f1b1d6423 | 46 | while(!(gamepad.check_event(gamepad.A_PRESSED))){ |
JamesCummins | 31:c95f1b1d6423 | 47 | float time_taken = _frames / fps; |
JamesCummins | 31:c95f1b1d6423 | 48 | char buffer[6]; |
JamesCummins | 31:c95f1b1d6423 | 49 | sprintf(buffer, "%4.f", time_taken); |
JamesCummins | 31:c95f1b1d6423 | 50 | lcd.clear(); |
JamesCummins | 31:c95f1b1d6423 | 51 | lcd.printString("You win!", 18, 1); |
JamesCummins | 31:c95f1b1d6423 | 52 | lcd.printString("Your time:", 12, 3); |
JamesCummins | 31:c95f1b1d6423 | 53 | lcd.printString(buffer, 18,4); |
JamesCummins | 31:c95f1b1d6423 | 54 | lcd.printChar('s',54,4); |
JamesCummins | 31:c95f1b1d6423 | 55 | lcd.printString("(A = back)", 24, 5); |
JamesCummins | 31:c95f1b1d6423 | 56 | lcd.refresh(); |
JamesCummins | 31:c95f1b1d6423 | 57 | wait(0.2); |
JamesCummins | 31:c95f1b1d6423 | 58 | } |
JamesCummins | 31:c95f1b1d6423 | 59 | } |
JamesCummins | 31:c95f1b1d6423 | 60 | |
JamesCummins | 31:c95f1b1d6423 | 61 | bool ClassicEngine::mode_failed(N5110 &lcd, Gamepad &gamepad, Ball &ball, Map &map){ |
JamesCummins | 31:c95f1b1d6423 | 62 | bool back_to_start_menu = false; |
JamesCummins | 31:c95f1b1d6423 | 63 | while(1){ |
JamesCummins | 31:c95f1b1d6423 | 64 | wait(0.2); |
JamesCummins | 31:c95f1b1d6423 | 65 | lcd.clear(); |
JamesCummins | 31:c95f1b1d6423 | 66 | lcd.printString("You lose!", 15, 1); |
JamesCummins | 31:c95f1b1d6423 | 67 | lcd.printString("Back = A", 18, 3); |
JamesCummins | 31:c95f1b1d6423 | 68 | lcd.printString("Replay = B", 12, 4); |
JamesCummins | 31:c95f1b1d6423 | 69 | lcd.refresh(); |
JamesCummins | 31:c95f1b1d6423 | 70 | if(gamepad.check_event(gamepad.A_PRESSED)){ |
JamesCummins | 31:c95f1b1d6423 | 71 | back_to_start_menu = true; |
JamesCummins | 31:c95f1b1d6423 | 72 | break; } |
JamesCummins | 31:c95f1b1d6423 | 73 | if(gamepad.check_event(gamepad.B_PRESSED)){ |
JamesCummins | 31:c95f1b1d6423 | 74 | back_to_start_menu = false; |
JamesCummins | 31:c95f1b1d6423 | 75 | break; } |
JamesCummins | 31:c95f1b1d6423 | 76 | } |
JamesCummins | 31:c95f1b1d6423 | 77 | return back_to_start_menu; |
JamesCummins | 31:c95f1b1d6423 | 78 | } |