Cleaned up UITextComponent and SpriteComponent
This commit is contained in:
parent
b5639e4f41
commit
66b8de6f40
Binary file not shown.
@ -8,10 +8,6 @@
|
||||
#ifndef SRC_ECS_SPRITECOMPONENT_H_
|
||||
#define SRC_ECS_SPRITECOMPONENT_H_
|
||||
|
||||
#define ASCII_START_IDX 32
|
||||
#define ASCII_COUNT 96
|
||||
#define ASCII_ROW_COUNT 16
|
||||
|
||||
#include "Components.h"
|
||||
#include "SDL2/SDL.h"
|
||||
#include "../assetmgr/TextureManager.h"
|
||||
@ -116,18 +112,6 @@ public:
|
||||
setTex(id);
|
||||
}
|
||||
|
||||
SpriteComponent(std::string id, SpriteType sType, char fontLetter, int letterW, int letterH, int letterScale)
|
||||
{
|
||||
spriteType = sType;
|
||||
setTex(id);
|
||||
letter = fontLetter;
|
||||
letterWidth = letterW;
|
||||
letterHeight = letterH;
|
||||
scale = letterScale;
|
||||
destRect.w = letterW*letterScale;
|
||||
destRect.h = letterH*letterScale;
|
||||
}
|
||||
|
||||
SpriteComponent(std::string id, SpriteType sType, SDL_Rect srcR, SDL_Rect destR)
|
||||
{
|
||||
spriteType = sType;
|
||||
@ -152,14 +136,6 @@ public:
|
||||
|
||||
switch(spriteType)
|
||||
{
|
||||
case spriteText:
|
||||
srcRect.x = ((letter-ASCII_START_IDX) % ASCII_ROW_COUNT)*letterWidth;
|
||||
srcRect.y = ((letter-ASCII_START_IDX)/ASCII_ROW_COUNT)*letterHeight;
|
||||
srcRect.w = letterWidth;
|
||||
srcRect.h = letterHeight;
|
||||
destRect.w = letterWidth*scale;
|
||||
destRect.h = letterHeight*scale;
|
||||
break;
|
||||
case spriteUIL0: case spriteUIL1: case spriteBackground:
|
||||
break;
|
||||
case spriteActor: case spriteAnimation: case spriteAtlas: case spriteObject: case spriteTileMap:
|
||||
|
@ -85,7 +85,7 @@ public:
|
||||
srcRect.w = letterWidth;
|
||||
srcRect.h = letterHeight;
|
||||
destRect.x = static_cast<int>(transform->position.x)*scale+(i%charsPerLine)*letterWidth*scale;
|
||||
destRect.y = static_cast<int>(transform->position.y)*scale+std::floor(i/charsPerLine)*letterHeight*scale*1.5;
|
||||
destRect.y = static_cast<int>(transform->position.y)*scale+std::floor(i/charsPerLine)*letterHeight*scale*1.1;
|
||||
destRect.w = letterWidth*scale;
|
||||
destRect.h = letterHeight*scale;
|
||||
letterTuple = std::make_tuple(srcRect,destRect);
|
||||
|
@ -24,14 +24,9 @@
|
||||
|
||||
Map* map;
|
||||
Manager manager;
|
||||
// UIText* text;
|
||||
UINineSlice* my9Slice;
|
||||
// UIText* scoreboardText;
|
||||
UINineSlice* scoreboard9Slice;
|
||||
UINineSlice* debugBox;
|
||||
// UIText* debugStaticText;
|
||||
// UIText* debugdynamicText;
|
||||
// UIText* debugJumpText;
|
||||
|
||||
GameStateManager* Game::gsm = new GameStateManager();
|
||||
|
||||
@ -52,6 +47,8 @@ auto& puppy(manager.addEntity());
|
||||
|
||||
// auto& scoreboard(manager.addEntity());
|
||||
auto& uiInfo(manager.addEntity());
|
||||
auto& uiJumpInfo(manager.addEntity());
|
||||
auto& uiTextInstructions(manager.addEntity());
|
||||
|
||||
bool Game::debugCollisionBoxes = false;
|
||||
bool Game::gravityOnPlayer = true;
|
||||
@ -141,8 +138,10 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
// 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, "start instructions", Game::groupUI_Layer1);
|
||||
// text->ParseString(myText, 12, 22, globalScale, "text",Game::groupUI_Layer1);
|
||||
uiTextInstructions.addComponent<TransformComponent>(18*gScale,22*gScale,138*gScale,20*gScale,gScale);
|
||||
uiTextInstructions.addComponent<UITextComponent>("font",myText,8,12,gScale);
|
||||
uiTextInstructions.addGroup(groupUI_Layer1);
|
||||
|
||||
SDL_Rect myDestRect = SDL_Rect();
|
||||
myDestRect.x = 12;
|
||||
myDestRect.y = 8;
|
||||
@ -151,54 +150,25 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
my9Slice = new UINineSlice("textBox");
|
||||
my9Slice->MakeSlices("textBox",32,32,14,16,14,16,myDestRect,globalScale,Game::groupUI_Layer0);
|
||||
|
||||
uiInfo.addComponent<TransformComponent>(10,10,180,56,1);
|
||||
uiInfo.addComponent<UITextComponent>("font", "UI Text works again!", 8, 12, 1);
|
||||
uiInfo.addGroup(groupUI_Layer3);
|
||||
// debug UI text
|
||||
/* UIText* debugStaticText2;
|
||||
UIText* debugStaticText3;
|
||||
UIText* debugStaticText4;
|
||||
UIText* debugStaticText5;
|
||||
UIText* debugStaticText6;
|
||||
UIText* debugStaticText7; */
|
||||
|
||||
|
||||
// std::string debugStaticString = "Collision";
|
||||
// debugStaticText = new UIText(debugStaticString, "font", 0,0,8,12,1,"debug text",Game::groupUI_Layer3);
|
||||
// debugStaticText->ParseString(debugStaticString,camera.w-100*globalScale,14*gScale,1,"debug",Game::groupUI_Layer3);
|
||||
// std::string debugStaticString2 = "Hori:";
|
||||
// debugStaticText2 = new UIText(debugStaticString2, "font", 0,0,8,12,1,"debug text",Game::groupUI_Layer3);
|
||||
// debugStaticText2->ParseString(debugStaticString2,camera.w-100*globalScale,24*gScale,1,"debug",Game::groupUI_Layer3);
|
||||
// std::string debugStaticString3 = "Vert:";
|
||||
// debugStaticText3 = new UIText(debugStaticString3, "font", 0,0,8,12,1,"debug text",Game::groupUI_Layer3);
|
||||
// debugStaticText3->ParseString(debugStaticString3,camera.w-100*globalScale,34*gScale,1,"debug",Game::groupUI_Layer3);
|
||||
// std::string debugStaticString4 = "Jump:";
|
||||
// debugStaticText4 = new UIText(debugStaticString4, "font", 0,0,8,12,1,"debug text",Game::groupUI_Layer3);
|
||||
// debugStaticText4->ParseString(debugStaticString4,camera.w-100*globalScale,44*gScale,1,"debug",Game::groupUI_Layer3);
|
||||
// std::string debugStaticString5 = "P.y :";
|
||||
// debugStaticText5 = new UIText(debugStaticString5, "font", 0,0,8,12,1,"debug text",Game::groupUI_Layer3);
|
||||
// debugStaticText5->ParseString(debugStaticString5,camera.w-100*globalScale,54*gScale,1,"debug",Game::groupUI_Layer3);
|
||||
// std::string debugStaticString6 = "P.dy:";
|
||||
// debugStaticText6 = new UIText(debugStaticString6, "font", 0,0,8,12,1,"debug text",Game::groupUI_Layer3);
|
||||
// debugStaticText6->ParseString(debugStaticString6,camera.w-100*globalScale,64*gScale,1,"debug",Game::groupUI_Layer3);
|
||||
// std::string debugStaticString7 = "YVec:";
|
||||
// debugStaticText7 = new UIText(debugStaticString7, "font", 0,0,8,12,1,"debug text",Game::groupUI_Layer3);
|
||||
// debugStaticText7->ParseString(debugStaticString7,camera.w-100*globalScale,74*gScale,1,"debug",Game::groupUI_Layer3);
|
||||
//
|
||||
uiInfo.addComponent<TransformComponent>(camera.w-94*gScale,10*gScale,72*gScale,96*gScale,1);
|
||||
uiInfo.addComponent<UITextComponent>("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1);
|
||||
uiInfo.addGroup(groupUI_Layer3);
|
||||
|
||||
uiJumpInfo.addComponent<TransformComponent>(camera.w-48*gScale,48*gScale,40*gScale,12*gScale,1);
|
||||
uiJumpInfo.addComponent<UITextComponent>("font", "false", 8, 12, 1);
|
||||
uiJumpInfo.addGroup(groupUI_Layer3);
|
||||
// debugJumpText = new UIText(Game::BoolToString(playerIsJumping), "font", 0,0,8,12,1,"debug text",Game::groupUI_Layer3);
|
||||
// debugJumpText->ParseString(Game::BoolToString(playerIsJumping),camera.w-50*globalScale,44*gScale,1,"debugJumpText",Game::groupUI_Layer3);
|
||||
|
||||
// debug UI box
|
||||
SDL_Rect debugBoxRect = SDL_Rect();
|
||||
debugBoxRect.x = camera.w-(100*globalScale);
|
||||
debugBoxRect.y = 8*globalScale;
|
||||
debugBoxRect.w = 98*globalScale;
|
||||
debugBoxRect.h = 94*globalScale;
|
||||
debugBoxRect.x = camera.w-(100*gScale);
|
||||
debugBoxRect.y = 4*gScale;
|
||||
debugBoxRect.w = 98*gScale;
|
||||
debugBoxRect.h = 100*gScale;
|
||||
debugBox = new UINineSlice("textBox");
|
||||
debugBox->MakeSlices("textBox",32,32,14,16,14,16,debugBoxRect,1,Game::groupUI_Layer2);
|
||||
|
||||
// printf("camera.w: %d \n",camera.w);
|
||||
|
||||
//ecs implementation
|
||||
|
||||
map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);
|
||||
@ -225,8 +195,6 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
}
|
||||
}
|
||||
|
||||
//camera.x = camera.x*globalScale;
|
||||
|
||||
// ====== Setup groups
|
||||
auto& tiles(manager.getGroup(Game::groupMap));
|
||||
auto& players(manager.getGroup(Game::groupPlayers));
|
||||
@ -258,8 +226,6 @@ void Game::update()
|
||||
SDL_Rect playerCol = player.getComponent<ColliderComponent>().collider;
|
||||
Vector2D playerPos = player.getComponent<TransformComponent>().position;
|
||||
|
||||
uiInfo.getComponent<UITextComponent>().updateString("Updating UIText works well, even with basic word wrap for new lines.");
|
||||
|
||||
// if (gsm->currentState == GameStateManager::ST_INIT)
|
||||
// {
|
||||
// const char* initText = "Loading...";
|
||||
@ -282,7 +248,6 @@ void Game::update()
|
||||
// Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0);
|
||||
// }
|
||||
|
||||
|
||||
// for (auto& letter : debugText)
|
||||
// {
|
||||
// if(letter->tag=="debugJumpText"){
|
||||
@ -313,7 +278,9 @@ void Game::update()
|
||||
// Gravity
|
||||
if (gravityOnPlayer){
|
||||
player.getComponent<TransformComponent>().position.y += 3*gScale;
|
||||
// debugJumpText->ParseString(Game::BoolToString(playerIsJumping),camera.w-50*gScale,44*gScale,1,"debugJumpText",Game::groupUI_Layer3);
|
||||
uiJumpInfo.getComponent<UITextComponent>().updateString("true");
|
||||
} else {
|
||||
uiJumpInfo.getComponent<UITextComponent>().updateString("false");
|
||||
}
|
||||
// for(auto& p: projectiles)
|
||||
// {
|
||||
@ -440,4 +407,3 @@ void Game::drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blu
|
||||
SDL_SetRenderDrawColor(renderer, red, green, blue, 255);
|
||||
SDL_RenderDrawLine(renderer, srcpt.x, srcpt.y, destpt.x, destpt.y);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user