diff --git a/build/BeagleRescue b/build/BeagleRescue index 6cc7b5a..dd67129 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/assetmgr/Map.cpp b/src/assetmgr/Map.cpp index af91a13..a2aeb32 100644 --- a/src/assetmgr/Map.cpp +++ b/src/assetmgr/Map.cpp @@ -60,7 +60,7 @@ void Map::LoadMap(std::string path, int sizeX, int sizeY, int scale) if (c == '1') { auto& tcol(manager.addEntity()); - tcol.addComponent("terrain",x*scaledSize,y*scaledSize,tileSize,scale); + tcol.addComponent("terrain",x*scaledSize,y*scaledSize,tileSize,scale,texID); tcol.addGroup(Game::groupColliders); } mapFile.ignore(2,','); diff --git a/src/ecs/ColliderComponent.h b/src/ecs/ColliderComponent.h index e2ba884..383c306 100644 --- a/src/ecs/ColliderComponent.h +++ b/src/ecs/ColliderComponent.h @@ -36,21 +36,23 @@ public: tag = t; } - ColliderComponent(std::string t, int xpos, int ypos, int size, int scale) + ColliderComponent(std::string t, int xpos, int ypos, int size, int scale, std::string texture) { tag = t; collider.x = xpos; collider.y = ypos; collider.w = collider.h = size*scale; + setTex(texture); } - ColliderComponent(std::string t, int width, int height, bool hasOffset, int oX, int oY) + ColliderComponent(std::string t, int width, int height, bool hasOffset, int oX, int oY, std::string texture) { tag = t; collider.w = width; collider.h = height; offsetX = oX; offsetY = oY; + setTex(texture); } void init() override @@ -89,6 +91,11 @@ public: TextureManager::Draw(tex, srcR,destR,SDL_FLIP_NONE); } } + + void setTex(std::string id) + { + tex = Game::assets->GetTexture(id); + } }; diff --git a/src/ecs/KeyboardController.h b/src/ecs/KeyboardController.h index a8da003..ee59dcb 100644 --- a/src/ecs/KeyboardController.h +++ b/src/ecs/KeyboardController.h @@ -16,7 +16,7 @@ class KeyboardController : public Component { public: -// bool keyIsAlreadyPressed[]; + TransformComponent *transform; SpriteComponent *sprite; diff --git a/src/game/Game.cpp b/src/game/Game.cpp index f9377b2..55c4efa 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -114,6 +114,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g assets->AddTexture("font", "assets/textures/ui/ui-font-cloud-sans.png"); assets->AddTexture("textBox", "assets/textures/ui/ui-element-cloud.png"); assets->AddTexture("puppy","assets/textures/actors/beaglepuppy.png"); + assets->AddTexture("collider","assets/textures/ColTex.png"); assets->AddMusicTrack("simonZ","assets/audio/music/sillypuppy.ogg"); assets->AddMusicTrack("simonZ","assets/audio/music/victory.ogg"); @@ -153,11 +154,11 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale); - player.addComponent(860*globalScale,630*globalScale,22,42,globalScale); + player.addComponent(860*globalScale,540*globalScale,22,42,globalScale); // player.addComponent(150*globalScale,80*globalScale,40,40,globalScale); player.addComponent("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json"); player.addComponent(); - player.addComponent("player",8*globalScale,8*globalScale, true, 7*globalScale,36*globalScale); + player.addComponent("player",8*globalScale,8*globalScale, true, 7*globalScale,34*globalScale, "collider"); player.addGroup(groupPlayers); puppy.addComponent(1024*globalScale,210*globalScale,36,30,globalScale); @@ -227,7 +228,7 @@ void Game::update() if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME) { // std::cout << "Play Music Now" << std::endl; - Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1); +// Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1); } if (Mix_PlayingMusic() != 0 && gsm->currentState != GameStateManager::ST_COREGAME) { @@ -250,8 +251,25 @@ void Game::update() // 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){ +/* player.getComponent().position.y = cCol.y-playerCol.h*gScale; + printDebug("cCol x,y,w,h"); + printDebug(std::to_string(cCol.x)); + printDebug(std::to_string(cCol.y)); + printDebug(std::to_string(cCol.w)); + printDebug(std::to_string(cCol.h)); + printDebug("playerCol x,y,w,h"); + printDebug(std::to_string(playerCol.x)); + printDebug(std::to_string(playerCol.y)); + printDebug(std::to_string(playerCol.w)); + printDebug(std::to_string(playerCol.h)); + printDebug("playerTransform x,y,w,h"); + printDebug(std::to_string(player.getComponent().position.x)); + printDebug(std::to_string(player.getComponent().position.y)); + printDebug(std::to_string(player.getComponent().width)); + printDebug(std::to_string(player.getComponent().height));*/ player.getComponent().Play("Idle"); } + gravityOnPlayer = false; playerIsGrounded = true; } @@ -288,11 +306,19 @@ void Game::update() { c->getComponent().hidden = false; } + for (auto& p: players) + { + p->getComponent().hidden = false; + } } else { for (auto& c: colliders) { c->getComponent().hidden = true; } + for (auto& p: players) + { + p->getComponent().hidden = true; + } } }