Added theme class and custom loaded font

This commit is contained in:
sigonasr2 2025-08-26 14:37:58 -05:00
parent 54079a939e
commit 07e71a5975
10 changed files with 245 additions and 44 deletions

View File

@ -213,6 +213,30 @@ src/ShepGame.cpp.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles\Shep.dir\build.make CMakeFiles/Shep.dir/src/ShepGame.cpp.s
.PHONY : src/ShepGame.cpp.s
src/Theme.o: src/Theme.cpp.o
.PHONY : src/Theme.o
# target to build an object file
src/Theme.cpp.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles\Shep.dir\build.make CMakeFiles/Shep.dir/src/Theme.cpp.o
.PHONY : src/Theme.cpp.o
src/Theme.i: src/Theme.cpp.i
.PHONY : src/Theme.i
# target to preprocess a source file
src/Theme.cpp.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles\Shep.dir\build.make CMakeFiles/Shep.dir/src/Theme.cpp.i
.PHONY : src/Theme.cpp.i
src/Theme.s: src/Theme.cpp.s
.PHONY : src/Theme.s
# target to generate assembly for a file
src/Theme.cpp.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles\Shep.dir\build.make CMakeFiles/Shep.dir/src/Theme.cpp.s
.PHONY : src/Theme.cpp.s
src/olcPGEX_MiniAudio.o: src/olcPGEX_MiniAudio.cpp.o
.PHONY : src/olcPGEX_MiniAudio.o
@ -304,6 +328,9 @@ help:
@echo ... src/ShepGame.o
@echo ... src/ShepGame.i
@echo ... src/ShepGame.s
@echo ... src/Theme.o
@echo ... src/Theme.i
@echo ... src/Theme.s
@echo ... src/olcPGEX_MiniAudio.o
@echo ... src/olcPGEX_MiniAudio.i
@echo ... src/olcPGEX_MiniAudio.s

View File

@ -97,9 +97,24 @@ PWR = Move Base Power
ATK = Shep Attack
MAX(PWR+PWR*(ATK*0.01)-PWR*(DEF*0.01),1)
Select a character:
Welcome! You are about to begin a great journey of your own.
This land is inhabited by creatures called Shep! Where they come from and their
mysteries have yet to be discovered. Why are they here?
Speaking of, what is your name?
Your adventure is about to unfold, come by my lab when you are ready! I will see you there.
Start in house, go downstairs. Receive a Shapedia. As you collect species you can review them.
Start Menu has:
Shapedia
(Name) - Your profile shows Ruin Shard Count, Geometry Star count, play time, and number of Shep caught.
Save
Options - UI color scheme, text speed, sound effect volume, music volume, controller scheme (a/b switch) Or L button mode
Tackle 20 2
Rush 30 2
Flash Hit 20 3 Has priority
Scratch 20 2
Slash 40 3

View File

@ -356,6 +356,10 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
<ClCompile Include="src\ShepGame.cpp" />
<ClCompile Include="src\olcPGEX_MiniAudio.cpp" />
<ClCompile Include="src\olcPixelGameEngine.cpp" />
<ClCompile Include="src\Theme.cpp">
<SubType>
</SubType>
</ClCompile>
<ClCompile Include="src\util.cpp" />
</ItemGroup>
<ItemGroup>
@ -396,6 +400,10 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="src\Theme.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="src\TMXParser.h">
<SubType>
</SubType>

View File

@ -30,6 +30,9 @@
<ClCompile Include="src\Player.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Theme.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\miniaudio.h">
@ -77,5 +80,8 @@
<ClInclude Include="src\AnimationState.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Theme.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
bin/assets/gfx/font.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -1,6 +1,7 @@
#include "ShepGame.h"
#include "GameSettings.h"
#include "TMXParser.h"
#include "Theme.h"
#include <ranges>
ShepGame*ShepGame::game{nullptr};
@ -82,6 +83,8 @@ const hw3d::mesh&ShepGame::GetSpriteMesh()const{
}
bool ShepGame::OnUserCreate(){
Theme::Initialize();
float fAspect = float(GetScreenSize().y) / float(GetScreenSize().x);
float S = 1.0f / (tan(3.14159f * 0.25f));
float f = 1000.0f;
@ -257,6 +260,8 @@ bool ShepGame::OnUserUpdate(float fElapsedTime){
}
}
Theme::DrawWindow({{20,20},{40,40}});
return true;
}

