ELEC2645 (2017/18) / Mbed 2 deprecated fy15raf

Dependencies:   mbed

Revision:
12:4d7f1349d796
Parent:
11:cb48d596aa3e
diff -r cb48d596aa3e -r 4d7f1349d796 Asteroids/Asteroid.cpp
--- a/Asteroids/Asteroid.cpp	Thu May 03 22:34:03 2018 +0000
+++ b/Asteroids/Asteroid.cpp	Fri May 04 21:19:34 2018 +0000
@@ -12,12 +12,12 @@
 
 void Asteroid::init(float speed)
 {
+    //initialise the Asteroid position, speed and size
     _size = 5;
-    _x = WIDTH - _size;
 
-   // srand(time(NULL));
+    _x = WIDTH - _size;
     _y1 = rand()%(HEIGHT); // random initial position on y-axis.
-//_y1 =22;
+
     _velocity.x = speed;
 }
 
@@ -26,14 +26,14 @@
 
     int sprite[6][11] =   {
 
-        
+
         { 0,0,1,1,0,1,0,0,1,1,0, },
         { 0,1,1,1,1,1,1,0,0,0,0, },
         { 1,1,0,1,1,1,0,1,0,0,0, },
         { 1,1,1,1,1,1,1,1,0,1,1, },
         { 0,1,1,1,0,1,1,0,0,0,0, },
         { 0,0,0,1,1,1,0,0,1,1,0, },
-         
+
     };
     lcd.drawSprite(_x,_y1,6,11,(int *)sprite);
 }
@@ -43,9 +43,8 @@
     if(_x>0) {
         _x -= _velocity.x;
     } else {
-        _x = WIDTH - _size; //start from the begining again
-        _y1= rand()%(HEIGHT);
-        //_y1 =22;
+        _x = WIDTH - _size;      //start from the begining again
+        _y1= rand()%(HEIGHT-6);    // with random position on y-axis.
     }
 }