I am learning OOP using c++ on a MicroBit by developing this simple game

Dependencies:   microbit

Revision:
3:a21366e3261e
Parent:
2:8f1130b99681
--- a/main.cpp	Wed Jul 08 17:48:31 2020 +0000
+++ b/main.cpp	Thu Jul 09 06:04:17 2020 +0000
@@ -2,6 +2,7 @@
 #include "Screen.h"
 #include "Bullet.h"
 #include "Spacecraft.h"
+#include "Asteroid.h"
 
 MicroBit ubit;
 MicroBitSerial serial(USBTX, USBRX);
@@ -12,17 +13,25 @@
     
     Spacecraft spacecraft;
     Bullet bullet;
+    Asteroid asteroid;
+
     bullet.setX(spacecraft.getX());
     bullet.setY(spacecraft.getY());
+    
     int rnd = 6;
+    rnd = ubit.random(5);
+    
+    asteroid.setX(rnd);
+    asteroid.setY(0);    
+    
+    int dist;
     while(true){
         
         // move spacecraft
-        rnd = ubit.random(10);
-        serial.send(rnd);
-        if(rnd >= 5)
+        rnd = ubit.random(9);
+        if(rnd > 5)
             spacecraft.moveRight();
-        else
+        else if(rnd < 3) 
             spacecraft.moveLeft();
         
         
@@ -31,10 +40,38 @@
             if(bullet.getY() == 0)
                 bullet.setX(spacecraft.getX());
             bullet.move();
+            
+            if(asteroid.hitBy(bullet)){
+                screen.draw(bullet);
+                screen.draw(spacecraft);
+                screen.draw(asteroid);
+                screen.refresh();
+                release_fiber();
+            }
+            
+            if(asteroid.getY() == 4){
+                rnd = ubit.random(5);
+                asteroid.setX(rnd);
+                serial.send(asteroid.getX());
+                serial.send(',');
+                serial.send(rnd);
+                serial.send("\n\r");
+            }
+            asteroid.move();
+            
+            if(asteroid.hitBy(bullet)){
+                screen.draw(bullet);
+                screen.draw(spacecraft);
+                screen.draw(asteroid);
+                screen.refresh();
+                release_fiber();
+            }
+            
             ubit.sleep(200);
             
             screen.draw(bullet);
             screen.draw(spacecraft);
+            screen.draw(asteroid);
             screen.refresh();
         }