
Simon Atkinson 201255483
Dependencies: mbed
Snake Game
Summary
Hello and welcome to my Snake Game. Snake is a simple game where you control a snake and eat an apple which increases your size. Normally touching the walls will kill you, always touching yourself will make you die!
Controls
The Controls for this game are simple the Start button starts the game (who would have thought) this button is the left button on the bottom of the gamepad next to the two blue potentiometers. The Reset button on the right of the potentiometers resets the game. Once the game starts use the left thumbstick to control the movement of the snake.
If you hit the wall with your snake you will die and the game will end.
Bugs/Missing Features
Unfortunatley I wasn't able to get the game eating the apple to work, when I tried I could never get it to detect the collisions I tried a few different ways but ran out of time. Because that doesn't work the score doesn't increase and the apple doesn't spawn in a different place. I will try continue to work on this when I have time as I enjoyed doing this project even though it was very frustrating at times!
Snake/Snake.h@21:e8d66c5f68cc, 2020-06-05 (annotated)
- Committer:
- Psy1990
- Date:
- Fri Jun 05 22:57:33 2020 +0000
- Revision:
- 21:e8d66c5f68cc
- Parent:
- 18:1255a2804713
Final Submission. I have read and agreed with Statement of Academic Integrity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Psy1990 | 8:32825d724856 | 1 | #ifndef Snake_H |
Psy1990 | 8:32825d724856 | 2 | #define Snake_H |
Psy1990 | 8:32825d724856 | 3 | |
Psy1990 | 8:32825d724856 | 4 | #include "mbed.h" |
Psy1990 | 8:32825d724856 | 5 | #include "N5110.h" |
Psy1990 | 8:32825d724856 | 6 | #include "Gamepad.h" |
Psy1990 | 18:1255a2804713 | 7 | |
Psy1990 | 11:ba20e1b516a1 | 8 | /** Snake Class File |
Psy1990 | 11:ba20e1b516a1 | 9 | * @brief Class containing the snake for the actual game. |
Psy1990 | 11:ba20e1b516a1 | 10 | * @author Simon Atkinson |
Psy1990 | 11:ba20e1b516a1 | 11 | * @date June 2020 |
Psy1990 | 11:ba20e1b516a1 | 12 | */ |
Psy1990 | 8:32825d724856 | 13 | |
Psy1990 | 8:32825d724856 | 14 | class Snake |
Psy1990 | 8:32825d724856 | 15 | { |
Psy1990 | 8:32825d724856 | 16 | public: |
Psy1990 | 8:32825d724856 | 17 | |
Psy1990 | 8:32825d724856 | 18 | Snake(); |
Psy1990 | 8:32825d724856 | 19 | ~Snake(); |
Psy1990 | 16:8cb23849b95a | 20 | /** |
Psy1990 | 16:8cb23849b95a | 21 | @pram The Initial setup of the of the snake |
Psy1990 | 16:8cb23849b95a | 22 | */ |
Psy1990 | 16:8cb23849b95a | 23 | void init(int _x, int _y, int score, int _speed, int snakeheight, int snakewidth); |
Psy1990 | 16:8cb23849b95a | 24 | /** |
Psy1990 | 16:8cb23849b95a | 25 | @pram For drawing the snake on the screen allows the use of the LCD |
Psy1990 | 16:8cb23849b95a | 26 | */ |
Psy1990 | 16:8cb23849b95a | 27 | void draw(N5110 &lcd); |
Psy1990 | 16:8cb23849b95a | 28 | /** |
Psy1990 | 16:8cb23849b95a | 29 | @return Gets the direction from the thumbstick |
Psy1990 | 16:8cb23849b95a | 30 | */ |
Psy1990 | 16:8cb23849b95a | 31 | void update(Direction d,float mag); |
Psy1990 | 16:8cb23849b95a | 32 | /** |
Psy1990 | 16:8cb23849b95a | 33 | @pram Eating an apple will add to the score |
Psy1990 | 16:8cb23849b95a | 34 | */ |
Psy1990 | 16:8cb23849b95a | 35 | void add_score(); |
Psy1990 | 16:8cb23849b95a | 36 | /** |
Psy1990 | 16:8cb23849b95a | 37 | @return Gives us the score |
Psy1990 | 16:8cb23849b95a | 38 | */ |
Psy1990 | 16:8cb23849b95a | 39 | int get_score(); |
Psy1990 | 16:8cb23849b95a | 40 | /** |
Psy1990 | 16:8cb23849b95a | 41 | @return Gets the position of the snake |
Psy1990 | 16:8cb23849b95a | 42 | */ |
Psy1990 | 16:8cb23849b95a | 43 | Vector2D get_pos(); |
Psy1990 | 16:8cb23849b95a | 44 | /** |
Psy1990 | 16:8cb23849b95a | 45 | @return Gets the value the determines how fast the snake moves |
Psy1990 | 16:8cb23849b95a | 46 | */ |
Psy1990 | 16:8cb23849b95a | 47 | Vector2D get_move(); |
Psy1990 | 16:8cb23849b95a | 48 | /** |
Psy1990 | 16:8cb23849b95a | 49 | @return Gets the direction the snake travels in can be only North, East, South or West and the snake can't move in other directions. |
Psy1990 | 16:8cb23849b95a | 50 | */ |
Psy1990 | 16:8cb23849b95a | 51 | Vector2D get_Direction(); |
Psy1990 | 16:8cb23849b95a | 52 | /** |
Psy1990 | 16:8cb23849b95a | 53 | @pram Sets the Movement of the snake |
Psy1990 | 16:8cb23849b95a | 54 | */ |
Psy1990 | 10:3e37b58e8600 | 55 | void set_move(Vector2D m); |
Psy1990 | 9:25597bc0cecc | 56 | |
Psy1990 | 10:3e37b58e8600 | 57 | |
Psy1990 | 8:32825d724856 | 58 | |
Psy1990 | 8:32825d724856 | 59 | private: |
Psy1990 | 8:32825d724856 | 60 | |
Psy1990 | 10:3e37b58e8600 | 61 | Vector2D _move; //Move value |
Psy1990 | 10:3e37b58e8600 | 62 | Vector2D _d; // Direction |
Psy1990 | 10:3e37b58e8600 | 63 | int _x; // X position of snake |
Psy1990 | 10:3e37b58e8600 | 64 | int _y; // Y Position of snake |
Psy1990 | 10:3e37b58e8600 | 65 | int _score; // Scoring system |
Psy1990 | 10:3e37b58e8600 | 66 | int _speed; // Speed the snake goes |
Psy1990 | 13:c20acb3b1adf | 67 | int _snakeheight; // set in main.cpp |
Psy1990 | 13:c20acb3b1adf | 68 | int _snakewidth; // set in main.cpp |
Psy1990 | 8:32825d724856 | 69 | |
Psy1990 | 8:32825d724856 | 70 | |
Psy1990 | 8:32825d724856 | 71 | }; |
Psy1990 | 8:32825d724856 | 72 | #endif |