diff --git a/assets/ColTex.png b/assets/ColTex.png index 4bb3142..6e1708b 100644 Binary files a/assets/ColTex.png and b/assets/ColTex.png differ diff --git a/build/BeagleRescue b/build/BeagleRescue index d900e1f..ace83dc 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/assetmgr/TextureManager.cpp b/src/assetmgr/TextureManager.cpp index f920713..594a349 100644 --- a/src/assetmgr/TextureManager.cpp +++ b/src/assetmgr/TextureManager.cpp @@ -17,6 +17,18 @@ SDL_Texture* TextureManager::LoadTexture(const char* texture) void TextureManager::Draw(SDL_Texture* tex, SDL_Rect src, SDL_Rect dest, SDL_RendererFlip flip) { - SDL_RenderCopyEx(Game::renderer, tex, &src, &dest, NULL, NULL, flip); } + +void TextureManager::DrawCollider(SDL_Rect colliderRect) +{ + Vector2D pt1, pt2, pt3, pt4; + pt1 = Vector2D(colliderRect.x,colliderRect.y); + pt2 = Vector2D(colliderRect.w-2,colliderRect.y); + pt3 = Vector2D(colliderRect.x,colliderRect.h-2); + pt4 = Vector2D(colliderRect.w-2,colliderRect.h-2); + Game::drawLine(pt1,pt2,255,0,255); + Game::drawLine(pt1,pt3,255,255,0); + Game::drawLine(pt2,pt4,0,0,255); + Game::drawLine(pt3,pt4,0,255,0); +} diff --git a/src/assetmgr/TextureManager.h b/src/assetmgr/TextureManager.h index bca14d0..e45bc73 100644 --- a/src/assetmgr/TextureManager.h +++ b/src/assetmgr/TextureManager.h @@ -16,8 +16,7 @@ class TextureManager public: static SDL_Texture* LoadTexture(const char* fileName); static void Draw(SDL_Texture* tex, SDL_Rect src, SDL_Rect dest, SDL_RendererFlip flip); + static void DrawCollider(SDL_Rect colliderRect); }; - - #endif /* SRC_TEXTUREMANAGER_H_ */ diff --git a/src/ecs/ColliderComponent.h b/src/ecs/ColliderComponent.h index 6582ca4..ef4f61d 100644 --- a/src/ecs/ColliderComponent.h +++ b/src/ecs/ColliderComponent.h @@ -23,6 +23,9 @@ public: SDL_Texture* tex; SDL_Rect srcR, destR; + + int offsetX = 0; + int offsetY = 0; TransformComponent* transform; @@ -42,11 +45,13 @@ public: collider.w = collider.h = size*scale; } - ColliderComponent(std::string t, int width, int height) + ColliderComponent(std::string t, int width, int height, bool hasOffset, int oX, int oY) { tag = t; collider.w = width; collider.h = height; + offsetX = oX; + offsetY = oY; } void init() override @@ -56,18 +61,21 @@ public: entity->addComponent(); } transform = &entity->getComponent(); - + collider.x = collider.x + offsetX; + collider.y = collider.y + offsetX; tex = TextureManager::LoadTexture("assets/ColTex.png"); srcR = { 0, 0, 16, 16}; destR = { collider.x, collider.y, collider.w, collider.h }; -// if(tag == "player"){ -// destR = { 18, 28, 24, 24 }; -// transform->height = 24; -// transform->width = 24; -// std::cout << "player collider init() ran" << std::endl; -// std::cout << "destR.w: " << destR.w << std::endl; -// std::cout << "destR.h: " << destR.h << std::endl; -// } +// if(tag == "player"){ +// destR = { 18, 28, 24, 24 }; +// collider.w = 16; +// collider.h = 16; +// transform->height = 24; +// transform->width = 24; +// std::cout << "player collider init() ran" << std::endl; +// std::cout << "destR.w: " << destR.w << std::endl; +// std::cout << "destR.h: " << destR.h << std::endl; +// } // Game::colliders.push_back(this); } @@ -75,20 +83,15 @@ public: { if(tag != "terrain") { - collider.x = static_cast(transform->position.x); - collider.y = static_cast(transform->position.y); - collider.w = transform->width * transform->scale; - collider.h = transform->height * transform->scale; + collider.x = static_cast(transform->position.x+offsetX); + collider.y = static_cast(transform->position.y+offsetY); +// collider.w = transform->width * transform->scale; +// collider.h = transform->height * transform->scale; // collider.w = 12 * transform->scale; // collider.h = 12 * transform->scale; -// -// std::cout << "collider.w: " << collider.w << std::endl; -// std::cout << "collider.h: " << collider.h << std::endl; -// std::cout << "tag: " << tag << std::endl; } destR.x = collider.x - Game::camera.x; destR.y = collider.y - Game::camera.y; -// std::cout << "tag: " << tag << std::endl; } void draw() override @@ -96,8 +99,10 @@ public: if(tag == "terrain") { TextureManager::Draw(tex, srcR, destR, SDL_FLIP_NONE); - } +// TextureManager::DrawCollider(destR); + } } + }; diff --git a/src/ecs/KeyboardController.h b/src/ecs/KeyboardController.h index 428c600..6bf7f63 100644 --- a/src/ecs/KeyboardController.h +++ b/src/ecs/KeyboardController.h @@ -98,10 +98,11 @@ public: } break; case SDLK_k: - if (Game::debugCollisionBoxes) - { Game::debugCollisionBoxes = false; } + SDL_Delay(100); + if (!Game::debugCollisionBoxes) + { Game::debugCollisionBoxes = true; } else - {Game::debugCollisionBoxes = true; } + {Game::debugCollisionBoxes = false; } break; case SDLK_j: transform->velocity.y = 0; diff --git a/src/game/Game.cpp b/src/game/Game.cpp index 49e74b0..9463acc 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -137,7 +137,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g // player.addComponent(150*globalScale,80*globalScale,40,40,globalScale); player.addComponent("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json"); player.addComponent(); - player.addComponent("player"); + player.addComponent("player",8*globalScale,8*globalScale, true, 7*globalScale,36*globalScale); player.addGroup(groupPlayers); puppy.addComponent(1024*globalScale,210*globalScale,36,30,globalScale); @@ -188,13 +188,13 @@ void Game::update() if (Mix_PlayingMusic() == 0) { // std::cout << "Play Music Now" << std::endl; - Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1); +// Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1); } - if (Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0) == 0) - { - Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0); - } +// if (Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0) == 0) +// { +// Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0); +// } manager.refresh(); manager.update(); @@ -210,8 +210,6 @@ void Game::update() } gravityOnPlayer = false; playerIsGrounded = true; - - } } @@ -242,7 +240,6 @@ void Game::update() camera.y = map->height-camera.h; } - void Game::render() { SDL_RenderClear(renderer); @@ -288,6 +285,20 @@ void Game::render() // destPt.x = 320.0*gScale; // destPt.y = 240.0*gScale; // drawLine(origPt,destPt,255,0,0); +// Vector2D pt1, pt2, pt3, pt4; +// pt1.x = 80.0*gScale; +// pt1.y = 80.0*gScale; +// pt2.x = 120.0*gScale; +// pt2.y = 80.0*gScale; +// pt3.x = 80.0*gScale; +// pt3.y = 120.0*gScale; +// pt4.x = 120.0*gScale; +// pt4.y = 120.0*gScale; +// Draw box with colors +// drawLine(pt1,pt2,0,0,255); +// drawLine(pt1,pt3,0,255,0); +// drawLine(pt2,pt4,255,255,0); +// drawLine(pt3,pt4,255,0,0); SDL_RenderPresent(renderer); } @@ -307,8 +318,8 @@ void Game::printDebug(char* debugInfo) printf("\n"); } -// void Game::drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blue) -// { -// SDL_SetRenderDrawColor(renderer, red, green, blue, 255); -// SDL_RenderDrawLine(renderer, srcpt.x, srcpt.y, destpt.x, destpt.y); -// } +void Game::drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blue) +{ + SDL_SetRenderDrawColor(renderer, red, green, blue, 255); + SDL_RenderDrawLine(renderer, srcpt.x, srcpt.y, destpt.x, destpt.y); +} diff --git a/src/game/Game.hpp b/src/game/Game.hpp index 908b9e9..be6af5b 100644 --- a/src/game/Game.hpp +++ b/src/game/Game.hpp @@ -29,7 +29,7 @@ public: void render(); void clean(); void printDebug(char* debugInfo); -// 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; } // static void AddTile(int srcX, int srcY, int xpos, int ypos); static SDL_Renderer *renderer;