Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Map/Map.h

Committer:
evanso
Date:
2020-04-26
Revision:
14:7419c680656f
Parent:
13:12276eed13ac
Child:
15:90b6821bcf64

File content as of revision 14:7419c680656f:

#ifndef MAP_H
#define MAP_H
 
// Include libraries -----------------------------------------------------------
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"

/** Map class
@brief Draws 
@author Benjamin Evans, University of Leeds
@date April 2020
*/

class Map {
    public:
        /** Constructor */
        Map();
        
        /** Destructor */
        ~Map();
        
        /** Initalises Spaceship 
        * @param pad @details Gampad object
        */
        void init(Gamepad &pad); 
        
        /** Draws map out of combination of random hight traingle and random 
        * length lines so map is differnt each new game and loops roudn at ends
        * @param lcd, move_map @details N5110 object and variable to move x postion of map
        */
        void draw_map(N5110 &lcd, int move_map);
         
        /** Gets 11 random integers for random lengths and hights arrays 
        * and fills arrays with  the random integers so same random map is drawn each frame
        * @param Pad @details Gampad adc object used to generate seed 
        */
        void fill_random_arrays(Gamepad &pad);
    
        // Accessors and mutators ----------------------------------------------
        
        /** Gets x postion of the map 
        * @return maps x postion 
        */
        int get_position_x_map(); 
       
    private:
        // Functions prototypes ------------------------------------------------
    
        /** Draws a triangle from position with specified hight wich represents a mountain of the map
         * @param lcd, tirangle_height @details N5110 object and teh random hight of triangle produced
         */
        void draw_triangle(N5110 &lcd, int triangle_height);
        
        /** Draws a horizontal line with specified length to represent flat land on map
         * @param lcd, tirangle_height @details N5110 object and random length of line produced
         */
        void draw_line(N5110 &lcd, int line_length);
        
       /** Duplicates the first part of the map to fill the gap when the map loops round
        * @ param lcd @details N5110 object
        */
        void check_duplicates_map_forward(N5110 &lcd);
    
       /** Duplicates the last part of the map to fill the gap when the map loops round
        * @ param lcd @details N5110 object
        */
        void check_duplicates_map_backwards(N5110 &lcd);
    
        // Variables -----------------------------------------------------------
    
        // Map x postion on lcd
        int position_x_map_;
        
        // Map y postion on lcd
        int position_y_map_;
        
        // Float to store random seed for random function 
        float rand_seed_;
        
        // Map length 
        int map_length_;
        
        // Arrays to hold random heights of triangles and lengths of lines
        int rand_heights_[12]; 
        int rand_lengths_[12];
        
        // To store the final element used in the random array befor the break in draw map
        int final_random_element_used_; 
        
        //Required to reset the map to it's origonal postion at end of each frame, as draw line and triangle functions change position_x_map_
        int reset_position_x_map_to_origonal_;    
};
 
#endif