ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Revision:
18:304700b5d8f8
Parent:
15:876c047a6ec9
Child:
21:20478f086bc2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Platforms/Platforms.cpp	Fri Apr 12 11:30:25 2019 +0000
@@ -0,0 +1,66 @@
+#include "Platforms.h"
+
+// Constructor and destructor
+Platforms::Platforms() {} 
+
+Platforms::~Platforms() {}
+
+void Platforms::init(int y) {
+  // Starting values for the platforms
+  _line_1.x_start = 0;
+  _line_1.x_end = 15;
+  _line_1.y = y;
+  _line_2.x_start = 25;
+  _line_2.x_end = 60;
+  _line_2.y = y;
+  _line_3.x_start = 60;
+  _line_3.x_end = 80;
+  _line_3.y = y;
+}
+
+void Platforms::generate_line_1(int length) {
+  // Always move the line from L to R, and only move the end of the line
+  // if the start has not gone off the screen. If it has, start again.
+  _line_1.x_start--; 
+  if(_line_1.x_start < 80 - length) _line_1.x_end--;
+  if(_line_1.x_start <= 0) _line_1.x_start = 0;
+  if(_line_1.x_end <= 0) {
+    _line_1.x_start = 80;
+    _line_1.x_end = 80;
+  }      
+}
+           
+void Platforms::generate_line_2(int length) {
+  _line_2.x_start--;
+  if(_line_2.x_start < 80 - length) _line_2.x_end--;
+  if(_line_2.x_start <= 0) _line_2.x_start = 0;
+  if(_line_2.x_end <= 0) {
+    _line_2.x_start = 80;
+    _line_2.x_end = 80;
+  }      
+}
+    
+void Platforms::generate_line_3(int length) {
+  _line_3.x_start--;
+  if(_line_3.x_start < 80 - length) _line_3.x_end--;
+  if(_line_3.x_start <= 0) _line_3.x_start = 0;
+  if(_line_3.x_end <= 0) {
+    _line_3.x_start = 80;
+    _line_3.x_end = 80;
+  }  
+}
+    
+Line Platforms::get_line_1() {
+  return _line_1;
+}
+
+Line Platforms::get_line_2() {
+  return _line_2;
+}
+    
+Line Platforms::get_line_3() {
+  return _line_3;
+}
+    
+    
+