ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Platforms Class Reference

Platforms Class Reference

Platforms Class. More...

#include <Platforms.h>

Public Member Functions

 Platforms ()
 Constructor.
 ~Platforms ()
 Destructor.
void init (int y)
 Initialises Platforms object.
void set_line_1 (int length)
 Sets all parameters of line 1.
void set_line_2 (int length)
 Sets all parameters of line 2.
void set_line_3 (int length)
 Sets all parameters of line 3.
Line get_line_1 ()
 Gets line 1.
Line get_line_2 ()
 Gets line 2.
Line get_line_3 ()
 Gets line 3.

Detailed Description

Platforms Class.

Generates a row of platforms (lines) for the skateboarder to move on

Author:
Lewis Wooltorton
Date:
March 2019
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
#include "Platforms.h"
#include <cstdlib>
#include <ctime>

N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad gamepad;
Platforms _lower_platforms;

int _length_1;
int _length_2;
int _length_3;

Line _lower_line_1;
Line _lower_line_2;
Line _lower_line_3;

int main() {
  _lower_platforms.init(20);  // Set vertical height to 20;
  while(1) {
    
    // Set all the line lengths to random values.
    _length_1 = (rand() %20) + 10;    
    _lower_platforms.set_line_1(_length_1);
    _lower_line_1 = _lower_platforms.get_line_1(); 
    _length_2 = (rand() %20) + 10;        
    _lower_platforms.set_line_2(_length_2);
    _lower_line_2 = _lower_platforms.get_line_2();
    _length_3 = (rand() %20) + 10;       
    _lower_platforms.set_line_3(_length_3);
    _lower_line_3 = _lower_platforms.get_line_3();
    
    // Print lines.
    lcd.drawLine(_lower_line_2.x_start,_lower_line_2.y,_lower_line_2.x_end,
               _lower_line_2.y,FILL_BLACK);
    lcd.drawLine(_lower_line_1.x_start,_lower_line_1.y,_lower_line_1.x_end,
               _lower_line_1.y,FILL_BLACK);
    lcd.drawLine(_lower_line_3.x_start,_lower_line_3.y,_lower_line_3.x_end,
               _lower_line_3.y,FILL_BLACK);
  }  
}    

Definition at line 67 of file Platforms.h.


Constructor & Destructor Documentation

Platforms (  )

Constructor.

Non user specified.

Definition at line 4 of file Platforms.cpp.

~Platforms (  )

Destructor.

Non user specified.

Definition at line 6 of file Platforms.cpp.


Member Function Documentation

Line get_line_1 (  )

Gets line 1.

Returns:
Line 1 (type: struct, Line)

Definition at line 57 of file Platforms.cpp.

Line get_line_2 (  )

Gets line 2.

Returns:
Line 2 (type: struct, Line)

Definition at line 61 of file Platforms.cpp.

Line get_line_3 (  )

Gets line 3.

Returns:
Line 3 (type: struct, Line)

Definition at line 65 of file Platforms.cpp.

void init ( int  y )

Initialises Platforms object.

Parameters:
yThe initial vertical coordinate of the platforms.

Definition at line 8 of file Platforms.cpp.

void set_line_1 ( int  length )

Sets all parameters of line 1.

Parameters:
lengththe length of line 1

Definition at line 21 of file Platforms.cpp.

void set_line_2 ( int  length )

Sets all parameters of line 2.

Parameters:
lengththe length of line 2

Definition at line 35 of file Platforms.cpp.

void set_line_3 ( int  length )

Sets all parameters of line 3.

Parameters:
lengththe length of line 3

Definition at line 46 of file Platforms.cpp.