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