Updated entity system a bit and added a new color to values
This commit is contained in:
parent
ce9153e2ca
commit
360877207a
7
Makefile
7
Makefile
|
@ -2,7 +2,7 @@ CC=g++
|
|||
SRCDIR=./src
|
||||
PONG_SRC=./games/Ping-Pong/src
|
||||
outputDir=./build
|
||||
CFLAGS=-fPIC
|
||||
CFLAGS=-fPIC -O2
|
||||
WarningFlags=-Wpedantic -pedantic -Wall -Wextra
|
||||
SDL_FLAGS=-lSDL2 -lSDL2main -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lSDL2_gfx
|
||||
INCLUDES=-I./include
|
||||
|
@ -31,11 +31,12 @@ engine_obj: audio.o entity.o logger.o math.o renderwindow.o timer.o timestep.o u
|
|||
|
||||
engine_lib: audio.o entity.o logger.o math.o renderwindow.o timer.o timestep.o utils.o values.o
|
||||
mkdir -p build
|
||||
g++ -shared -o $(outputDir)/$(LIBFILE) $^
|
||||
g++ -shared $(SDL_FLAGS) -o $(outputDir)/$(LIBFILE) $^
|
||||
|
||||
install: engine_lib
|
||||
cp $(outputDir)/$(LIBFILE) /usr/local/lib/
|
||||
cp -r ./include /usr/local/include/birb2d
|
||||
mkdir -p /usr/local/include/birb2d
|
||||
cp ./include/* /usr/local/include/birb2d/
|
||||
|
||||
uninstall:
|
||||
rm -f /usr/local/lib/$(LIBFILE)
|
||||
|
|
|
@ -25,6 +25,8 @@ namespace Birb2D
|
|||
|
||||
/* Make it possible to update the TextComponent */
|
||||
void SetText(std::string newText);
|
||||
void SetFont(TTF_Font* font);
|
||||
void SetColor(SDL_Color* color);
|
||||
|
||||
std::string name;
|
||||
SDL_Texture* sprite;
|
||||
|
@ -35,6 +37,7 @@ namespace Birb2D
|
|||
|
||||
TextComponent textComponent;
|
||||
void LoadSprite();
|
||||
void ReloadSprite();
|
||||
void SetBaseEntityValues();
|
||||
};
|
||||
|
||||
|
|
|
@ -22,13 +22,14 @@ namespace Global
|
|||
|
||||
namespace Colors
|
||||
{
|
||||
static SDL_Color White = { 255, 255, 255, 255 };
|
||||
static SDL_Color Black = { 0, 0, 0, 255 };
|
||||
static SDL_Color Red = { 255, 0, 0, 255 };
|
||||
static SDL_Color Green = { 0, 255, 0, 255 };
|
||||
static SDL_Color Blue = { 0, 0, 255, 255 };
|
||||
static SDL_Color DarkGray = { 60, 60, 60, 255 };
|
||||
static SDL_Color LightGray = { 180, 180, 180, 255 };
|
||||
static SDL_Color White = { 255, 255, 255, 255 };
|
||||
static SDL_Color Black = { 0, 0, 0, 255 };
|
||||
static SDL_Color Red = { 255, 0, 0, 255 };
|
||||
static SDL_Color Green = { 0, 255, 0, 255 };
|
||||
static SDL_Color Blue = { 0, 0, 255, 255 };
|
||||
static SDL_Color Yellow = { 255, 255, 0, 255 };
|
||||
static SDL_Color DarkGray = { 60, 60, 60, 255 };
|
||||
static SDL_Color LightGray = { 180, 180, 180, 255 };
|
||||
|
||||
SDL_Color ChangeColorIntensity(SDL_Color color, int delta);
|
||||
}
|
||||
|
|
|
@ -21,12 +21,30 @@ namespace Birb2D
|
|||
if (textComponent.text == newText)
|
||||
return;
|
||||
|
||||
/* Destroy the old sprite */
|
||||
SDL_DestroyTexture(sprite);
|
||||
|
||||
/* Create new text sprite */
|
||||
textComponent.text = newText;
|
||||
LoadSprite();
|
||||
ReloadSprite();
|
||||
}
|
||||
|
||||
void Entity::SetFont(TTF_Font* font)
|
||||
{
|
||||
/* Don't do anything if the font hasn't changed at all */
|
||||
if (textComponent.font == font)
|
||||
return;
|
||||
|
||||
textComponent.font = font;
|
||||
ReloadSprite();
|
||||
}
|
||||
|
||||
void Entity::SetColor(SDL_Color* color)
|
||||
{
|
||||
/* Don't do anything if the color hasn't changed at all */
|
||||
if (color->a == textComponent.color->a
|
||||
&& color->r == textComponent.color->r
|
||||
&& color->g == textComponent.color->g
|
||||
&& color->b == textComponent.color->b) return;
|
||||
|
||||
textComponent.color = color;
|
||||
ReloadSprite();
|
||||
}
|
||||
|
||||
void Entity::SetBaseEntityValues()
|
||||
|
@ -88,4 +106,13 @@ namespace Birb2D
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::ReloadSprite()
|
||||
{
|
||||
/* Destroy the old sprite */
|
||||
SDL_DestroyTexture(sprite);
|
||||
|
||||
/* Create new text sprite */
|
||||
LoadSprite();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,6 +106,10 @@ namespace Birb2D
|
|||
|
||||
std::string Timer::SplitDigitalFormat(double previousmills)
|
||||
{
|
||||
/* Return default 00:00 if time hasn't passed */
|
||||
if (!running && ElapsedMilliseconds() == 0)
|
||||
return "00:00";
|
||||
|
||||
double elapsedMilliseconds = ElapsedMilliseconds() - previousmills;
|
||||
double elapsedMinutes = std::floor(CalcMinutes(elapsedMilliseconds));
|
||||
double elapsedSeconds = std::floor(CalcSeconds(elapsedMilliseconds)) - (elapsedMinutes * 60);
|
||||
|
|
Loading…
Reference in New Issue