From 21e373d1ec022544d690f99873cfd6e45fa26069 Mon Sep 17 00:00:00 2001 From: SoloArchx250 Date: Sat, 30 May 2020 17:25:19 -0400 Subject: [PATCH] working on collision detection --- src/phys_obj.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/phys_obj.h | 4 ++++ 2 files changed, 51 insertions(+) diff --git a/src/phys_obj.cpp b/src/phys_obj.cpp index 8c83efd..5347099 100644 --- a/src/phys_obj.cpp +++ b/src/phys_obj.cpp @@ -1,5 +1,9 @@ #include "phys_obj.h" +#ifndef PI +#define PI 3.14159265359 +#endif + phys_obj::phys_obj(Quad object, Vector init_vel) { this->obj=object; this->velocity=init_vel; @@ -12,4 +16,47 @@ void phys_obj::force(Vector vec) { void phys_obj::render(SDL_Renderer *rend) { obj.render(rend); bounds.render(rend); +} + +void phys_obj::translate(Vector vec) { + obj.translate(vec); + bounds.update(); +} + +bool phys_obj::checkCollision(phys_obj o) { +} + +void phys_obj::calculate_vectors(std::vector objects) { + for(int i=0; i 0) { + objects[i].velocity.x--; + step.x = 1; + } + } + } + if(yvel != 0) { + if(yvel < 0) { + objects[i].velocity.y++; + step.y = -1; + } else { + if(yvel > 0) { + objects[i].velocity.y--; + step.y = 1; + } + } + } + objects[i].translate(step); + for(int y=0; y class phys_obj { public: @@ -8,4 +9,7 @@ class phys_obj { phys_obj(Quad object, Vector init_vel); void force(Vector vec); void render(SDL_Renderer *rend); + static void calculate_vectors(std::vector objects); + void translate(Vector vec); + bool checkCollision(phys_obj o); }; \ No newline at end of file