ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_ll16j23s

Dependencies:   mbed ll16j23s_test_docs

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 "FXOS8700CQ.h"
00008 #include "SnakeBody.h"
00009 #include "Food.h"
00010 #include <vector>
00011 
00012 /** SnakeEngine:
00013 @brief  - Engine that controls the mechanics of the snake game
00014 @author Joseph Shotton
00015 @date May 2020
00016 @version V1.0
00017 */ 
00018 
00019 class SnakeEngine
00020 {
00021 
00022 public:
00023     SnakeEngine();
00024     ~SnakeEngine();
00025     
00026     
00027     /** Initialises menu 1
00028     *@param Gamepad
00029     *@paran LCD
00030     */
00031     void menu1_init(Gamepad &pad, N5110 &lcd);
00032     
00033     
00034     /** Controls selection of options in menu 1
00035     *@param Gamepad
00036     *@param LCD
00037     *@param Magnometer
00038     */
00039     void menu1_select(Gamepad &pad, N5110 &lcd, FXOS8700CQ &mag);
00040 
00041 
00042     /** Controls selection of options in menu 2
00043     *@param Gamepad
00044     *@param LCD
00045     *@param Magnometer
00046     */
00047     void menu2_select(Gamepad &pad, N5110 &lcd, FXOS8700CQ &mag);
00048 
00049 
00050     /** Runs game 
00051     *@param Gamepad
00052     *@param LCD
00053     */
00054     void game_run(Gamepad &pad, N5110 &lcd);
00055     
00056     
00057     /** Controls selection of options in death menu
00058     *@param Gamepad
00059     *@param LCD
00060     *@param Magnometer
00061     */
00062     void death_select(Gamepad &pad, N5110 &lcd, FXOS8700CQ &mag);
00063     
00064     
00065     /** Reads pot2 and controls contrast accordingly
00066     *@param Gamepad
00067     *@param LCD
00068     */
00069     void contrast(Gamepad &pad, N5110 &lcd_);
00070     
00071     int score;
00072     int game_state;
00073     
00074 
00075 private:
00076 
00077     SnakeBody _body;
00078     Food _food;
00079     
00080 //  game functions and variables
00081     
00082     
00083     /** Initialises the game
00084     *@param Gamepad
00085     *@param LCD
00086     *@param Magnometer
00087     */
00088     void game_init(Gamepad &pad, N5110 &lcd, FXOS8700CQ &mag);
00089     
00090     
00091     /** Detects snake-food collisions and controls respawning of food/length increase etc
00092     *@param Gamepad
00093     *@param LCD
00094     */
00095     void snake_food_collision(Gamepad &pad, N5110 &lcd);
00096     
00097     
00098     /** Controls correct map to be displayed and correct snake-map collision functions
00099     *@param LCD
00100     */
00101     void map_run(N5110 &lcd);
00102     
00103     
00104      /** Draws map 2 (Ring)
00105     *@param LCD
00106     */
00107     void map2_draw(N5110 &lcd);
00108     
00109     
00110      /** Draws map 3 (Cross)
00111     *@param LCD
00112     */
00113     void map3_draw(N5110 &lcd);
00114     
00115     
00116      /** Draws map 4 (Lanes)
00117     *@param LCD
00118     */
00119     void map4_draw(N5110 &lcd);
00120     
00121     
00122      /** Detects snake-map collision on map 2
00123     */
00124     void snake_map2_collision();
00125     
00126     
00127      /** Detects snake-map collision on map 3
00128     */
00129     void snake_map3_collision();
00130     
00131     
00132      /** Detects snake-map collision on map 4
00133     */
00134     void snake_map4_collision();
00135     
00136     bool _death;
00137     int _map4_location; 
00138     float _angle;  
00139     
00140 //  menu/transition functions and variables
00141 
00142     /** Initialises menu 2
00143     *@param Gamepad
00144     *@param LCD
00145     */
00146     void menu2_init(Gamepad &pad, N5110 &lcd);
00147     
00148     
00149     /** Initialises death menu
00150     *@param Gamepad
00151     *@param LCD
00152     */
00153     void death_init(Gamepad &pad, N5110 &lcd);
00154     
00155     
00156     /** Creates black transition animation
00157     *@param LCD
00158     */
00159     void transition_black(N5110 &lcd);
00160         
00161     
00162     /** Creates white transition animation
00163     *@param LCD
00164     */
00165     void transition_white(N5110 &lcd);
00166     
00167     
00168     /** Draws black circle on selected line and clears other lines' circles
00169     *@param LCD
00170     *@param Line that current option will be selected on. Range 1 - 5  
00171     */
00172     void select_circles(N5110 &lcd, int line);
00173     
00174     
00175     /** Generates short preview of selected map, then reinitialises menu 2
00176     *@param Gamepad
00177     *@param LCD
00178     */
00179     void preview(Gamepad &pad, N5110 &lcd);
00180     
00181     
00182     /** Resets relevant variables so game can be replayed
00183     */
00184     void game_reset();
00185     
00186     /** Triple flashes LEDs
00187     *@param Gamepad
00188     *@param Led numbers - will trigger both sides (ie both red LEDs). Range 1 - 3
00189     */
00190     void menu_flash(Gamepad &pad, int led);
00191      
00192     int _menu_select; 
00193     int _map_select;
00194     double _pot2;
00195 
00196 };
00197 
00198 #endif