Compare commits

..

No commits in common. "31e16585d1968592b08eabeccc1fa10e9e54ac1d" and "de99b127b1c6d1f18a71b416ff03390b2843b0d1" have entirely different histories.

7 changed files with 19 additions and 42 deletions

Binary file not shown.

View File

@ -1,7 +0,0 @@
Collision Stats:
Player Center
x: 871
y: 690
ObjectCollider Center
x: 872
y: 696

View File

@ -70,21 +70,19 @@ public:
spriteType = sType; spriteType = sType;
if(sType == spriteAnimation) if(sType == spriteAnimation)
{ {
// std::string bogusPath = "src/config/credits.json"; std::string bogusPath = "src/config/credits.json";
// std::ifstream fin(bogusPath); std::ifstream fin(bogusPath);
std::ifstream fin(json);
if(fin.is_open()){ if(fin.is_open()){
// std::cout<<"file is open"<<std::endl; std::cout<<"file is open"<<std::endl;
} else { } else {
std::cout<<"json file is NOT open"<<std::endl; std::cout<<"file is NOT open"<<std::endl;
} }
if(fin.fail()){ if(fin.fail()){
std::cout<<"json file open fail"<<std::endl; std::cout<<"file open fail"<<std::endl;
} else{ } else{
// std::cout<<"json file open success"<<std::endl; std::cout<<"file open success"<<std::endl;
} }
std::ifstream jsonText(json); std::ifstream jsonText(json);
@ -113,7 +111,7 @@ public:
int toFrame = cJSON_GetObjectItem(animItem, "to")->valueint; int toFrame = cJSON_GetObjectItem(animItem, "to")->valueint;
Animation anim = Animation(fromFrame,toFrame,100); Animation anim = Animation(fromFrame,toFrame,100);
animations.emplace(name, anim); animations.emplace(name, anim);
// printf("Adding animation named: %s fromFrame:%d toFrame:%d \n",name,fromFrame,toFrame); // printf("Playing animation named: %s fromFrame:%d toFrame:%d \n",name,fromFrame,toFrame);
Play(name); Play(name);
} }

View File

@ -11,14 +11,15 @@
bool Collision::AABB(const SDL_Rect& recA, const SDL_Rect& recB) bool Collision::AABB(const SDL_Rect& recA, const SDL_Rect& recB)
{ {
if( if(
recA.x + recA.w > recB.x && recA.x + recA.w >= recB.x &&
recB.x + recB.w > recA.x && recB.x + recB.w >= recA.x &&
recA.y + recA.h > recB.y && recA.y + recA.h >= recB.y &&
recB.y + recB.h > recA.y recB.y + recB.h >= recA.y
) )
{ {
return true; return true;
} }
return false; return false;
} }
@ -27,10 +28,6 @@ bool Collision::AABB(const ColliderComponent& colA, const ColliderComponent& col
if(AABB(colA.collider, colB.collider)) if(AABB(colA.collider, colB.collider))
{ {
// std::cout << colA.tag << " hit: " << colB.tag << std::endl; // std::cout << colA.tag << " hit: " << colB.tag << std::endl;
// if(recA.x + recA.w >= recB.x) { printf("LeftCollision"); }
// if(recB.x + recB.w >= recA.x) { printf("RightCollision"); }
// if(recA.y + recA.h >= recB.y) { printf("TopCollision"); }
// if(recB.y + recB.h >= recA.y) { printf("BottomCollision"); }
return true; return true;
} }
else else

View File

@ -9,7 +9,6 @@
#define SRC_COLLISION_H_ #define SRC_COLLISION_H_
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
// #include "Vector2D.h"
class ColliderComponent; class ColliderComponent;
@ -18,7 +17,6 @@ class Collision
public: public:
static bool AABB(const SDL_Rect& recA, const SDL_Rect& recB); static bool AABB(const SDL_Rect& recA, const SDL_Rect& recB);
static bool AABB(const ColliderComponent& colA, const ColliderComponent& colB); static bool AABB(const ColliderComponent& colA, const ColliderComponent& colB);
// void showColType();
}; };

View File

@ -121,8 +121,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
map = new Map("terrain",globalScale,16); map = new Map("terrain",globalScale,16);
// std::string myText = "Find lost puppies!\nThey need your help!"; std::string myText = "Find lost puppies!\nThey need your help!";
std::string myText = "Press U to Start";
text = new UIText(myText, "font", 0, 0, 8, 12, globalScale); text = new UIText(myText, "font", 0, 0, 8, 12, globalScale);
text->ParseString(myText, 12, 22, globalScale, "text"); text->ParseString(myText, 12, 22, globalScale, "text");
@ -231,9 +230,7 @@ void Game::update()
SDL_Rect cCol = c->getComponent<ColliderComponent>().collider; SDL_Rect cCol = c->getComponent<ColliderComponent>().collider;
if(Collision::AABB(cCol, playerCol)) if(Collision::AABB(cCol, playerCol))
{ {
// printDebug("Collision Detected"); // printf("Collision detected!\nplayerIsGrounded:%d if 0: idle plays\n",playerIsGrounded);
// printf("Collision Stats:\nPlayer Center\nx: %d\ny: %d\nObjectCollider Center\nx: %d\ny: %d\n",(playerCol.x+playerCol.w/2)/gScale,(playerCol.y+playerCol.h/2)/gScale,(cCol.x+cCol.w/2)/gScale,(cCol.y+cCol.h/2)/gScale);
// printDebug("");
if(!playerIsGrounded){ if(!playerIsGrounded){
player.getComponent<SpriteComponent>().Play("Idle"); player.getComponent<SpriteComponent>().Play("Idle");
} }
@ -327,16 +324,10 @@ void Game::clean()
printf("Game Cleaned\n"); printf("Game Cleaned\n");
} }
std::string previousMessage = ""; void Game::printDebug(char* debugInfo)
void Game::printDebug(std::string debugInfo)
{ {
if (previousMessage != debugInfo) printf("%s",debugInfo);
{
std::cout << debugInfo;
printf("\n"); printf("\n");
}
previousMessage = debugInfo;
} }
void Game::drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blue) void Game::drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blue)

View File

@ -29,7 +29,7 @@ public:
void update(); void update();
void render(); void render();
void clean(); void clean();
void printDebug(std::string debugInfo); void printDebug(char* debugInfo);
static void drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blue); static void drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blue);
bool running() { return isRunning; } bool running() { return isRunning; }
// static void AddTile(int srcX, int srcY, int xpos, int ypos); // static void AddTile(int srcX, int srcY, int xpos, int ypos);