Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
SnakeHead/SnakeHead.h@13:4fa0d5148216, 2020-05-24 (annotated)
- Committer:
- sdlashmar
- Date:
- Sun May 24 15:08:31 2020 +0000
- Revision:
- 13:4fa0d5148216
- Parent:
- 12:cb3a81adf48b
MOUSE X AND Y COORDS WORKING PROPERLY
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| sdlashmar | 5:256e5e0b6cd7 | 1 | #ifndef SNAKEHEAD_H |
| sdlashmar | 5:256e5e0b6cd7 | 2 | #define SNAKEHEAD_H |
| sdlashmar | 3:36f9e3a75905 | 3 | |
| sdlashmar | 3:36f9e3a75905 | 4 | #include "mbed.h" |
| sdlashmar | 3:36f9e3a75905 | 5 | #include "N5110.h" |
| sdlashmar | 3:36f9e3a75905 | 6 | #include "Gamepad.h" |
| sdlashmar | 4:c5addc5475d3 | 7 | #include "time.h" |
| sdlashmar | 3:36f9e3a75905 | 8 | |
| sdlashmar | 12:cb3a81adf48b | 9 | /** Snake Head Class |
| sdlashmar | 12:cb3a81adf48b | 10 | * @author Samuel D Lashmar |
| sdlashmar | 12:cb3a81adf48b | 11 | * @brief controls the snake head in the snake game and allows user to access certain variable |
| sdlashmar | 12:cb3a81adf48b | 12 | * @date May 2020 |
| sdlashmar | 12:cb3a81adf48b | 13 | */ |
| sdlashmar | 12:cb3a81adf48b | 14 | |
| sdlashmar | 5:256e5e0b6cd7 | 15 | class SnakeHead |
| sdlashmar | 3:36f9e3a75905 | 16 | { |
| sdlashmar | 3:36f9e3a75905 | 17 | |
| sdlashmar | 3:36f9e3a75905 | 18 | public: |
| sdlashmar | 12:cb3a81adf48b | 19 | /** Constructor */ |
| sdlashmar | 5:256e5e0b6cd7 | 20 | SnakeHead(); |
| sdlashmar | 12:cb3a81adf48b | 21 | /** Destructor */ |
| sdlashmar | 5:256e5e0b6cd7 | 22 | ~SnakeHead(); |
| sdlashmar | 12:cb3a81adf48b | 23 | /** Initialise snake head position, speed an direction |
| sdlashmar | 13:4fa0d5148216 | 24 | *@param Snake Head size |
| sdlashmar | 12:cb3a81adf48b | 25 | *@param Snake Head speed |
| sdlashmar | 12:cb3a81adf48b | 26 | */ |
| sdlashmar | 3:36f9e3a75905 | 27 | void init(int size, int speed); |
| sdlashmar | 12:cb3a81adf48b | 28 | /** Draws snake head on the LCD screen*/ |
| sdlashmar | 3:36f9e3a75905 | 29 | void draw(N5110 &lcd); |
| sdlashmar | 12:cb3a81adf48b | 30 | /** Updates head position */ |
| sdlashmar | 4:c5addc5475d3 | 31 | void update(); |
| sdlashmar | 12:cb3a81adf48b | 32 | /** Changes the direction in whihc the head moves |
| sdlashmar | 13:4fa0d5148216 | 33 | @param Direction of the joystick (N,E,S,W) |
| sdlashmar | 12:cb3a81adf48b | 34 | */ |
| sdlashmar | 4:c5addc5475d3 | 35 | void change_direction(Direction d); |
| sdlashmar | 13:4fa0d5148216 | 36 | /** Sets the velocity of the head |
| sdlashmar | 13:4fa0d5148216 | 37 | @param 2D vector for x and y speeds |
| sdlashmar | 13:4fa0d5148216 | 38 | */ |
| sdlashmar | 3:36f9e3a75905 | 39 | void set_velocity(Vector2D v); |
| sdlashmar | 13:4fa0d5148216 | 40 | /** gets the current head velocity |
| sdlashmar | 13:4fa0d5148216 | 41 | @returns velocity |
| sdlashmar | 13:4fa0d5148216 | 42 | */ |
| sdlashmar | 3:36f9e3a75905 | 43 | Vector2D get_velocity(); |
| sdlashmar | 13:4fa0d5148216 | 44 | /** Gets the current position of the head |
| sdlashmar | 13:4fa0d5148216 | 45 | @returns position |
| sdlashmar | 13:4fa0d5148216 | 46 | */ |
| sdlashmar | 3:36f9e3a75905 | 47 | Vector2D get_pos(); |
| sdlashmar | 13:4fa0d5148216 | 48 | /** Sets the position of the head |
| sdlashmar | 13:4fa0d5148216 | 49 | @param 2D vector of x and y coordinates |
| sdlashmar | 13:4fa0d5148216 | 50 | */ |
| sdlashmar | 3:36f9e3a75905 | 51 | void set_pos(Vector2D p); |
| sdlashmar | 3:36f9e3a75905 | 52 | |
| sdlashmar | 4:c5addc5475d3 | 53 | |
| sdlashmar | 3:36f9e3a75905 | 54 | private: |
| sdlashmar | 4:c5addc5475d3 | 55 | Vector2D _velocity; |
| sdlashmar | 4:c5addc5475d3 | 56 | Gamepad pad; |
| sdlashmar | 3:36f9e3a75905 | 57 | int _size; |
| sdlashmar | 3:36f9e3a75905 | 58 | int _speed; |
| sdlashmar | 3:36f9e3a75905 | 59 | int _x; |
| sdlashmar | 3:36f9e3a75905 | 60 | int _y; |
| sdlashmar | 3:36f9e3a75905 | 61 | }; |
| sdlashmar | 3:36f9e3a75905 | 62 | |
| sdlashmar | 3:36f9e3a75905 | 63 | #endif |