ELEC2645 (2019/20)
/
ELEC2645_Project_el17oc1
Owen Cavender 201159294
GameEngine.cpp@14:7fb3c93343b6, 2020-05-30 (annotated)
- Committer:
- el17oc
- Date:
- Sat May 30 02:31:43 2020 +0000
- Revision:
- 14:7fb3c93343b6
- Parent:
- 12:60c856354406
- Child:
- 15:6857657bb4e2
ff
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 | 14:7fb3c93343b6 | 15 | |
el17oc | 8:997f90c88246 | 16 | int score = snake.get_score(); |
el17oc | 8:997f90c88246 | 17 | |
el17oc | 8:997f90c88246 | 18 | char buffer1[14]; |
el17oc | 8:997f90c88246 | 19 | sprintf(buffer1,"%2d",score); |
el17oc | 14:7fb3c93343b6 | 20 | lcd.printString(buffer1,0,48); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits |
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 | 14:7fb3c93343b6 | 30 | int _x0 = Snakehead.x; |
el17oc | 14:7fb3c93343b6 | 31 | int _y0 = Snakehead.y; //depending where the snakehead is on the screen, different LEDs will turn on indicating its postion |
el17oc | 8:997f90c88246 | 32 | |
el17oc | 14:7fb3c93343b6 | 33 | if (_x0 >= 42 && _y0 <= 16) { //defines paramaters of the top right quadrant of the lcd rectangle and turns on and off the top right LED if the |
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 | 14:7fb3c93343b6 | 41 | if (_x0 <= 42 && _y0 <= 16 ) { |
el17oc | 14:7fb3c93343b6 | 42 | |
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 | 14:7fb3c93343b6 | 47 | //bottom left //defines paramaters of the bottom left quadrant of the rectangle ont the lcd display and turns on and off the bottom left LED |
el17oc | 14:7fb3c93343b6 | 48 | if (_x0 <=42 && _y0 >= 16 ) { |
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 | 14:7fb3c93343b6 | 55 | if (_x0 >= 42 && _y0 >= 16) { |
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 | 14:7fb3c93343b6 | 60 | } else { |
el17oc | 8:997f90c88246 | 61 | } |
el17oc | 12:60c856354406 | 62 | } |
el17oc | 12:60c856354406 | 63 | |
el17oc | 14:7fb3c93343b6 | 64 | void GameEngine::print_countdown(N5110 &lcd, Snake &snake) |
el17oc | 14:7fb3c93343b6 | 65 | { |
el17oc | 12:60c856354406 | 66 | |
el17oc | 14:7fb3c93343b6 | 67 | int countdown = snake.get_countdown(); //Accessing the value of the member variale _countdown |
el17oc | 12:60c856354406 | 68 | |
el17oc | 12:60c856354406 | 69 | char buffer1[14]; |
el17oc | 14:7fb3c93343b6 | 70 | sprintf(buffer1,"%2d",countdown); //printing value onto lcd in each loops. - counter is set to decrement by 1 each loop |
el17oc | 14:7fb3c93343b6 | 71 | lcd.printString(buffer1,0,4); // |
el17oc | 14:7fb3c93343b6 | 72 | // printf(" countdown= %d ", countdown); |
el17oc | 12:60c856354406 | 73 | } |
el17oc | 12:60c856354406 | 74 |