![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Owen Cavender 201159294
GameEngine.cpp@12:60c856354406, 2020-05-29 (annotated)
- Committer:
- el17oc
- Date:
- Fri May 29 16:00:56 2020 +0000
- Revision:
- 12:60c856354406
- Parent:
- 10:ee781d18e0f6
- Child:
- 14:7fb3c93343b6
HH
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17oc | 8:997f90c88246 | 1 | #include "GameEngine.h" |
el17oc | 8:997f90c88246 | 2 | |
el17oc | 8:997f90c88246 | 3 | GameEngine::GameEngine() |
el17oc | 8:997f90c88246 | 4 | { |
el17oc | 8:997f90c88246 | 5 | |
el17oc | 8:997f90c88246 | 6 | } |
el17oc | 8:997f90c88246 | 7 | |
el17oc | 8:997f90c88246 | 8 | GameEngine::~GameEngine() |
el17oc | 8:997f90c88246 | 9 | { |
el17oc | 8:997f90c88246 | 10 | } |
el17oc | 8:997f90c88246 | 11 | |
el17oc | 8:997f90c88246 | 12 | |
el17oc | 9:a69a6a06dddf | 13 | void GameEngine::print_scores(N5110 &lcd, Snake &snake) |
el17oc | 8:997f90c88246 | 14 | { |
el17oc | 8:997f90c88246 | 15 | int score = snake.get_score(); |
el17oc | 8:997f90c88246 | 16 | |
el17oc | 8:997f90c88246 | 17 | char buffer1[14]; |
el17oc | 8:997f90c88246 | 18 | sprintf(buffer1,"%2d",score); |
el17oc | 12:60c856354406 | 19 | lcd.printString(buffer1,0 ,48); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits |
el17oc | 8:997f90c88246 | 20 | } |
el17oc | 8:997f90c88246 | 21 | |
el17oc | 8:997f90c88246 | 22 | |
el17oc | 8:997f90c88246 | 23 | |
el17oc | 8:997f90c88246 | 24 | |
el17oc | 9:a69a6a06dddf | 25 | void GameEngine::get_LEDs(Gamepad &pad, Snake &snake) |
el17oc | 8:997f90c88246 | 26 | { |
el17oc | 8:997f90c88246 | 27 | pad.leds_off(); |
el17oc | 8:997f90c88246 | 28 | Vector2D Snakehead = snake.get_Snakehead(); |
el17oc | 8:997f90c88246 | 29 | int _x0 = Snakehead.x; |
el17oc | 8:997f90c88246 | 30 | int _y0 = Snakehead.y; |
el17oc | 8:997f90c88246 | 31 | |
el17oc | 8:997f90c88246 | 32 | if (_x0 >= 42 && _y0 >= 24) { |
el17oc | 8:997f90c88246 | 33 | // top right led on |
el17oc | 8:997f90c88246 | 34 | |
el17oc | 8:997f90c88246 | 35 | pad.led(4, 1); |
el17oc | 10:ee781d18e0f6 | 36 | wait(0.2); |
el17oc | 10:ee781d18e0f6 | 37 | pad.led(4, 0); |
el17oc | 8:997f90c88246 | 38 | } |
el17oc | 8:997f90c88246 | 39 | // topleft led on |
el17oc | 8:997f90c88246 | 40 | if (_x0 <= 42 && _y0 >=24) { |
el17oc | 8:997f90c88246 | 41 | // top right led on |
el17oc | 8:997f90c88246 | 42 | pad.led(1, 1); |
el17oc | 10:ee781d18e0f6 | 43 | wait(0.2); |
el17oc | 10:ee781d18e0f6 | 44 | pad.led(1, 0); |
el17oc | 8:997f90c88246 | 45 | } |
el17oc | 8:997f90c88246 | 46 | //bottom left |
el17oc | 8:997f90c88246 | 47 | if (_x0 <=42 && _y0 <= 24) { |
el17oc | 8:997f90c88246 | 48 | |
el17oc | 8:997f90c88246 | 49 | pad.led(3,1); |
el17oc | 10:ee781d18e0f6 | 50 | wait(0.2); |
el17oc | 10:ee781d18e0f6 | 51 | pad.led(3, 0); |
el17oc | 8:997f90c88246 | 52 | } |
el17oc | 8:997f90c88246 | 53 | //bottom right |
el17oc | 8:997f90c88246 | 54 | if (_x0 >= 42 && _y0 <= 24) { |
el17oc | 8:997f90c88246 | 55 | // top right led on |
el17oc | 8:997f90c88246 | 56 | pad.led(6, 1); |
el17oc | 10:ee781d18e0f6 | 57 | wait(0.2); |
el17oc | 10:ee781d18e0f6 | 58 | pad.led(6, 0); |
el17oc | 8:997f90c88246 | 59 | } |
el17oc | 10:ee781d18e0f6 | 60 | else { |
el17oc | 8:997f90c88246 | 61 | } |
el17oc | 12:60c856354406 | 62 | } |
el17oc | 12:60c856354406 | 63 | |
el17oc | 12:60c856354406 | 64 | void GameEngine::print_countdown(N5110 &lcd, Snake &snake){ |
el17oc | 12:60c856354406 | 65 | |
el17oc | 12:60c856354406 | 66 | int countdown = snake.get_countdown(); |
el17oc | 12:60c856354406 | 67 | |
el17oc | 12:60c856354406 | 68 | char buffer1[14]; |
el17oc | 12:60c856354406 | 69 | sprintf(buffer1,"%2d",countdown); |
el17oc | 12:60c856354406 | 70 | lcd.printString(buffer1,WIDTH/2 - 3,4); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits |
el17oc | 12:60c856354406 | 71 | printf(" countdown= %d ", countdown); |
el17oc | 12:60c856354406 | 72 | } |
el17oc | 12:60c856354406 | 73 |