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
SnakeEngine/SnakeEngine.h@13:c20acb3b1adf, 2020-06-05 (annotated)
- Committer:
- Psy1990
- Date:
- Fri Jun 05 22:13:33 2020 +0000
- Revision:
- 13:c20acb3b1adf
- Parent:
- 12:8eb40a18f15d
- Child:
- 16:8cb23849b95a
Tried to get the eat function to detect when the snake collides with the apple and it would flash the green LEDs and increase the score and respawn the apple but haven't managed to get it to work. Commiting due to time to go back if needed.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| Psy1990 | 7:9bd49beccdd1 | 1 | #ifndef SNAKEENGINE_H | 
| Psy1990 | 7:9bd49beccdd1 | 2 | #define SNAKEENGINE_H | 
| Psy1990 | 7:9bd49beccdd1 | 3 | |
| Psy1990 | 7:9bd49beccdd1 | 4 | #include "mbed.h" | 
| Psy1990 | 7:9bd49beccdd1 | 5 | #include "N5110.h" | 
| Psy1990 | 7:9bd49beccdd1 | 6 | #include "Gamepad.h" | 
| Psy1990 | 8:32825d724856 | 7 | #include "Apple.h" | 
| Psy1990 | 8:32825d724856 | 8 | #include "Snake.h" | 
| Psy1990 | 8:32825d724856 | 9 | #include "Bitmap.h" | 
| Psy1990 | 11:ba20e1b516a1 | 10 | /** Apple Class File | 
| Psy1990 | 11:ba20e1b516a1 | 11 | * @brief Class containing the engine that runs the game. | 
| Psy1990 | 11:ba20e1b516a1 | 12 | * @author Simon Atkinson | 
| Psy1990 | 11:ba20e1b516a1 | 13 | * @date June 2020 | 
| Psy1990 | 11:ba20e1b516a1 | 14 | */ | 
| Psy1990 | 7:9bd49beccdd1 | 15 | |
| Psy1990 | 8:32825d724856 | 16 | // gap from edge of screen | 
| Psy1990 | 8:32825d724856 | 17 | #define GAP 2 | 
| Psy1990 | 7:9bd49beccdd1 | 18 | |
| Psy1990 | 7:9bd49beccdd1 | 19 | |
| Psy1990 | 7:9bd49beccdd1 | 20 | class SnakeEngine | 
| Psy1990 | 7:9bd49beccdd1 | 21 | { | 
| Psy1990 | 7:9bd49beccdd1 | 22 | |
| Psy1990 | 7:9bd49beccdd1 | 23 | public: | 
| Psy1990 | 7:9bd49beccdd1 | 24 | SnakeEngine(); | 
| Psy1990 | 7:9bd49beccdd1 | 25 | ~SnakeEngine(); | 
| Psy1990 | 7:9bd49beccdd1 | 26 | |
| Psy1990 | 13:c20acb3b1adf | 27 | void init(int apple_size, int snake_speed, int snake_score, int snake_snakeheight, int snake_snakewidth); | 
| Psy1990 | 10:3e37b58e8600 | 28 | void read_input(Gamepad &pad); //Allows us to read the input from the thumbstick | 
| Psy1990 | 12:8eb40a18f15d | 29 | void update(Gamepad &pad, N5110 &lcd); //Allows us to update the gamepad | 
| Psy1990 | 10:3e37b58e8600 | 30 | void draw(N5110 &lcd); //Allows us to draw on the screen | 
| Psy1990 | 12:8eb40a18f15d | 31 | void dead(N5110 &lcd, Gamepad &pad); // The snake is DEAD :( | 
| Psy1990 | 13:c20acb3b1adf | 32 | void eat(N5110 &lcd, Gamepad &pad); // Deals with the snake eating the apple | 
| Psy1990 | 7:9bd49beccdd1 | 33 | private: | 
| Psy1990 | 7:9bd49beccdd1 | 34 | |
| Psy1990 | 7:9bd49beccdd1 | 35 | void print_score(N5110 &lcd); | 
| Psy1990 | 7:9bd49beccdd1 | 36 | |
| Psy1990 | 10:3e37b58e8600 | 37 | int sx; //Snake X | 
| Psy1990 | 10:3e37b58e8600 | 38 | int sy; //Snake Y | 
| Psy1990 | 10:3e37b58e8600 | 39 | int ax; //Apple X | 
| Psy1990 | 10:3e37b58e8600 | 40 | int ay; //Apple Y | 
| Psy1990 | 10:3e37b58e8600 | 41 | int _apple_size; //Apple size is defined and taken from main.cpp | 
| Psy1990 | 10:3e37b58e8600 | 42 | int _snake_speed; //Stores the speed the snake goes | 
| Psy1990 | 10:3e37b58e8600 | 43 | int _snake_score; //Stores the score | 
| Psy1990 | 13:c20acb3b1adf | 44 | int _snake_snakeheight; // Snake Hight | 
| Psy1990 | 13:c20acb3b1adf | 45 | int _snake_snakewidth; // Snake Width | 
| Psy1990 | 12:8eb40a18f15d | 46 | bool _dead; | 
| Psy1990 | 7:9bd49beccdd1 | 47 | |
| Psy1990 | 10:3e37b58e8600 | 48 | Snake _s; //Allows us to use the Snake | 
| Psy1990 | 10:3e37b58e8600 | 49 | Apple _a; //Allows us to use the Apple | 
| Psy1990 | 10:3e37b58e8600 | 50 | Direction _d; //Direction | 
| Psy1990 | 10:3e37b58e8600 | 51 | float _mag; //Magnitude | 
| Psy1990 | 12:8eb40a18f15d | 52 | |
| Psy1990 | 12:8eb40a18f15d | 53 | |
| Psy1990 | 7:9bd49beccdd1 | 54 | |
| Psy1990 | 7:9bd49beccdd1 | 55 | }; | 
| Psy1990 | 7:9bd49beccdd1 | 56 | |
| Psy1990 | 7:9bd49beccdd1 | 57 | #endif |