ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Platforms.h Source File

Platforms.h

00001 #ifndef PLATFORMS_H
00002 #define PLATFORMS_H
00003 
00004 #include "mbed.h"
00005 
00006 /** Line struct */
00007 struct Line {  
00008   int x_start; /**< Integer for the start of the line. */
00009   int x_end; /**< Integer for the end of the line. */
00010   int y; /**< Integer for the Y position of the line. */
00011 };
00012 
00013 /** Platforms Class
00014 * @brief Generates a row of platforms (lines) for the skateboarder to move on 
00015 * @author Lewis Wooltorton
00016 * @date March 2019
00017 
00018 @code
00019 
00020 #include "mbed.h"
00021 #include "N5110.h"
00022 #include "Gamepad.h"
00023 #include "Platforms.h"
00024 #include <cstdlib>
00025 #include <ctime>
00026 
00027 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
00028 Gamepad gamepad;
00029 Platforms _lower_platforms;
00030 
00031 int _length_1;
00032 int _length_2;
00033 int _length_3;
00034 
00035 Line _lower_line_1;
00036 Line _lower_line_2;
00037 Line _lower_line_3;
00038 
00039 int main() {
00040   _lower_platforms.init(20);  // Set vertical height to 20;
00041   while(1) {
00042     
00043     // Set all the line lengths to random values.
00044     _length_1 = (rand() %20) + 10;    
00045     _lower_platforms.set_line_1(_length_1);
00046     _lower_line_1 = _lower_platforms.get_line_1(); 
00047     _length_2 = (rand() %20) + 10;        
00048     _lower_platforms.set_line_2(_length_2);
00049     _lower_line_2 = _lower_platforms.get_line_2();
00050     _length_3 = (rand() %20) + 10;       
00051     _lower_platforms.set_line_3(_length_3);
00052     _lower_line_3 = _lower_platforms.get_line_3();
00053     
00054     // Print lines.
00055     lcd.drawLine(_lower_line_2.x_start,_lower_line_2.y,_lower_line_2.x_end,
00056                _lower_line_2.y,FILL_BLACK);
00057     lcd.drawLine(_lower_line_1.x_start,_lower_line_1.y,_lower_line_1.x_end,
00058                _lower_line_1.y,FILL_BLACK);
00059     lcd.drawLine(_lower_line_3.x_start,_lower_line_3.y,_lower_line_3.x_end,
00060                _lower_line_3.y,FILL_BLACK);
00061   }  
00062 }    
00063 
00064 @endcode
00065 */
00066 
00067 class Platforms {
00068  public:
00069   // Constructor and Destructor.
00070   /**
00071   * @brief Constructor @details Non user specified.
00072   */
00073   Platforms();
00074   /**
00075   * @brief Destructor @details Non user specified.
00076   */
00077   ~Platforms();
00078   
00079   // Mutators.
00080   /** 
00081   * @brief Initialises Platforms object.
00082   * @param y @details The initial vertical coordinate of the platforms. 
00083   */
00084   void init(int y);
00085   /**
00086   * @brief Sets all parameters of line 1.
00087   * @param length @details the length of line 1
00088   */
00089   void set_line_1(int length);
00090   /**
00091   * @brief Sets all parameters of line 2.
00092   * @param length @details the length of line 2
00093   */
00094   void set_line_2(int length);
00095   /**
00096   * @brief Sets all parameters of line 3.
00097   * @param length @details the length of line 3
00098   */
00099   void set_line_3(int length);
00100   
00101   // Accessors.
00102   /**
00103   * @brief Gets line 1.
00104   * @returns Line 1 (type: struct, Line)
00105   */
00106   Line get_line_1();
00107   /**
00108   * @brief Gets line 2.
00109   * @returns Line 2 (type: struct, Line)
00110   */
00111   Line get_line_2();
00112   /**
00113   * @brief Gets line 3.
00114   * @returns Line 3 (type: struct, Line)
00115   */
00116   Line get_line_3();
00117     
00118  private:
00119   Line _line_1;
00120   Line _line_2;
00121   Line _line_3;
00122 };
00123 #endif
00124 
00125