Snake game snake library
Snake.h@3:b24ef00836c5, 2017-05-05 (annotated)
- Committer:
- Nefos
- Date:
- Fri May 05 13:56:24 2017 +0000
- Revision:
- 3:b24ef00836c5
- Parent:
- 2:5e04e34a3b66
- Child:
- 4:c74ec3f409f9
pretty solid code, bugs: snake _dir, some wall detection, self detection, need comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nefos | 0:2eb4d7e86e2f | 1 | #ifndef SNAKE_H |
Nefos | 0:2eb4d7e86e2f | 2 | #define SNAKE_H |
Nefos | 0:2eb4d7e86e2f | 3 | |
Nefos | 0:2eb4d7e86e2f | 4 | |
Nefos | 0:2eb4d7e86e2f | 5 | #include "mbed.h" |
Nefos | 0:2eb4d7e86e2f | 6 | #include "N5110.h" |
Nefos | 0:2eb4d7e86e2f | 7 | #include "Gamepad.h" |
Nefos | 2:5e04e34a3b66 | 8 | #include "Food.h" |
Nefos | 0:2eb4d7e86e2f | 9 | #include <deque> |
Nefos | 0:2eb4d7e86e2f | 10 | |
Nefos | 0:2eb4d7e86e2f | 11 | struct snakePart{ |
Nefos | 0:2eb4d7e86e2f | 12 | char _x[4000]; |
Nefos | 0:2eb4d7e86e2f | 13 | char _y[4000]; |
Nefos | 0:2eb4d7e86e2f | 14 | char _dir[4000]; |
Nefos | 0:2eb4d7e86e2f | 15 | |
Nefos | 0:2eb4d7e86e2f | 16 | }; |
Nefos | 0:2eb4d7e86e2f | 17 | |
Nefos | 0:2eb4d7e86e2f | 18 | |
Nefos | 0:2eb4d7e86e2f | 19 | class Snake |
Nefos | 0:2eb4d7e86e2f | 20 | { |
Nefos | 0:2eb4d7e86e2f | 21 | public: |
Nefos | 0:2eb4d7e86e2f | 22 | |
Nefos | 0:2eb4d7e86e2f | 23 | Snake(); |
Nefos | 0:2eb4d7e86e2f | 24 | ~Snake(); |
Nefos | 3:b24ef00836c5 | 25 | void init(int x, int y, int lenght,int _live); |
Nefos | 0:2eb4d7e86e2f | 26 | void draw(N5110 &lcd); |
Nefos | 0:2eb4d7e86e2f | 27 | void update(Gamepad &pad); |
Nefos | 2:5e04e34a3b66 | 28 | void deadSnake(N5110 &lcd); |
Nefos | 3:b24ef00836c5 | 29 | void add_point(); |
Nefos | 2:5e04e34a3b66 | 30 | void checkWallCollision(N5110 &lcd); |
Nefos | 0:2eb4d7e86e2f | 31 | int _length; |
Nefos | 2:5e04e34a3b66 | 32 | int live; |
Nefos | 3:b24ef00836c5 | 33 | |
Nefos | 0:2eb4d7e86e2f | 34 | |
Nefos | 1:93a4cb86f100 | 35 | |
Nefos | 0:2eb4d7e86e2f | 36 | |
Nefos | 0:2eb4d7e86e2f | 37 | |
Nefos | 0:2eb4d7e86e2f | 38 | private: |
Nefos | 0:2eb4d7e86e2f | 39 | //deque<snakePart> snek; |
Nefos | 0:2eb4d7e86e2f | 40 | |
Nefos | 0:2eb4d7e86e2f | 41 | int _speed; |
Nefos | 0:2eb4d7e86e2f | 42 | int _direction; |
Nefos | 2:5e04e34a3b66 | 43 | |
Nefos | 3:b24ef00836c5 | 44 | |
Nefos | 1:93a4cb86f100 | 45 | int startx; |
Nefos | 1:93a4cb86f100 | 46 | int starty; |
Nefos | 3:b24ef00836c5 | 47 | int startl; |
Nefos | 2:5e04e34a3b66 | 48 | |
Nefos | 0:2eb4d7e86e2f | 49 | //int _snakeX[4000]; |
Nefos | 0:2eb4d7e86e2f | 50 | //int _snakeY[4000]; |
Nefos | 0:2eb4d7e86e2f | 51 | //int _snakeDir[4000]; |
Nefos | 0:2eb4d7e86e2f | 52 | int x; |
Nefos | 0:2eb4d7e86e2f | 53 | Direction d; |
Nefos | 3:b24ef00836c5 | 54 | Food _food; |
Nefos | 2:5e04e34a3b66 | 55 | //Gamepad pad; |
Nefos | 2:5e04e34a3b66 | 56 | //GameEngine engine; |
Nefos | 0:2eb4d7e86e2f | 57 | |
Nefos | 0:2eb4d7e86e2f | 58 | |
Nefos | 0:2eb4d7e86e2f | 59 | }; |
Nefos | 0:2eb4d7e86e2f | 60 | |
Nefos | 0:2eb4d7e86e2f | 61 | #endif |