![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Final Submission. I have read and agreed with Statement of Academic Integrity.
Dependencies: mbed Gamepad N5110 Joystick
Snake/Snake.cpp@3:660de4311976, 2019-05-09 (annotated)
- Committer:
- el16dlc
- Date:
- Thu May 09 00:19:35 2019 +0000
- Revision:
- 3:660de4311976
- Parent:
- 2:0bd6711eae26
- Child:
- 10:aedca0082855
4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el16dlc | 1:b9f3b7d869d8 | 1 | #include "Snake.h" |
el16dlc | 1:b9f3b7d869d8 | 2 | |
el16dlc | 1:b9f3b7d869d8 | 3 | Snake::Snake() { |
el16dlc | 1:b9f3b7d869d8 | 4 | } |
el16dlc | 1:b9f3b7d869d8 | 5 | |
el16dlc | 1:b9f3b7d869d8 | 6 | Snake::~Snake() { |
el16dlc | 1:b9f3b7d869d8 | 7 | } |
el16dlc | 1:b9f3b7d869d8 | 8 | |
el16dlc | 1:b9f3b7d869d8 | 9 | void Snake::init() { |
el16dlc | 1:b9f3b7d869d8 | 10 | _snake_posX = WIDTH/2 - 2; // Snake head set to horizontal centre |
el16dlc | 1:b9f3b7d869d8 | 11 | _snake_posY = HEIGHT/2 - 2; // Snake head set to vertical centre |
el16dlc | 1:b9f3b7d869d8 | 12 | } |
el16dlc | 1:b9f3b7d869d8 | 13 | |
el16dlc | 1:b9f3b7d869d8 | 14 | void Snake::draw_head(N5110 &lcd) { |
el16dlc | 1:b9f3b7d869d8 | 15 | lcd.drawRect(_snake_posX,_snake_posY,4,4,FILL_BLACK); // Draws snake head |
el16dlc | 1:b9f3b7d869d8 | 16 | } |
el16dlc | 1:b9f3b7d869d8 | 17 | |
el16dlc | 2:0bd6711eae26 | 18 | void Snake::set_snake_posX(int snake_posX) {_snake_posX = snake_posX;} // mutators allow changing snake position |
el16dlc | 2:0bd6711eae26 | 19 | void Snake::set_snake_posY(int snake_posY) {_snake_posY = snake_posY;} |
el16dlc | 2:0bd6711eae26 | 20 | |
el16dlc | 2:0bd6711eae26 | 21 | // accessors |
el16dlc | 2:0bd6711eae26 | 22 | int Snake::get_snake_posX() { |
el16dlc | 2:0bd6711eae26 | 23 | return _snake_posX; |
el16dlc | 2:0bd6711eae26 | 24 | } |
el16dlc | 2:0bd6711eae26 | 25 | int Snake::get_snake_posY() { |
el16dlc | 2:0bd6711eae26 | 26 | return _snake_posY; |
el16dlc | 2:0bd6711eae26 | 27 | } |
el16dlc | 3:660de4311976 | 28 | |
el16dlc | 3:660de4311976 | 29 | void Snake::set_food_posX(int food_posX) {_food_posX = food_posX;} // mutators allow changing snake position |
el16dlc | 3:660de4311976 | 30 | void Snake::set_food_posY(int food_posY) {_food_posY = food_posY;} |
el16dlc | 3:660de4311976 | 31 | |
el16dlc | 3:660de4311976 | 32 | // accessors |
el16dlc | 3:660de4311976 | 33 | int Snake::get_food_posX() { |
el16dlc | 3:660de4311976 | 34 | return _food_posX; |
el16dlc | 3:660de4311976 | 35 | } |
el16dlc | 3:660de4311976 | 36 | int Snake::get_food_posY() { |
el16dlc | 3:660de4311976 | 37 | return _food_posY; |
el16dlc | 3:660de4311976 | 38 | } |
el16dlc | 3:660de4311976 | 39 | |
el16dlc | 3:660de4311976 | 40 | void Snake::draw_food(N5110 &lcd) { |
el16dlc | 3:660de4311976 | 41 | lcd.drawRect(_food_posX,_food_posY,4,4,FILL_BLACK); |
el16dlc | 3:660de4311976 | 42 | } |