Worked on Colliders
This commit is contained in:
parent
1e5beb5b88
commit
165052a617
Binary file not shown.
@ -60,7 +60,7 @@ void Map::LoadMap(std::string path, int sizeX, int sizeY, int scale)
|
|||||||
if (c == '1')
|
if (c == '1')
|
||||||
{
|
{
|
||||||
auto& tcol(manager.addEntity());
|
auto& tcol(manager.addEntity());
|
||||||
tcol.addComponent<ColliderComponent>("terrain",x*scaledSize,y*scaledSize,tileSize,scale);
|
tcol.addComponent<ColliderComponent>("terrain",x*scaledSize,y*scaledSize,tileSize,scale,texID);
|
||||||
tcol.addGroup(Game::groupColliders);
|
tcol.addGroup(Game::groupColliders);
|
||||||
}
|
}
|
||||||
mapFile.ignore(2,',');
|
mapFile.ignore(2,',');
|
||||||
|
@ -36,21 +36,23 @@ public:
|
|||||||
tag = t;
|
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;
|
tag = t;
|
||||||
collider.x = xpos;
|
collider.x = xpos;
|
||||||
collider.y = ypos;
|
collider.y = ypos;
|
||||||
collider.w = collider.h = size*scale;
|
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;
|
tag = t;
|
||||||
collider.w = width;
|
collider.w = width;
|
||||||
collider.h = height;
|
collider.h = height;
|
||||||
offsetX = oX;
|
offsetX = oX;
|
||||||
offsetY = oY;
|
offsetY = oY;
|
||||||
|
setTex(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() override
|
void init() override
|
||||||
@ -90,6 +92,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setTex(std::string id)
|
||||||
|
{
|
||||||
|
tex = Game::assets->GetTexture(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
class KeyboardController : public Component
|
class KeyboardController : public Component
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// bool keyIsAlreadyPressed[];
|
|
||||||
TransformComponent *transform;
|
TransformComponent *transform;
|
||||||
SpriteComponent *sprite;
|
SpriteComponent *sprite;
|
||||||
|
|
||||||
|
@ -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("font", "assets/textures/ui/ui-font-cloud-sans.png");
|
||||||
assets->AddTexture("textBox", "assets/textures/ui/ui-element-cloud.png");
|
assets->AddTexture("textBox", "assets/textures/ui/ui-element-cloud.png");
|
||||||
assets->AddTexture("puppy","assets/textures/actors/beaglepuppy.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/sillypuppy.ogg");
|
||||||
assets->AddMusicTrack("simonZ","assets/audio/music/victory.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);
|
map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);
|
||||||
|
|
||||||
player.addComponent<TransformComponent>(860*globalScale,630*globalScale,22,42,globalScale);
|
player.addComponent<TransformComponent>(860*globalScale,540*globalScale,22,42,globalScale);
|
||||||
// player.addComponent<TransformComponent>(150*globalScale,80*globalScale,40,40,globalScale);
|
// player.addComponent<TransformComponent>(150*globalScale,80*globalScale,40,40,globalScale);
|
||||||
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
|
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
|
||||||
player.addComponent<KeyboardController>();
|
player.addComponent<KeyboardController>();
|
||||||
player.addComponent<ColliderComponent>("player",8*globalScale,8*globalScale, true, 7*globalScale,36*globalScale);
|
player.addComponent<ColliderComponent>("player",8*globalScale,8*globalScale, true, 7*globalScale,34*globalScale, "collider");
|
||||||
player.addGroup(groupPlayers);
|
player.addGroup(groupPlayers);
|
||||||
|
|
||||||
puppy.addComponent<TransformComponent>(1024*globalScale,210*globalScale,36,30,globalScale);
|
puppy.addComponent<TransformComponent>(1024*globalScale,210*globalScale,36,30,globalScale);
|
||||||
@ -227,7 +228,7 @@ void Game::update()
|
|||||||
if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME)
|
if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME)
|
||||||
{
|
{
|
||||||
// std::cout << "Play Music Now" << std::endl;
|
// 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)
|
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);
|
// 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("");
|
// printDebug("");
|
||||||
if(!playerIsGrounded){
|
if(!playerIsGrounded){
|
||||||
|
/* player.getComponent<TransformComponent>().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<TransformComponent>().position.x));
|
||||||
|
printDebug(std::to_string(player.getComponent<TransformComponent>().position.y));
|
||||||
|
printDebug(std::to_string(player.getComponent<TransformComponent>().width));
|
||||||
|
printDebug(std::to_string(player.getComponent<TransformComponent>().height));*/
|
||||||
player.getComponent<SpriteComponent>().Play("Idle");
|
player.getComponent<SpriteComponent>().Play("Idle");
|
||||||
}
|
}
|
||||||
|
|
||||||
gravityOnPlayer = false;
|
gravityOnPlayer = false;
|
||||||
playerIsGrounded = true;
|
playerIsGrounded = true;
|
||||||
}
|
}
|
||||||
@ -288,11 +306,19 @@ void Game::update()
|
|||||||
{
|
{
|
||||||
c->getComponent<ColliderComponent>().hidden = false;
|
c->getComponent<ColliderComponent>().hidden = false;
|
||||||
}
|
}
|
||||||
|
for (auto& p: players)
|
||||||
|
{
|
||||||
|
p->getComponent<ColliderComponent>().hidden = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto& c: colliders)
|
for (auto& c: colliders)
|
||||||
{
|
{
|
||||||
c->getComponent<ColliderComponent>().hidden = true;
|
c->getComponent<ColliderComponent>().hidden = true;
|
||||||
}
|
}
|
||||||
|
for (auto& p: players)
|
||||||
|
{
|
||||||
|
p->getComponent<ColliderComponent>().hidden = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user