ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18s2a_2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SnakeEngine.h Source File

SnakeEngine.h

00001 #ifndef SNAKEENGINE_H
00002 #define SNAKEENGINE_H
00003 
00004 #include "mbed.h"
00005 #include "N5110.h"
00006 #include "Gamepad.h"
00007 #include "Apple.h"
00008 #include "Snake.h"
00009 #include "Bitmap.h"
00010 
00011 /** SnakeEngine Class File
00012 * @brief This contains the core of the Game.
00013 * @author Simon Atkinson
00014 * @date June 2020
00015 */
00016 
00017 // gap from edge of screen
00018 #define GAP 2
00019 
00020 
00021 class SnakeEngine
00022 {
00023 
00024 public:
00025     SnakeEngine();
00026     ~SnakeEngine();
00027     
00028     /**
00029     @pram The Initial setup of the of the game engine.
00030     */
00031     void init(int apple_size, int snake_speed, int snake_score, int snake_snakeheight, int snake_snakewidth);
00032     /**
00033     @pram Allows us to read from any of the inputs in the gamepad in this case its the Thumbstick on the left hand side which controls the snakes movement.
00034     */
00035     void read_input(Gamepad &pad);  
00036     /**
00037     @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.
00038     */    
00039     void crash(Gamepad &pad, N5110 &lcd); 
00040     /**
00041     @pram This is used to draw what you see on the LCD display
00042     */
00043     void draw(N5110 &lcd);         
00044     /**
00045     @pram The snake is DEAD :( Ends the game when the snake is dead and displays your score and instructions for restarting the game. 
00046     */
00047     void dead(N5110 &lcd, Gamepad &pad); // 
00048     /**
00049     @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.
00050     */
00051     void eat(N5110 &lcd, Gamepad &pad); 
00052 
00053 
00054 private:
00055 
00056     void print_score(N5110 &lcd);
00057     
00058     int sx;  //Snake X
00059     int sy;  //Snake Y
00060     int ax;  //Apple X
00061     int ay;  //Apple Y
00062     int _apple_size;  //Apple size is defined and taken from main.cpp
00063     int _snake_speed; //Stores the speed the snake goes
00064     int _snake_score; //Stores the score
00065     int _snake_snakeheight; // Snake Hight
00066     int _snake_snakewidth; // Snake Width
00067     bool _dead;
00068     
00069     Snake _s;   //Allows us to use the Snake 
00070     Apple _a;   //Allows us to use the Apple 
00071     Direction _d; //Direction
00072     float _mag;   //Magnitude
00073     
00074 
00075 
00076 };
00077 
00078 #endif