![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Owen Cavender 201159294
GameEngine.cpp@10:ee781d18e0f6, 2020-05-28 (annotated)
- Committer:
- el17oc
- Date:
- Thu May 28 20:58:49 2020 +0000
- Revision:
- 10:ee781d18e0f6
- Parent:
- 9:a69a6a06dddf
- Child:
- 11:e7c56013acd9
- Child:
- 12:60c856354406
kkk
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 | 8:997f90c88246 | 19 | lcd.printString(buffer1,WIDTH/2 - 3,1); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits |
el17oc | 8:997f90c88246 | 20 | char buffer2[14]; |
el17oc | 8:997f90c88246 | 21 | } |
el17oc | 8:997f90c88246 | 22 | |
el17oc | 8:997f90c88246 | 23 | |
el17oc | 8:997f90c88246 | 24 | |
el17oc | 8:997f90c88246 | 25 | |
el17oc | 9:a69a6a06dddf | 26 | void GameEngine::get_LEDs(Gamepad &pad, Snake &snake) |
el17oc | 8:997f90c88246 | 27 | { |
el17oc | 8:997f90c88246 | 28 | pad.leds_off(); |
el17oc | 8:997f90c88246 | 29 | Vector2D Snakehead = snake.get_Snakehead(); |
el17oc | 8:997f90c88246 | 30 | int _x0 = Snakehead.x; |
el17oc | 8:997f90c88246 | 31 | int _y0 = Snakehead.y; |
el17oc | 8:997f90c88246 | 32 | |
el17oc | 8:997f90c88246 | 33 | if (_x0 >= 42 && _y0 >= 24) { |
el17oc | 8:997f90c88246 | 34 | // top right led on |
el17oc | 8:997f90c88246 | 35 | |
el17oc | 8:997f90c88246 | 36 | pad.led(4, 1); |
el17oc | 10:ee781d18e0f6 | 37 | wait(0.2); |
el17oc | 10:ee781d18e0f6 | 38 | pad.led(4, 0); |
el17oc | 8:997f90c88246 | 39 | } |
el17oc | 8:997f90c88246 | 40 | // topleft led on |
el17oc | 8:997f90c88246 | 41 | if (_x0 <= 42 && _y0 >=24) { |
el17oc | 8:997f90c88246 | 42 | // top right led on |
el17oc | 8:997f90c88246 | 43 | pad.led(1, 1); |
el17oc | 10:ee781d18e0f6 | 44 | wait(0.2); |
el17oc | 10:ee781d18e0f6 | 45 | pad.led(1, 0); |
el17oc | 8:997f90c88246 | 46 | } |
el17oc | 8:997f90c88246 | 47 | //bottom left |
el17oc | 8:997f90c88246 | 48 | if (_x0 <=42 && _y0 <= 24) { |
el17oc | 8:997f90c88246 | 49 | |
el17oc | 8:997f90c88246 | 50 | pad.led(3,1); |
el17oc | 10:ee781d18e0f6 | 51 | wait(0.2); |
el17oc | 10:ee781d18e0f6 | 52 | pad.led(3, 0); |
el17oc | 8:997f90c88246 | 53 | } |
el17oc | 8:997f90c88246 | 54 | //bottom right |
el17oc | 8:997f90c88246 | 55 | if (_x0 >= 42 && _y0 <= 24) { |
el17oc | 8:997f90c88246 | 56 | // top right led on |
el17oc | 8:997f90c88246 | 57 | pad.led(6, 1); |
el17oc | 10:ee781d18e0f6 | 58 | wait(0.2); |
el17oc | 10:ee781d18e0f6 | 59 | pad.led(6, 0); |
el17oc | 8:997f90c88246 | 60 | } |
el17oc | 10:ee781d18e0f6 | 61 | else { |
el17oc | 8:997f90c88246 | 62 | } |
el17oc | 10:ee781d18e0f6 | 63 | } |