ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18s2a_2

Dependencies:   mbed

Committer:
Psy1990
Date:
Fri Jun 05 22:44:54 2020 +0000
Revision:
16:8cb23849b95a
Parent:
13:c20acb3b1adf
Child:
19:0bf3ed373218
Documentation Update;

Who changed what in which revision?

UserRevisionLine numberNew 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 16:8cb23849b95a 10
Psy1990 16:8cb23849b95a 11 /** SnakeEngine Class File
Psy1990 11:ba20e1b516a1 12 * @brief Class containing the engine that runs the game.
Psy1990 11:ba20e1b516a1 13 * @author Simon Atkinson
Psy1990 11:ba20e1b516a1 14 * @date June 2020
Psy1990 11:ba20e1b516a1 15 */
Psy1990 7:9bd49beccdd1 16
Psy1990 8:32825d724856 17 // gap from edge of screen
Psy1990 8:32825d724856 18 #define GAP 2
Psy1990 7:9bd49beccdd1 19
Psy1990 7:9bd49beccdd1 20
Psy1990 7:9bd49beccdd1 21 class SnakeEngine
Psy1990 7:9bd49beccdd1 22 {
Psy1990 7:9bd49beccdd1 23
Psy1990 7:9bd49beccdd1 24 public:
Psy1990 7:9bd49beccdd1 25 SnakeEngine();
Psy1990 7:9bd49beccdd1 26 ~SnakeEngine();
Psy1990 16:8cb23849b95a 27 /**
Psy1990 16:8cb23849b95a 28 @pram The Initial setup of the of the game engine.
Psy1990 16:8cb23849b95a 29 */
Psy1990 13:c20acb3b1adf 30 void init(int apple_size, int snake_speed, int snake_score, int snake_snakeheight, int snake_snakewidth);
Psy1990 16:8cb23849b95a 31 /**
Psy1990 16:8cb23849b95a 32 @pram Allows us to read from any of the inputs in the gamepad in this case its the Thumbstick on the left hand side.
Psy1990 16:8cb23849b95a 33 */
Psy1990 16:8cb23849b95a 34 void read_input(Gamepad &pad);
Psy1990 16:8cb23849b95a 35 /**
Psy1990 16:8cb23849b95a 36 @pram We are using this for collision dection. Currently it only detects when you crash into the wall. If a collision is detected the game is over.
Psy1990 16:8cb23849b95a 37 */
Psy1990 16:8cb23849b95a 38 void crash(Gamepad &pad, N5110 &lcd);
Psy1990 16:8cb23849b95a 39 /**
Psy1990 16:8cb23849b95a 40 @pram This is used to draw what you see on the LCD display
Psy1990 16:8cb23849b95a 41 */
Psy1990 16:8cb23849b95a 42 void draw(N5110 &lcd);
Psy1990 16:8cb23849b95a 43 /**
Psy1990 16:8cb23849b95a 44 @pram The snake is DEAD :( Ends the game when the snake is dead and displays your score and instructions for restarting the game.
Psy1990 16:8cb23849b95a 45 */
Psy1990 16:8cb23849b95a 46 void dead(N5110 &lcd, Gamepad &pad); //
Psy1990 16:8cb23849b95a 47 /**
Psy1990 16:8cb23849b95a 48 @pram Deals with the snake eating the apple. Started but wasn't able to get to work. It should detect when you eat the apple, add to the score and spawn another apple and give a flash of the green LEDs to show that the apple has been eaten.
Psy1990 16:8cb23849b95a 49 */
Psy1990 16:8cb23849b95a 50 void eat(N5110 &lcd, Gamepad &pad);
Psy1990 16:8cb23849b95a 51
Psy1990 16:8cb23849b95a 52
Psy1990 7:9bd49beccdd1 53 private:
Psy1990 7:9bd49beccdd1 54
Psy1990 7:9bd49beccdd1 55 void print_score(N5110 &lcd);
Psy1990 7:9bd49beccdd1 56
Psy1990 10:3e37b58e8600 57 int sx; //Snake X
Psy1990 10:3e37b58e8600 58 int sy; //Snake Y
Psy1990 10:3e37b58e8600 59 int ax; //Apple X
Psy1990 10:3e37b58e8600 60 int ay; //Apple Y
Psy1990 10:3e37b58e8600 61 int _apple_size; //Apple size is defined and taken from main.cpp
Psy1990 10:3e37b58e8600 62 int _snake_speed; //Stores the speed the snake goes
Psy1990 10:3e37b58e8600 63 int _snake_score; //Stores the score
Psy1990 13:c20acb3b1adf 64 int _snake_snakeheight; // Snake Hight
Psy1990 13:c20acb3b1adf 65 int _snake_snakewidth; // Snake Width
Psy1990 12:8eb40a18f15d 66 bool _dead;
Psy1990 7:9bd49beccdd1 67
Psy1990 10:3e37b58e8600 68 Snake _s; //Allows us to use the Snake
Psy1990 10:3e37b58e8600 69 Apple _a; //Allows us to use the Apple
Psy1990 10:3e37b58e8600 70 Direction _d; //Direction
Psy1990 10:3e37b58e8600 71 float _mag; //Magnitude
Psy1990 12:8eb40a18f15d 72
Psy1990 12:8eb40a18f15d 73
Psy1990 7:9bd49beccdd1 74
Psy1990 7:9bd49beccdd1 75 };
Psy1990 7:9bd49beccdd1 76
Psy1990 7:9bd49beccdd1 77 #endif