74
src/Theme.cpp Normal file
View File

@ -0,0 +1,74 @@
#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#include "Theme.h"
#include "ShepGame.h"
Renderable Theme::sheet{};
uint8_t Theme::currentTheme{};
std::unordered_map<Theme::Color,Pixel>Theme::backCol{
{Color::PINK,{204,102,145}},
{Color::LILAC,{204,122,157}},
{Color::BLUE,{81,163,204}},
{Color::GREEN,{81,204,140}},
{Color::RED,{178,35,41}},
{Color::BLACK,{25,25,25}},
};
void Theme::Initialize(){
auto&game{ShepGame::Game()};
game.SetFontSprite("assets/gfx/font.png");
sheet.Load("assets/gfx/CuteRPG_Icons.png",nullptr,false,false);
std::cout<<"Theme sheet loaded"<<std::endl;
}
void Theme::DrawWindow(const geom2d::rect<int>window){
auto&game{ShepGame::Game()};
game.FillRectDecal(window.pos,window.size,backCol.at(Color(currentTheme)));
game.DrawStringPropDecal(window.pos,"Hello World!!",WHITE,{4,4});
}
void Theme::ToggleNext(){
currentTheme++;
if(currentTheme>int(Color::BLACK))currentTheme=0;
}
void Theme::TogglePrev(){
currentTheme--;
if(currentTheme<0)currentTheme=int(Color::BLACK);
}
const uint8_t Theme::GetCurrentTheme(){
return currentTheme;
}

62
src/Theme.h Normal file
View File

@ -0,0 +1,62 @@
#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#pragma once
#include "olcUTIL_Geometry2D.h"
#include "olcPixelGameEngine.h"
class Theme{
public:
static void Initialize();
static void DrawWindow(const geom2d::rect<int>window);
static void ToggleNext();
static void TogglePrev();
static const uint8_t GetCurrentTheme();
private:
enum class Color{
PINK,
LILAC,
BLUE,
GREEN,
RED,
BLACK,
};
static std::unordered_map<Color,Pixel>backCol;
static Renderable sheet;
static uint8_t currentTheme;
};

View File

