diff --git a/assets/images/ball.png b/assets/images/ball.png new file mode 100644 index 0000000..0b62c40 Binary files /dev/null and b/assets/images/ball.png differ diff --git a/breakout.c b/breakout.c new file mode 100644 index 0000000..c872dff --- /dev/null +++ b/breakout.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include +#include +#include + +#include "vector.h" + +#ifndef __nullptr__ +#define Nullptr(type) (type *)0 +#endif // __nullptr__ + +void BREAKOUT_INITIALIZE(){ + +} diff --git a/breakout.h b/breakout.h new file mode 100644 index 0000000..6c82371 --- /dev/null +++ b/breakout.h @@ -0,0 +1,32 @@ +#ifndef __breakout_h__ +#define __breakout_h__ + +#include "vector.h" + +// Structs +typedef struct ballStruct { + Vector Location, Momentum; + SDL_Rect TargetRect; +} Ball; + +typedef struct paddleStruct { + double XLocation; + SDL_Rect TargetRect; +} Paddle; + +typedef struct blockStruct { + Vector Location; + SDL_Rect TargetRect; +} Block; + +typedef struct powerupStruct { // Maybe implement later + Vector Location; + SDL_Rect TargetRect; +} Powerup; +// End Structs + +// Prototypes + +// End Prototypes + +#endif // __breakout_h__ diff --git a/main.c b/main.c index a79b008..e29ea4a 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,13 @@ #include #include -#include #include #include +#include #include +#include +#include + +#include "vector.h" #ifndef __nullptr__ #define Nullptr(type) (type *)0 diff --git a/vector.c b/vector.c new file mode 100644 index 0000000..b4ec420 --- /dev/null +++ b/vector.c @@ -0,0 +1,84 @@ +#include + +#include "vector.h" + +// Properties +const double degreeToRadians = M_PI / 180.0f; +// End Properties + +Vector vectorScale(Vector v, double factor){ + return (Vector) + { + .x = v.x * factor, + .y = v.y * factor + }; +} + +double vectorMagnitude(Vector v){ + return sqrt((v.x * v.x) + (v.y * v.y)); +} + +double vectorRotation(Vector v){ + double da = atan2(v.x, -v.y) / degreeToRadians; + + if (da < 0.0f) return (da + 360.0f); + else return da; +} + +Vector vectorScaleTo(Vector v, double magnitude){ + return vectorScale(v, magnitude / vectorMagnitude(v)); +} + +double dotProduct(Vector v1, Vector v2){ + return (v1.x * v2.x ) + (v1.y * v2.y); +} + +double vectorDist(Vector v1, Vector v2){ + return sqrt(dotProduct(v1, v2)); +} + +Vector vectorAdd(Vector v1, Vector v2){ + return (Vector) + { + .x = v1.x + v2.x, + .y = v1.y + v2.y + }; +} + +Vector vectorSub(Vector v1, Vector v2){ + return (Vector) + { + .x = v1.x - v2.x, + .y = v1.y - v2.y + }; +} + +double degreeSin(double x){ + return sin(x * degreeToRadians); +} + +double degreeCos(double x){ + return cos(x * degreeToRadians); +} + +Vector getDirectionalUnitVector(double rotation){ + return (Vector) + { + .x = degreeSin(rotation), + .y = -degreeCos(rotation) + }; +} + +Vector getScaledDirectionalUnitVector(double rotation, double Magnitude){ + Vector v = (Vector) + { + .x = degreeSin(rotation), + .y = -degreeCos(rotation) + }; + + return vectorScale(v, Magnitude); +} + +Vector getScaledVectorFromTo(Vector from, Vector to, double Magnitude){ + return vectorScale(vectorSub(to, from), Magnitude); +} diff --git a/vector.h b/vector.h new file mode 100644 index 0000000..2bbaf4d --- /dev/null +++ b/vector.h @@ -0,0 +1,26 @@ +#ifndef __vector_h__ +#define __vector_h__ + +// Structs +typedef struct vectorStruct { + double x, y; +} Vector; +// End Structs + +// Prototypes +Vector vectorScale(Vector v, double factor); +double vectorMagnitude(Vector v); +double vectorRotation(Vector v); +Vector vectorScaleTo(Vector v, double magnitude); +double dotProduct(Vector v1, Vector v2); +double vectorDist(Vector v1, Vector v2); +Vector vectorAdd(Vector v1, Vector v2); +Vector vectorSub(Vector v1, Vector v2); +double degreeSin(double x); +double degreeCos(double x); +Vector getDirectionalUnitVector(double rotation); +Vector getScaledDirectionalUnitVector(double rotation, double Magnitude); +Vector getScaledVectorFromTo(Vector from, Vector to, double Magnitude); +// End Prototypes + +#endif // __vector_h__