ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Platforms.cpp Source File

Platforms.cpp

00001 #include "Platforms.h"
00002 
00003 // Constructor and destructor.
00004 Platforms::Platforms() {} 
00005 
00006 Platforms::~Platforms() {}
00007 
00008 void Platforms::init(int y) {
00009   // Starting values for the platforms.
00010   _line_1.x_start = 0;
00011   _line_1.x_end = 15;
00012   _line_1.y = y;
00013   _line_2.x_start = 25;
00014   _line_2.x_end = 60;
00015   _line_2.y = y;
00016   _line_3.x_start = 60;
00017   _line_3.x_end = 80;
00018   _line_3.y = y;
00019 }
00020 
00021 void Platforms::set_line_1(int length) {
00022   // Lines move from R to L via de-incrementing.
00023   _line_1.x_start--; 
00024   if (_line_1.x_start < 80 - length) _line_1.x_end--;  // Only move end of the
00025   // line if the line length is fully on the screen.
00026   if (_line_1.x_start <= 0) _line_1.x_start = 0;  // Terminate line 1 start at 0 
00027   // when it reaches LHS of screen so it does not go negative.
00028   if (_line_1.x_end <= 0) {  // Start Drawing line again from start once the end 
00029   // has reaches LHS of screen.
00030     _line_1.x_start = 80;
00031     _line_1.x_end = 80;
00032   }      
00033 }
00034            
00035 void Platforms::set_line_2(int length) {
00036   // Same as set_line_1.
00037   _line_2.x_start--;
00038   if (_line_2.x_start < 80 - length) _line_2.x_end--;
00039   if (_line_2.x_start <= 0) _line_2.x_start = 0;
00040   if (_line_2.x_end <= 0) {
00041     _line_2.x_start = 80;
00042     _line_2.x_end = 80;
00043   }      
00044 }
00045     
00046 void Platforms::set_line_3(int length) {
00047   // Same as set_line_1.
00048   _line_3.x_start--;
00049   if (_line_3.x_start < 80 - length) _line_3.x_end--;
00050   if (_line_3.x_start <= 0) _line_3.x_start = 0;
00051   if (_line_3.x_end <= 0) {
00052     _line_3.x_start = 80;
00053     _line_3.x_end = 80;
00054   }  
00055 }
00056     
00057 Line Platforms::get_line_1() {
00058   return _line_1;
00059 }
00060 
00061 Line Platforms::get_line_2() {
00062   return _line_2;
00063 }
00064     
00065 Line Platforms::get_line_3() {
00066   return _line_3;
00067 }
00068     
00069     
00070    
00071