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 SnakeBody.h Source File

SnakeBody.h

00001 #ifndef SNAKEBODY_H
00002 #define SNAKEBODY_H
00003 
00004 #include "mbed.h"
00005 #include "N5110.h"
00006 #include "Gamepad.h"
00007 #include <vector>
00008 
00009 /** SnakeBody:
00010 @brief - Functions that exclusively control the snake body
00011 @author Joseph Shotton
00012 @date May 2020
00013 @version V1.0
00014 */ 
00015 
00016 
00017 class SnakeBody
00018 {
00019 struct Direction {
00020      int delta_x; // increment value for x          /**< x incrementation of the body in this state  */
00021      int delta_y; // increment value for y          /**< y incrementation of the body in this state  */
00022      int nextState[5];  // array of next states     /**< array of next states  */
00023     };
00024 
00025 public:
00026 
00027     SnakeBody();
00028     ~SnakeBody();
00029     
00030     
00031      /** Initialises the body
00032     */
00033     void init();
00034     
00035     
00036      /** Adjusts the _length_increase variable so the snake's length gradually increases
00037     *@param The body units that the snake will eventually grow to
00038     */
00039     void add_length(int increase);
00040     
00041     
00042     /** Runs the appropriate functions for the body
00043     *@param Gamepad
00044     *@param LCD
00045     *@param _death is the flag for if there is a collision (in this case snake-snake)
00046     */
00047     void run(Gamepad &pad, N5110 &lcd, bool &_death); 
00048     
00049     
00050      /** Resets body variables so game can be replayed 
00051     */
00052     void reset();
00053     
00054     int head_x;
00055     int head_y;
00056     
00057     std::vector<int> body_x;
00058     std::vector<int> body_y;
00059 
00060 private:
00061     
00062     
00063     /** Controls all movement functions
00064     *@param Gamepad
00065     */
00066     void snake_movement(Gamepad &pad);
00067     
00068     
00069     /** Draws body
00070     *@param LCD
00071     */
00072     void draw_body(N5110 &lcd);
00073     
00074     /** Detects snake-snake collision
00075     *@param Gamepad
00076     *@param _death  is the flag for if there is a collision (in this case snake-snake)
00077     */
00078     void snake_snake_collision(Gamepad &pad, bool &_death); 
00079     
00080     
00081     /** Updates direction of snake
00082     */
00083     void update_direction(); 
00084     
00085     
00086     /** Updates position of snake
00087     */
00088     void update_position(); 
00089     
00090     
00091     /** Updates body coordinates of whole snake
00092     */
00093     void update_body();
00094     
00095     float _angle;
00096     int _d;
00097     int _move_state;
00098     int _length;
00099     int _length_increase;
00100     
00101 };
00102 #endif