ColliderComponent hidden prop
This commit is contained in:
parent
8713b76f83
commit
1e5beb5b88
Binary file not shown.
@ -27,14 +27,13 @@ public:
|
||||
int offsetX = 0;
|
||||
int offsetY = 0;
|
||||
|
||||
bool hidden = true;
|
||||
|
||||
TransformComponent* transform;
|
||||
|
||||
ColliderComponent(std::string t)
|
||||
{
|
||||
tag = t;
|
||||
// collider.x = 10;
|
||||
// collider.y = 52;
|
||||
// collider.w = collider.h = 12;
|
||||
}
|
||||
|
||||
ColliderComponent(std::string t, int xpos, int ypos, int size, int scale)
|
||||
@ -66,17 +65,6 @@ public:
|
||||
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 };
|
||||
// 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);
|
||||
}
|
||||
|
||||
void update() override
|
||||
@ -85,10 +73,6 @@ public:
|
||||
{
|
||||
collider.x = static_cast<int>(transform->position.x+offsetX);
|
||||
collider.y = static_cast<int>(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;
|
||||
}
|
||||
destR.x = collider.x - Game::camera.x;
|
||||
destR.y = collider.y - Game::camera.y;
|
||||
@ -96,12 +80,15 @@ public:
|
||||
|
||||
void draw() override
|
||||
{
|
||||
if(tag == "terrain")
|
||||
{
|
||||
TextureManager::Draw(tex, srcR, destR, SDL_FLIP_NONE);
|
||||
// TextureManager::DrawCollider(destR);
|
||||
// if(tag == "terrain")
|
||||
// {
|
||||
// TextureManager::Draw(tex, srcR, destR, SDL_FLIP_NONE);
|
||||
// }
|
||||
if(hidden == false)
|
||||
{
|
||||
TextureManager::Draw(tex, srcR,destR,SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
@ -17,7 +17,4 @@
|
||||
#include "TileComponent.h"
|
||||
#include "UIFontComponent.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* SRC_COMPONENTS_H_ */
|
||||
|
@ -90,16 +90,6 @@ public:
|
||||
{
|
||||
switch (Game::event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_UP:
|
||||
// transform->velocity.y = 0;
|
||||
// sprite->Play("idle");
|
||||
// sprite->spriteFlip = SDL_FLIP_NONE;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
// transform->velocity.y = 0;
|
||||
// sprite->Play("idle");
|
||||
// sprite->spriteFlip = SDL_FLIP_NONE;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
|
||||
transform->velocity.x = 0;
|
||||
|
@ -24,7 +24,6 @@ public:
|
||||
{
|
||||
transform = &entity->getComponent<TransformComponent>();
|
||||
transform->velocity = velocity;
|
||||
// std::cout << transform->position << std::endl;
|
||||
}
|
||||
|
||||
void update() override
|
||||
|
@ -70,13 +70,9 @@ public:
|
||||
spriteType = sType;
|
||||
if(sType == spriteAnimation)
|
||||
{
|
||||
// std::string bogusPath = "src/config/credits.json";
|
||||
// std::ifstream fin(bogusPath);
|
||||
|
||||
std::ifstream fin(json);
|
||||
|
||||
if(fin.is_open()){
|
||||
// std::cout<<"file is open"<<std::endl;
|
||||
} else {
|
||||
std::cout<<"json file is NOT open"<<std::endl;
|
||||
}
|
||||
@ -84,7 +80,6 @@ public:
|
||||
if(fin.fail()){
|
||||
std::cout<<"json file open fail"<<std::endl;
|
||||
} else{
|
||||
// std::cout<<"json file open success"<<std::endl;
|
||||
}
|
||||
|
||||
std::ifstream jsonText(json);
|
||||
@ -94,35 +89,20 @@ public:
|
||||
cJSON * animJson = cJSON_Parse(aJson.c_str());
|
||||
cJSON * meta = cJSON_GetObjectItem(animJson, "meta");
|
||||
cJSON * frameTags = cJSON_GetObjectItem(meta,"frameTags");
|
||||
// printf("frameTags:\n%s\n",cJSON_Print(frameTags));
|
||||
int tagsCount = cJSON_GetArraySize(frameTags);
|
||||
// printf("number of tags: \n%d\n",tagsCount);
|
||||
// cJSON * arrItem = cJSON_GetArrayItem(frameTags,0);
|
||||
// cJSON * animItem = cJSON_GetArrayItem(frameTags, 0);
|
||||
// printf("Animation item: \n%s\n",cJSON_Print(animItem));
|
||||
// printf("arrItem: \n%s\n",cJSON_Print(arrItem));
|
||||
|
||||
for (int t = 0; t < tagsCount; t++)
|
||||
{
|
||||
// printf("Tag: \n%d\n",t);
|
||||
// printf("tag number: \n%d\n",t);
|
||||
cJSON * animItem = cJSON_GetArrayItem(frameTags,t);
|
||||
// printf("Animation item: \n%s\n",cJSON_Print(animItem));
|
||||
cJSON * nameJson = cJSON_GetObjectItem(animItem, "name");
|
||||
const char * name = cJSON_Print(nameJson);
|
||||
int fromFrame = cJSON_GetObjectItem(animItem, "from")->valueint;
|
||||
int toFrame = cJSON_GetObjectItem(animItem, "to")->valueint;
|
||||
Animation anim = Animation(fromFrame,toFrame,100);
|
||||
animations.emplace(name, anim);
|
||||
// printf("Adding animation named: %s fromFrame:%d toFrame:%d \n",name,fromFrame,toFrame);
|
||||
Play(name);
|
||||
}
|
||||
|
||||
// if(!animations.empty()){
|
||||
// printf("animations found!\n");
|
||||
// }else{
|
||||
// printf("No animations\n");
|
||||
// }
|
||||
// Play("idle");
|
||||
Animation idle = Animation(0,3,100);
|
||||
animations.emplace("Idle", idle);
|
||||
Animation walk = Animation(1,3,100);
|
||||
@ -140,7 +120,6 @@ public:
|
||||
{
|
||||
spriteType = sType;
|
||||
setTex(id);
|
||||
// text = isText;
|
||||
letter = fontLetter;
|
||||
letterWidth = letterW;
|
||||
letterHeight = letterH;
|
||||
|
@ -35,8 +35,6 @@ public:
|
||||
SDL_Rect srcRect, destRect;
|
||||
Vector2D position;
|
||||
|
||||
// UIFontComponent() = default;
|
||||
|
||||
UIFontComponent(std::string id, int letterW, int letterH, int xpos, int ypos, int scale)
|
||||
{
|
||||
texture = Game::assets->GetTexture(id);
|
||||
|
@ -282,6 +282,18 @@ void Game::update()
|
||||
camera.x = map->width-camera.w;
|
||||
if (camera.y > map->height-camera.h)
|
||||
camera.y = map->height-camera.h;
|
||||
if (Game::debugCollisionBoxes)
|
||||
{
|
||||
for (auto& c: colliders)
|
||||
{
|
||||
c->getComponent<ColliderComponent>().hidden = false;
|
||||
}
|
||||
} else {
|
||||
for (auto& c: colliders)
|
||||
{
|
||||
c->getComponent<ColliderComponent>().hidden = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Game::render()
|
||||
@ -295,12 +307,10 @@ void Game::render()
|
||||
{
|
||||
t->draw();
|
||||
}
|
||||
if (Game::debugCollisionBoxes)
|
||||
|
||||
for (auto& c : colliders)
|
||||
{
|
||||
for (auto& c : colliders)
|
||||
{
|
||||
c->draw();
|
||||
}
|
||||
c->draw();
|
||||
}
|
||||
|
||||
for (auto& o : objects)
|
||||
|
@ -49,20 +49,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
finalRect.w = finalRect.w*scale;
|
||||
finalRect.h = finalRect.h*scale;
|
||||
|
||||
// x0 = x0*scale;
|
||||
// x1 = x1*scale;
|
||||
// y0 = y0*scale;
|
||||
// y1 = y1*scale;
|
||||
|
||||
// printf("finalRect x:%d, y:%d, w:%d, h:%d \n",finalRect.x,finalRect.y,finalRect.w,finalRect.h);
|
||||
|
||||
// destRect.x = destRect.x*scale;
|
||||
// destRect.y = destRect.y*scale;
|
||||
// destRect.w = destRect.w*scale;
|
||||
// destRect.h = destRect.h*scale;
|
||||
// colsRemainder = colsRemainder*scale;
|
||||
// rowsRemainder = rowsRemainder*scale;
|
||||
|
||||
for (int i=0; i<9; i++)
|
||||
{
|
||||
switch(i)
|
||||
@ -72,7 +58,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
srcRect.y = 0;
|
||||
srcRect.w = x0;
|
||||
srcRect.h = y0;
|
||||
// printf("tile zero.w or x0: %d\n",x0);
|
||||
destRect.w = srcRect.w;
|
||||
destRect.h = srcRect.h;
|
||||
break;
|
||||
@ -91,8 +76,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
srcRect.h = y0;
|
||||
destRect.w = srcRect.w;
|
||||
destRect.h = srcRect.h;
|
||||
// printf("srcRect.x: %d",srcRect.x);
|
||||
// printf("UI9Slice #2 srcRect x:%d y:%d w:%d h:%d \n",srcRect.x,srcRect.y,srcRect.w,srcRect.h);
|
||||
break;
|
||||
case 3:
|
||||
srcRect.x = 0;
|
||||
@ -150,14 +133,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
destRect.w = 0;
|
||||
destRect.h = 0;
|
||||
}
|
||||
// These will be the same for each SDL_Rect except if there's a scaling int, which still needs to be implemented
|
||||
// destRect.w = srcRect.w*scale;
|
||||
// destRect.h = srcRect.h*scale;
|
||||
|
||||
// x0 = x0*scale;
|
||||
// x1 = x1*scale;
|
||||
// y0 = y0*scale;
|
||||
// y1 = y1*scale;
|
||||
|
||||
// Calculate where and how many tiles to place
|
||||
// We only need one instance of each of these in each corner or slices 0,2,6,8
|
||||
@ -184,9 +159,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
destRect.y = finalRect.y+(finalRect.h-srcRect.h*scale);
|
||||
}
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("Corner Slice\n");
|
||||
// printf("srcRect x:%d, y:%d, w:%d, h:%d \n",srcRect.x,srcRect.y,srcRect.w,srcRect.h);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n\n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
// Slices 1,7 need to be repeated in a row
|
||||
if (i==1||i==7)
|
||||
@ -198,9 +170,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
destRect.x = finalRect.x+(x0*scale+c*(x1*scale-x0*scale));
|
||||
destRect.y = finalRect.y;
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("Top Slice (1) \n");
|
||||
// printf("srcRect x:%d, y:%d, w:%d, h:%d \n",srcRect.x,srcRect.y,srcRect.w,srcRect.h);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n\n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
if (colsRemainder>0){
|
||||
destRect.x = finalRect.x+(x0*scale+cols*(x1*scale-x0*scale));
|
||||
@ -208,9 +177,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
srcRect.w = colsRemainder;
|
||||
destRect.w = colsRemainder;
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("Top Slice (1) \n");
|
||||
// printf("srcRect x:%d, y:%d, w:%d, h:%d \n",srcRect.x,srcRect.y,srcRect.w,srcRect.h);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n\n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
}
|
||||
if (i==7)
|
||||
@ -220,7 +186,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
destRect.x = finalRect.x+(x0*scale+c*(x1*scale-x0*scale));
|
||||
destRect.y = finalRect.y+(finalRect.h-(srcH-y1)*scale);
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
if (colsRemainder>0){
|
||||
destRect.x = finalRect.x+(x0*scale+cols*(x1*scale-x0*scale));
|
||||
@ -228,7 +193,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
srcRect.w = colsRemainder;
|
||||
destRect.w = colsRemainder;
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -242,7 +206,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
destRect.x = finalRect.x;
|
||||
destRect.y = finalRect.y+(y0*scale+r*(y1-y0)*scale);
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
if (rowsRemainder>0){
|
||||
destRect.x = finalRect.x;
|
||||
@ -250,7 +213,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
srcRect.h = rowsRemainder;
|
||||
destRect.h = rowsRemainder;
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
}
|
||||
if (i==5)
|
||||
@ -260,7 +222,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
destRect.x = finalRect.x+(finalRect.w-(srcW-x1)*scale);
|
||||
destRect.y = finalRect.y+(y0*scale+r*(y1-y0)*scale);
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
if (rowsRemainder>0){
|
||||
destRect.x = finalRect.x+(finalRect.w-(srcW-x1)*scale);
|
||||
@ -268,7 +229,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
srcRect.h = rowsRemainder;
|
||||
destRect.h = rowsRemainder;
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -284,7 +244,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
destRect.x = finalRect.x+(x0*scale+c*(x1-x0)*scale);
|
||||
destRect.y = finalRect.y+(y0*scale+rowY*scale);
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
if (colsRemainder>0)
|
||||
{
|
||||
@ -293,7 +252,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
srcRect.w = colsRemainder;
|
||||
destRect.w = colsRemainder;
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
}
|
||||
if (rowsRemainder>0)
|
||||
@ -307,7 +265,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
srcRect.w = (srcW-x0-(srcW-x1));
|
||||
destRect.w = (srcW-x0-(srcW-x1));
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
}
|
||||
if(rowsRemainder>0&&colsRemainder>0)
|
||||
@ -319,15 +276,13 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in
|
||||
destRect.w = colsRemainder;
|
||||
destRect.h = rowsRemainder;
|
||||
AddSlice(srcRect,destRect,scale);
|
||||
// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Need to take in variables: (srcRect, desiredRect)
|
||||
|
||||
void UINineSlice::AddSlice(SDL_Rect srcRect, SDL_Rect destRect, int scale)
|
||||
{
|
||||
// printf("adding a 9slice element");
|
||||
auto& slice(manager.addEntity());
|
||||
SDL_Rect scaledRect = SDL_Rect();
|
||||
scaledRect.x = destRect.x;
|
||||
|
@ -37,22 +37,10 @@ void UIText::ParseString(std::string inputText, int x, int y, int letterScale, s
|
||||
int posX = x;
|
||||
int posY = y;
|
||||
int i = 0;
|
||||
// printf(inputText);
|
||||
char current = inputText[i];
|
||||
// const char* newLineChar{10};
|
||||
|
||||
// std::vector<char> writableStr(inputText.begin(), inputText.end());
|
||||
// writableStr.push_back('\0');
|
||||
|
||||
do
|
||||
{
|
||||
// for (int i = 0; i < writableStr.size(); i++)
|
||||
// {
|
||||
// if (writableStr.at(i) == '\n')
|
||||
// {
|
||||
// printf("found new line");
|
||||
// }
|
||||
// }
|
||||
++i;
|
||||
if (strcmp(¤t,"\n")!=0)
|
||||
{
|
||||
@ -60,7 +48,6 @@ void UIText::ParseString(std::string inputText, int x, int y, int letterScale, s
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("new line detected/n");
|
||||
posX = x;
|
||||
posY += letterHeight;
|
||||
}
|
||||
@ -74,12 +61,7 @@ void UIText::AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrS
|
||||
{
|
||||
auto& letter(manager.addEntity());
|
||||
letter.addComponent<TransformComponent>(xpos*lttrScale, ypos*lttrScale, letterWidth, letterHeight, 1);
|
||||
// printf("Scale: %d\n",scale);
|
||||
letter.addComponent<SpriteComponent>("font", SpriteComponent::spriteText, crnt, letterWidth, letterHeight, lttrScale);
|
||||
letter.setTag(tag);
|
||||
letter.addGroup(Game::groupUI_Layer1);
|
||||
}
|
||||
|
||||
// void UIText::RemoveLetter()
|
||||
// {
|
||||
// }
|
||||
|
@ -23,7 +23,6 @@ public:
|
||||
UIText(std::string inputText, std::string texID, int x, int y, int letterW, int letterH, int lScale);
|
||||
~UIText();
|
||||
|
||||
// void SetCharClips(SDL_Texture* fontTex, int x, int y, int letterW, int letterH);
|
||||
void AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale);
|
||||
void ParseString(std::string inputText, int x, int y, int letterScale, std::string tag);
|
||||
int scale;
|
||||
|
Loading…
Reference in New Issue
Block a user