From 656802688636800d5e3e37e5ceeb2f04aa03d073 Mon Sep 17 00:00:00 2001 From: Alan Youngblood Date: Fri, 4 Aug 2023 14:34:43 -0400 Subject: [PATCH] refactored Text, box UI and reconfigured config.json --- .kdev4/KaijuSaveEarth.kdev4 | 38 ++++++++++++++++ ...UITextBubble.png => ui-element-bubble.png} | Bin .../ui/{LoRez5Font.png => ui-font-lorez5.png} | Bin src/config/config.json | 8 ++-- src/game/Game.cpp | 43 +++++++++++------- src/game/Game.hpp | 6 +++ 6 files changed, 75 insertions(+), 20 deletions(-) create mode 100644 .kdev4/KaijuSaveEarth.kdev4 rename assets/textures/ui/{UITextBubble.png => ui-element-bubble.png} (100%) rename assets/textures/ui/{LoRez5Font.png => ui-font-lorez5.png} (100%) diff --git a/.kdev4/KaijuSaveEarth.kdev4 b/.kdev4/KaijuSaveEarth.kdev4 new file mode 100644 index 0000000..3fb8ed5 --- /dev/null +++ b/.kdev4/KaijuSaveEarth.kdev4 @@ -0,0 +1,38 @@ +[CMake] +Build Directory Count=1 +Current Build Directory Index-Host System=0 + +[CMake][CMake Build Directory 0] +Build Directory Path=/home/ayoungblood/projects/KaijuSaveEarth/build +Build Type=Release +CMake Binary=/usr/bin/cmake +CMake Executable=/usr/bin/cmake +Environment Profile= +Extra Arguments= +Install Directory= +Runtime=Host System + +[Launch] +Launch Configurations=Launch Configuration 0 + +[Launch][Launch Configuration 0] +Configured Launch Modes=execute +Configured Launchers=nativeAppLauncher +Name=KaijuSaveEarth +Type=Native Application + +[Launch][Launch Configuration 0][Data] +Arguments= +Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x02\x00\x00\x00\x1c\x00K\x00a\x00i\x00j\x00u\x00S\x00a\x00v\x00e\x00E\x00a\x00r\x00t\x00h\x00\x00\x00\x1c\x00K\x00a\x00i\x00j\x00u\x00S\x00a\x00v\x00e\x00E\x00a\x00r\x00t\x00h) +Dependency Action=Build +EnvironmentGroup= +Executable=file:///home/ayoungblood/projects/KaijuSaveEarth/build/KaijuSaveEarth +External Terminal=konsole --noclose --workdir %workdir -e %exe +Kill Before Executing Again=65536 +Project Target=KaijuSaveEarth,KaijuSaveEarth +Use External Terminal=false +Working Directory=file:///home/ayoungblood/projects/KaijuSaveEarth +isExecutable=true + +[Project] +VersionControlSupport=kdevgit diff --git a/assets/textures/ui/UITextBubble.png b/assets/textures/ui/ui-element-bubble.png similarity index 100% rename from assets/textures/ui/UITextBubble.png rename to assets/textures/ui/ui-element-bubble.png diff --git a/assets/textures/ui/LoRez5Font.png b/assets/textures/ui/ui-font-lorez5.png similarity index 100% rename from assets/textures/ui/LoRez5Font.png rename to assets/textures/ui/ui-font-lorez5.png diff --git a/src/config/config.json b/src/config/config.json index 5c4ae94..d81749c 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -1,7 +1,7 @@ { -"GameName":"Beagle Rescue", -"WindowName":"Beagle Rescue", -"WindowSize":{"w":427,"h":240}, +"GameName":"Kaiju Save Earth", +"WindowName":"Kaiju Save Earth", +"WindowSize":{"w":64,"h":64}, "WindowFullScreen": 0, -"GlobalScale": 2 +"GlobalScale": 12 } diff --git a/src/game/Game.cpp b/src/game/Game.cpp index bb97f86..212f39b 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -46,6 +46,13 @@ bool Game::debugMenu = false; auto& player(manager.addEntity()); Vector2D Game::playerPosition; Vector2D Game::pVel; +Vector2D Game::fontSize; +Vector2D Game::nineSliceSize; + +int Game::nineSliceX0 = 4; +int Game::nineSliceX1 = 12; +int Game::nineSliceY0 = 4; +int Game::nineSliceY1 = 12; // auto& enemy(manager.addEntity()); auto& puppy(manager.addEntity()); @@ -136,8 +143,8 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g } assets->AddTexture("player", "assets/textures/actors/firefighter.png"); - assets->AddTexture("font", "assets/textures/ui/ui-font-cloud-sans.png"); - assets->AddTexture("textBox", "assets/textures/ui/ui-element-cloud.png"); + assets->AddTexture("font", "assets/textures/ui/ui-font-lorez5.png"); + assets->AddTexture("textBox", "assets/textures/ui/ui-element-bubble.png"); assets->AddTexture("puppy","assets/textures/actors/beaglepuppy.png"); assets->AddTexture("collider","assets/textures/ColTex.png"); @@ -151,9 +158,13 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g // map = new Map("terrain",globalScale,16); // std::string myText = "Find lost puppies!\nThey need your help!"; std::string myText = "Press U to Start"; - + + //Set Font and UI NineSlice Sizes here + fontSize = Vector2D(5,5); + nineSliceSize = Vector2D(16,16); + uiTextInstructions.addComponent(18,22,138*gScale,20*gScale,gScale); - uiTextInstructions.addComponent("font",myText,8,12,gScale); + uiTextInstructions.addComponent("font",myText,fontSize.x,fontSize.y,gScale); uiTextInstructions.addGroup(groupUI_Layer1); SDL_Rect myDestRect = SDL_Rect(); @@ -162,42 +173,42 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g myDestRect.w = 160; myDestRect.h = 40; my9Slice = new UINineSlice("textBox"); - my9Slice->MakeSlices("textBox",32,32,14,16,14,16,myDestRect,globalScale,Game::groupUI_Layer0); + my9Slice->MakeSlices("textBox",nineSliceSize.x,nineSliceSize.y,nineSliceX0,nineSliceX1,nineSliceY0,nineSliceY1,myDestRect,globalScale,Game::groupUI_Layer0); // std::cout << "camera.w " << camera.w << std::endl; uiInfo.addComponent(camera.w/gScale-94,10,72*gScale,96*gScale,gScale); -// uiInfo.addComponent("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1); -// uiInfo.addComponent("font", "Player PTiX: PTiY: P.x: P.y : coll: Px2: tson: ", 8, 12, gScale); - uiInfo.addComponent("font", "Player PTiX: PTiY: P.x: P.y : coll: ", 8, 12, gScale); +// uiInfo.addComponent("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", fontSize.x,fontSize.y, 1); +// uiInfo.addComponent("font", "Player PTiX: PTiY: P.x: P.y : coll: Px2: tson: ", fontSize.x,fontSize.y, gScale); + uiInfo.addComponent("font", "Player PTiX: PTiY: P.x: P.y : coll: ", fontSize.x,fontSize.y, gScale); uiInfo.addGroup(groupUI_Layer3); uiCamXInfo.addComponent(camera.w/gScale-48,23,40*gScale,12*gScale,gScale); - uiCamXInfo.addComponent("font", "nan", 8, 12, gScale); + uiCamXInfo.addComponent("font", "nan", fontSize.x,fontSize.y, gScale); uiCamXInfo.addGroup(groupUI_Layer3); uiCamYInfo.addComponent(camera.w/gScale-48,36,40*gScale,12*gScale,gScale); - uiCamYInfo.addComponent("font", "nan", 8, 12, gScale); + uiCamYInfo.addComponent("font", "nan", fontSize.x,fontSize.y, gScale); uiCamYInfo.addGroup(groupUI_Layer3); uiPlayerXInfo.addComponent(camera.w/gScale-49,49,40*gScale,12*gScale,gScale); - uiPlayerXInfo.addComponent("font", "nan", 8, 12, gScale); + uiPlayerXInfo.addComponent("font", "nan", fontSize.x,fontSize.y, gScale); uiPlayerXInfo.addGroup(groupUI_Layer3); uiPlayerYInfo.addComponent(camera.w/gScale-48,62,40*gScale,12*gScale,gScale); - uiPlayerYInfo.addComponent("font", "nan", 8, 12, gScale); + uiPlayerYInfo.addComponent("font", "nan",fontSize.x,fontSize.y, gScale); uiPlayerYInfo.addGroup(groupUI_Layer3); uiBoundary1Info.addComponent(camera.w/gScale-48,75,128*gScale,12*gScale,gScale); - uiBoundary1Info.addComponent("font", "nan", 8, 12, gScale); + uiBoundary1Info.addComponent("font", "nan",fontSize.x,fontSize.y, gScale); uiBoundary1Info.addGroup(groupUI_Layer3); // uiBoundary2Info.addComponent(camera.w/gScale-64,88,128*gScale,12*gScale,gScale); -// uiBoundary2Info.addComponent("font", "nan", 8, 12, gScale); +// uiBoundary2Info.addComponent("font", "nan",fontSize.x,fontSize.y, gScale); // uiBoundary2Info.addGroup(groupUI_Layer3); // // uiBoundary3Info.addComponent(camera.w/gScale-64,101,128*gScale,12*gScale,gScale); -// uiBoundary3Info.addComponent("font", "nan", 8, 12, gScale); +// uiBoundary3Info.addComponent("font", "nan",fontSize.x,fontSize.y, gScale); // uiBoundary3Info.addGroup(groupUI_Layer3); // debug UI box @@ -207,7 +218,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g debugBoxRect.w = 98*gScale; debugBoxRect.h = 112*gScale; debugBox = new UINineSlice("textBox"); - debugBox->MakeSlices("textBox",32,32,14,16,14,16,debugBoxRect,1,Game::groupUI_Layer2); + debugBox->MakeSlices("textBox",nineSliceSize.x,nineSliceSize.y,nineSliceX0,nineSliceX1,nineSliceY0,nineSliceY1,debugBoxRect,globalScale,Game::groupUI_Layer2); //ecs implementation diff --git a/src/game/Game.hpp b/src/game/Game.hpp index a1ee8eb..964f77e 100644 --- a/src/game/Game.hpp +++ b/src/game/Game.hpp @@ -51,6 +51,12 @@ public: static bool playerIsJumping; static Vector2D playerPosition; static Vector2D pVel; + static Vector2D fontSize; + static Vector2D nineSliceSize; + static int nineSliceX0; + static int nineSliceX1; + static int nineSliceY0; + static int nineSliceY1; static SDL_Rect camera; static SDL_Rect levelMap; static AssetManager* assets;