ELEC2645 (2017/18) / Mbed 2 deprecated fy15raf

Dependencies:   mbed

Revision:
12:4d7f1349d796
Parent:
9:e70179ff61c5
Child:
14:cf4a32245152
--- a/Rocket/Rocket.cpp	Thu May 03 22:34:03 2018 +0000
+++ b/Rocket/Rocket.cpp	Fri May 04 21:19:34 2018 +0000
@@ -1,6 +1,5 @@
 #include "Rocket.h"
 
-// nothing doing in the constructor and destructor
 Rocket::Rocket()
 {
 
@@ -13,41 +12,42 @@
 
 void Rocket::init()
 {
-    _x = WIDTH/2 ;  
+    //initialise the rocket position and speed
+    _x = 15 ;
     _y = HEIGHT/2 ;
-    _speed = 1;  
+    _speed = 1;
 }
 
 void Rocket::draw(N5110 &lcd)
 {
-   int sprite[7][10] =   {
-    
-    { 0,1,1,1,1,0,0,0,0,0, },
-    { 0,0,1,0,0,1,1,0,0,0, },
-    { 0,0,0,1,0,0,0,1,1,0, },
-    { 0,0,0,1,1,1,1,1,1,1, },
-    { 0,0,0,1,0,0,0,1,1,0, },
-    { 0,0,1,0,0,1,1,0,0,0, },
-    { 0,1,1,1,1,0,0,0,0,0, },
-};
+    int sprite[7][10] =   {
+
+        { 0,1,1,1,1,0,0,0,0,0, },
+        { 0,0,1,0,0,1,1,0,0,0, },
+        { 0,0,0,1,0,0,0,1,1,0, },
+        { 0,0,0,1,1,1,1,1,1,1, },
+        { 0,0,0,1,0,0,0,1,1,0, },
+        { 0,0,1,0,0,1,1,0,0,0, },
+        { 0,1,1,1,1,0,0,0,0,0, },
+    };
     lcd.drawSprite(_x,_y,7,10,(int *)sprite);
 }
 
-void Rocket::update(Direction d,float mag, N5110 &lcd)
+void Rocket::update(Direction d,float mag)
 {
-    _speed = int(mag*10.0f);  // scale is arbitrary, could be changed in future
+    _speed = int(mag*10.0f); //shows how far from the center does the rocket move based on the joystick
 
-    // update y and x values depending on direction of movement
+    // update y and x values based on direction of movement
     if (d == N) {
         _y-=_speed;
     } else if (d == S) {
         _y+=_speed;
-    }else if (d == W) {
+    } else if (d == W) {
         _x-=_speed;
     } else if (d == E) {
         _x+=_speed;
     }
-    
+
     // check the rocket coordinates so it doesn't go off screen
     if (_y < 1) {
         _y = 1;
@@ -63,56 +63,57 @@
     }
 }
 
-Vector2D Rocket::get_pos() {
+Vector2D Rocket::get_pos()
+{
     Vector2D p = {_x,_y};
-    return p;    
+    return p;
 }
 
-void Rocket::add_score()
+void Rocket::add_collisions()
 {
-    _score++;
+    _collision++;
 }
 
-int Rocket::get_score()
+int Rocket::get_collisions()
 {
-    return _score;
+    return _collision;
 }
 
 void Rocket::drawFullHearts(N5110 &lcd)
 {
-   int sprite[5][17] =   {
-    
-    { 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, },
-    { 1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1, },
-    { 1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1, },
-    { 0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0, },
-    { 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, },
-};
+    int sprite[5][17] =   {
+
+        { 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, },
+        { 1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1, },
+        { 1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1, },
+        { 0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0, },
+        { 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, },
+    };
     lcd.drawSprite(0,0,5,17,(int *)sprite);
 }
 
 void Rocket::drawTwoHearts(N5110 &lcd)
 {
-   int sprite[5][17] =   {
-    
-    { 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, },
-    { 1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1, },
-    { 1,1,1,1,1,0,1,1,1,1,1,0,1,0,0,0,1, },
-    { 0,1,1,1,0,0,0,1,1,1,0,0,0,1,0,1,0, },
-    { 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, },
-};
+    int sprite[5][17] =   {
+
+        { 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, },
+        { 1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1, },
+        { 1,1,1,1,1,0,1,1,1,1,1,0,1,0,0,0,1, },
+        { 0,1,1,1,0,0,0,1,1,1,0,0,0,1,0,1,0, },
+        { 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, },
+    };
     lcd.drawSprite(0,0,5,17,(int *)sprite);
 }
 
 void Rocket::drawOneHeart(N5110 &lcd)
 {
-   int sprite[5][17] =   {
-    
-    { 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, },
-    { 1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1, },
-    { 1,1,1,1,1,0,1,0,0,0,1,0,1,0,0,0,1, },
-    { 0,1,1,1,0,0,0,1,0,1,0,0,0,1,0,1,0, },
-    { 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, },
-};
+    int sprite[5][17] =   {
+
+        { 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, },
+        { 1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1, },
+        { 1,1,1,1,1,0,1,0,0,0,1,0,1,0,0,0,1, },
+        { 0,1,1,1,0,0,0,1,0,1,0,0,0,1,0,1,0, },
+        { 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, },
+    };
     lcd.drawSprite(1,1,5,17,(int *)sprite);
 }
\ No newline at end of file