Elements used in the Balls and Things games for the RETRO.

Dependents:   RETRO_BallsAndPaddle RETRO_BallAndHoles

Revision:
0:3d0db4e183ee
Child:
2:74bc9b16fb88
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Vector.cpp	Fri Feb 06 09:51:06 2015 +0000
@@ -0,0 +1,60 @@
+#include "Vector.h"
+
+Vector::Vector()
+{   // constructor
+    this->set((float)0,(float)0);
+}
+
+Vector::Vector(float fX, float fY)
+{
+    this->set(fX, fY);
+}
+
+void Vector::set(float fX, float fY)
+{
+    x=fX;
+    y=fY;
+}
+void Vector::set(int nX, int nY)
+{
+    this->set((float)nX, (float)nY);
+}
+
+float Vector::getSize()
+{   // get the size of the vector
+    return(sqrt(x*x+y*y));
+}
+
+bool Vector::isLeft()  { return(x<0); }
+bool Vector::isRight() { return(x>0); }
+bool Vector::isUp()    { return(y<0); }
+bool Vector::isDown()  { return(y>0); }
+
+
+void Vector::add(float fAdd)
+{   // add the size of the vector by adding to its size
+    float fSize=getSize();
+    float fSizeNew=fSize+fAdd;
+    if(fSize!=0)
+    {
+        x=x * (fSizeNew/fSize);
+        y=y * (fSizeNew/fSize);
+    }
+    else
+    {   // in case of zero lenght, default to addition in first quadrant.
+        x=sqrt(0.5 * fAdd * fAdd);
+        y=x;
+    }
+}
+
+void Vector::add(Vector vAdd)
+{
+    x+=vAdd.x;
+    y+=vAdd.y;
+}
+
+void Vector::multiply(Vector vMult)
+{   // multiply the vector by means of the other vector
+    x*=vMult.x;
+    y*=vMult.y;
+}
\ No newline at end of file