Harry Rance 200925395 Embedded Systems Project

Dependencies:   mbed

Revision:
2:50feb42b982c
Parent:
0:c9bf674fe0c7
Child:
5:2eb139b24219
diff -r 95d7dd44bb0d -r 50feb42b982c AliensArray.cpp
--- a/AliensArray.cpp	Thu Apr 13 13:30:39 2017 +0000
+++ b/AliensArray.cpp	Wed Apr 26 17:40:17 2017 +0000
@@ -13,15 +13,13 @@
 
 void AliensArray::initialise(int x_origin, int y_origin, int speed)
 {
-
   _x = x_origin;
   _y = y_origin;
 
-
   int direction = 0;
 
   if (direction == 0) {
-    _velocity.x = speed;
+    _velocity.x = speed * 1.5;
   } else if (direction == 1) {
     _velocity.x = -speed;
   }
@@ -37,53 +35,59 @@
 void AliensArray::draw(N5110 &lcd)
 {
   type_1_draw(lcd);
-  type_2_draw(lcd);
-  type_3_draw(lcd);
+  type_1_1_draw(lcd);
   lcd.drawRect (0,0,84,48,0);
+
 }
 
 void AliensArray::type_1_draw(N5110 &lcd)
 {
-  _x_origin = _x/8;
-  _y_origin = _y;
-
-  for (int i = 0; i < 46; i+= 5){
-    lcd.setPixel((_x_origin+10+i)-1,(_y_origin+10)-1);
-    lcd.setPixel((_x_origin+10+i),(_y_origin+10)-1);
-    lcd.setPixel((_x_origin+10+i),(_y_origin+10)+1);
-    lcd.setPixel((_x_origin+10+i)-1,(_y_origin+10)+1);
-    lcd.setPixel((_x_origin+10+i)+1,(_y_origin+10));
-  }
-}
-
-void AliensArray::type_2_draw(N5110 &lcd)
-{
+  int add_x = 0;
   _x_origin = _x/8;
   _y_origin = _y;
+  for (int j = 0; j < 11; j++){
+    add_x +=5;
+    _array_x[0][j] = add_x;
 
-  for (int i = 0; i < 46; i+= 5){
-    lcd.setPixel((_x_origin+10+i),(_y_origin+16));
-    lcd.setPixel((_x_origin+10+i)-1,(_y_origin+16));
-    lcd.setPixel((_x_origin+10+i)+1,(_y_origin+16));
-    lcd.setPixel((_x_origin+10+i)+1,(_y_origin+16)-1);
-    lcd.setPixel((_x_origin+10+i)+1,(_y_origin+16)+1);
   }
+
+  for (int scan_j = 0; scan_j < 11; scan_j++){
+    int ind = _array_x[0][scan_j];
+
+    if (array_active[0][scan_j] == 1){
+      lcd.setPixel((_x_origin+10+ind)-1,(_y_origin+10)-1);
+      lcd.setPixel((_x_origin+10+ind),(_y_origin+10)-1);
+      lcd.setPixel((_x_origin+10+ind),(_y_origin+10)+1);
+      lcd.setPixel((_x_origin+10+ind)-1,(_y_origin+10)+1);
+      lcd.setPixel((_x_origin+10+ind)+1,(_y_origin+10));
+    }
+  }
+
 }
 
-void AliensArray::type_3_draw(N5110 &lcd)
+void AliensArray::type_1_1_draw(N5110 &lcd)
 {
+  int add_x = 0;
   _x_origin = _x/8;
   _y_origin = _y;
+  for (int j = 0; j < 11; j++){
+    add_x +=5;
+    _array_x[1][j] = add_x;
 
-  for (int i = 0; i < 46; i+= 5){
-    lcd.setPixel((_x_origin+10+i),(_y_origin+22));
-    lcd.setPixel((_x_origin+10+i)-1,(_y_origin+22)-1);
-    lcd.setPixel((_x_origin+10+i),(_y_origin+22)-1);
-    lcd.setPixel((_x_origin+10+i)-1,(_y_origin+22));
-    lcd.setPixel((_x_origin+10+i)+1,(_y_origin+22));
-    lcd.setPixel((_x_origin+10+i)-1,(_y_origin+22)+1);
-    lcd.setPixel((_x_origin+10+i),(_y_origin+22)+1);
   }
+
+  for (int scan_j = 0; scan_j < 11; scan_j++){
+    int ind = _array_x[1][scan_j];
+
+    if (array_active[1][scan_j] == 1){
+      lcd.setPixel((_x_origin+10+ind)-1,(_y_origin+16)-1);
+      lcd.setPixel((_x_origin+10+ind),(_y_origin+16)-1);
+      lcd.setPixel((_x_origin+10+ind),(_y_origin+16)+1);
+      lcd.setPixel((_x_origin+10+ind)-1,(_y_origin+16)+1);
+      lcd.setPixel((_x_origin+10+ind)+1,(_y_origin+16));
+    }
+  }
+
 }
 
 Vector2D AliensArray::get_velocity()