@ -1483,7 +1483,7 @@ namespace olc
void ClearBuffer(Pixel p, bool bDepth = true);
// Returns the font image
olc::Sprite* GetFontSprite();
void SetFontSprite(std::string_view newFontFile);
// Clip a line segment to visible area
bool ClipLineToScreen(olc::vi2d& in_p1, olc::vi2d& in_p2);
@ -2847,6 +2847,11 @@ namespace olc
return fontRenderable.Sprite();
}
void PixelGameEngine::SetFontSprite(std::string_view newFontFile)
{ fontRenderable.Load(std::string(newFontFile)); }
bool PixelGameEngine::ClipLineToScreen(olc::vi2d& in_p1, olc::vi2d& in_p2)
{
// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm
@ -3831,18 +3836,18 @@ namespace olc
{
if (c == '\n')
{
spos.x = 0; spos.y += 8.0f * scale.y;
spos.x = 0; spos.y += 16.0f * scale.y;
}
else if (c == '\t')
{
spos.x += 8.0f * float(nTabSizeInSpaces) * scale.x;
spos.x += 16.0f * float(nTabSizeInSpaces) * scale.x;
}
else
{
int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16;
DrawPartialDecal(pos + spos, fontRenderable.Decal(), { float(ox) * 8.0f, float(oy) * 8.0f }, { 8.0f, 8.0f }, scale, col);
spos.x += 8.0f * scale.x;
DrawPartialDecal(pos + spos, fontRenderable.Decal(), { float(ox) * 16.0f, float(oy) * 16.0f }, { 16.0f, 16.0f }, scale, col);
spos.x += 16.0f * scale.x;
}
}
}
@ -3854,17 +3859,17 @@ namespace olc
{
if (c == '\n')
{
spos.x = 0; spos.y += 8.0f * scale.y;
spos.x = 0; spos.y += 16.0f * scale.y;
}
else if (c == '\t')
{
spos.x += 8.0f * float(nTabSizeInSpaces) * scale.x;
spos.x += 16.0f * float(nTabSizeInSpaces) * scale.x;
}
else
{
int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16;
DrawPartialDecal(pos + spos, fontRenderable.Decal(), { float(ox) * 8.0f + float(vFontSpacing[c - 32].x), float(oy) * 8.0f }, { float(vFontSpacing[c - 32].y), 8.0f }, scale, col);
DrawPartialDecal(pos + spos, fontRenderable.Decal(), { float(ox) * 16.0f + float(vFontSpacing[c - 32].x), float(oy) * 16.0f }, { float(vFontSpacing[c - 32].y), 16.0f }, scale, col);
spos.x += float(vFontSpacing[c - 32].y) * scale.x;
}
}
@ -3877,18 +3882,18 @@ namespace olc
{
if (c == '\n')
{
spos.x = center.x; spos.y -= 8.0f;
spos.x = center.x; spos.y -= 16.0f;
}
else if (c == '\t')
{
spos.x += 8.0f * float(nTabSizeInSpaces) * scale.x;
spos.x += 16.0f * float(nTabSizeInSpaces) * scale.x;
}
else
{
int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16;
DrawPartialRotatedDecal(pos, fontRenderable.Decal(), fAngle, spos, { float(ox) * 8.0f, float(oy) * 8.0f }, { 8.0f, 8.0f }, scale, col);
spos.x -= 8.0f;
DrawPartialRotatedDecal(pos, fontRenderable.Decal(), fAngle, spos, { float(ox) * 16.0f, float(oy) * 16.0f }, { 16.0f, 16.0f }, scale, col);
spos.x -= 16.0f;
}
}
}
@ -3900,11 +3905,11 @@ namespace olc
{
if (c == '\n')
{
spos.x = center.x; spos.y -= 8.0f;
spos.x = center.x; spos.y -= 16.0f;
}
else if (c == '\t')
{
spos.x += 8.0f * float(nTabSizeInSpaces) * scale.x;
spos.x += 16.0f * float(nTabSizeInSpaces) * scale.x;
}
else
{
@ -3928,7 +3933,7 @@ namespace olc
size.x = std::max(size.x, pos.x);
size.y = std::max(size.y, pos.y);
}
return size * 8;
return size * 16;
}
void PixelGameEngine::DrawString(const olc::vi2d& pos, const std::string& sText, Pixel col, uint32_t scale)
@ -3951,11 +3956,11 @@ namespace olc
{
if (c == '\n')
{
sx = 0; sy += 8 * scale;
sx = 0; sy += 16 * scale;
}
else if (c == '\t')
{
sx += 8 * nTabSizeInSpaces * scale;
sx += 16 * nTabSizeInSpaces * scale;
}
else
{
@ -3964,21 +3969,21 @@ namespace olc
if (scale > 1)
{
for (uint32_t i = 0; i < 8; i++)
for (uint32_t j = 0; j < 8; j++)
if (fontRenderable.Sprite()->GetPixel(i + ox * 8, j + oy * 8).r > 0)
for (uint32_t i = 0; i < 16; i++)
for (uint32_t j = 0; j < 16; j++)
if (fontRenderable.Sprite()->GetPixel(i + ox * 16, j + oy * 16).r > 0)
for (uint32_t is = 0; is < scale; is++)
for (uint32_t js = 0; js < scale; js++)
Draw(x + sx + (i * scale) + is, y + sy + (j * scale) + js, col);
}
else
{
for (uint32_t i = 0; i < 8; i++)
for (uint32_t j = 0; j < 8; j++)
if (fontRenderable.Sprite()->GetPixel(i + ox * 8, j + oy * 8).r > 0)
for (uint32_t i = 0; i < 16; i++)
for (uint32_t j = 0; j < 16; j++)
if (fontRenderable.Sprite()->GetPixel(i + ox * 16, j + oy * 16).r > 0)
Draw(x + sx + i, y + sy + j, col);
}
sx += 8 * scale;
sx += 16 * scale;
}
}
SetPixelMode(m);
@ -3991,13 +3996,13 @@ namespace olc
for (auto c : s)
{
if (c == '\n') { pos.y += 1; pos.x = 0; }
else if (c == '\t') { pos.x += nTabSizeInSpaces * 8; }
else if (c == '\t') { pos.x += nTabSizeInSpaces * 16; }
else pos.x += vFontSpacing[c - 32].y;
size.x = std::max(size.x, pos.x);
size.y = std::max(size.y, pos.y);
}
size.y *= 8;
size.y *= 16;
return size;
}
@ -4021,11 +4026,11 @@ namespace olc
{
if (c == '\n')
{
sx = 0; sy += 8 * scale;
sx = 0; sy += 16 * scale;
}
else if (c == '\t')
{
sx += 8 * nTabSizeInSpaces * scale;
sx += 16 * nTabSizeInSpaces * scale;
}
else
{
@ -4035,8 +4040,8 @@ namespace olc
if (scale > 1)
{
for (int32_t i = 0; i < vFontSpacing[c - 32].y; i++)
for (int32_t j = 0; j < 8; j++)
if (fontRenderable.Sprite()->GetPixel(i + ox * 8 + vFontSpacing[c - 32].x, j + oy * 8).r > 0)
for (int32_t j = 0; j < 16; j++)
if (fontRenderable.Sprite()->GetPixel(i + ox * 16 + vFontSpacing[c - 32].x, j + oy * 16).r > 0)
for (int32_t is = 0; is < int(scale); is++)
for (int32_t js = 0; js < int(scale); js++)
Draw(x + sx + (i * scale) + is, y + sy + (j * scale) + js, col);
@ -4044,8 +4049,8 @@ namespace olc
else
{
for (int32_t i = 0; i < vFontSpacing[c - 32].y; i++)
for (int32_t j = 0; j < 8; j++)
if (fontRenderable.Sprite()->GetPixel(i + ox * 8 + vFontSpacing[c - 32].x, j + oy * 8).r > 0)
for (int32_t j = 0; j < 16; j++)
if (fontRenderable.Sprite()->GetPixel(i + ox * 16 + vFontSpacing[c - 32].x, j + oy * 16).r > 0)
Draw(x + sx + i, y + sy + j, col);
}
sx += vFontSpacing[c - 32].y * scale;
@ -4808,13 +4813,12 @@ namespace olc
fontRenderable.Decal()->Update();
constexpr std::array<uint8_t, 96> vSpacing = { {
0x03,0x25,0x16,0x08,0x07,0x08,0x08,0x04,0x15,0x15,0x08,0x07,0x15,0x07,0x24,0x08,
0x08,0x17,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x24,0x15,0x06,0x07,0x16,0x17,
0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x17,0x08,0x08,0x17,0x08,0x08,0x08,
0x08,0x08,0x08,0x08,0x17,0x08,0x08,0x08,0x08,0x17,0x08,0x15,0x08,0x15,0x08,0x08,
0x24,0x18,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x33,0x17,0x17,0x33,0x18,0x17,0x17,
0x17,0x17,0x17,0x17,0x07,0x17,0x17,0x18,0x18,0x17,0x17,0x07,0x33,0x07,0x08,0x00, } };
0x03,0x02,0x04,0x03,0x06,0x0B,0x0A,0x03,0x04,0x04,0x04,0x06,0x03,0x03,0x03,0x05,
0x06,0x05,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x02,0x03,0x05,0x06,0x05,0x05,
0x05,0x07,0x06,0x06,0x06,0x05,0x05,0x06,0x06,0x02,0x05,0x06,0x05,0x08,0x06,0x06,
0x06,0x06,0x06,0x06,0x06,0x06,0x07,0x08,0x06,0x06,0x05,0x06,0x05,0x07,0x05,0x06,
0x03,0x06,0x05,0x05,0x05,0x05,0x04,0x05,0x05,0x02,0x03,0x05,0x02,0x08,0x05,0x05,
0x05,0x05,0x04,0x05,0x04,0x05,0x06,0x08,0x05,0x05,0x05,0x03,0x06,0x03,0x07,0x08, } };
for (auto c : vSpacing) vFontSpacing.push_back({ c >> 4, c & 15 });
// UK Standard Layout