tibia-client/src/otclient/core/creature.cpp

78 lines
2.3 KiB
C++
Raw Normal View History

2011-08-15 16:11:24 +02:00
#include "creature.h"
2011-08-15 21:15:49 +02:00
#include "datmanager.h"
2011-08-15 16:11:24 +02:00
#include <framework/graphics/graphics.h>
#include <framework/graphics/framebuffer.h>
#include "game.h"
2011-08-15 23:02:52 +02:00
Creature::Creature() : Thing(THING_CREATURE)
2011-08-15 16:11:24 +02:00
{
2011-08-15 23:02:52 +02:00
m_healthPercent = 0;
m_direction = DIRECTION_SOUTH;
2011-08-15 16:11:24 +02:00
}
void Creature::draw(int x, int y)
{
//ThingAttributes *creatureAttributes = getAttributes();
int anim = 0;
// draw outfit
internalDraw(x, y, 0, m_direction, 0, 0, anim);
2011-08-19 14:26:26 +02:00
const ThingAttributes& attributes = getAttributes();
if(attributes.blendframes > 1) {
g_graphics.bindBlendFunc(BLEND_COLORIZING);
for(int mask = 0; mask < 4; ++mask) {
int outfitColorId = 0;
if(mask == SpriteMaskYellow)
outfitColorId = m_outfit.head;
else if(mask == SpriteMaskRed)
outfitColorId = m_outfit.body;
2011-08-20 04:08:27 +02:00
else if(mask == SpriteMaskGreen)
2011-08-19 14:26:26 +02:00
outfitColorId = m_outfit.legs;
2011-08-20 04:08:27 +02:00
else if(mask == SpriteMaskBlue)
2011-08-19 14:26:26 +02:00
outfitColorId = m_outfit.feet;
2011-08-19 15:23:35 +02:00
g_graphics.bindColor(OutfitColors[outfitColorId]);
2011-08-19 14:32:08 +02:00
internalDraw(x, y, 1, m_direction, 0, 0, anim, (SpriteMask)mask);
2011-08-19 14:26:26 +02:00
}
g_graphics.bindBlendFunc(BLEND_NORMAL);
2011-08-19 14:32:08 +02:00
g_graphics.bindColor(Color::white);
2011-08-19 14:26:26 +02:00
}
2011-08-19 15:23:35 +02:00
// health bar
// TODO: draw outside framebuffer
Color healthColor = Color::black;
if(m_healthPercent > 60 && m_healthPercent <= 100) {
healthColor.setRed(0.0f);
healthColor.setGreen(0.75f);
} else if(m_healthPercent > 30 && m_healthPercent <= 60) {
healthColor.setRed(0.75f);
healthColor.setGreen(0.75f);
} else if(m_healthPercent > 10 && m_healthPercent <= 30) {
healthColor.setRed(0.75f);
healthColor.setGreen(0.00f);
} else if(m_healthPercent > 0 && m_healthPercent <= 10) {
healthColor.setRed(0.25f);
healthColor.setGreen(0.00f);
}
Rect healthRect = Rect(x - 14, y - 11, 27, 4);
2011-08-20 22:30:41 +02:00
g_graphics.bindColor(Color::black);
g_graphics.drawBoundingRect(healthRect);
g_graphics.bindColor(healthColor);
g_graphics.drawFilledRect(healthRect.expanded(-1));
// restore white color
g_graphics.bindColor(Color::white);
2011-08-15 16:11:24 +02:00
}
2011-08-15 23:02:52 +02:00
const ThingAttributes& Creature::getAttributes()
{
return g_dat.getCreatureAttributes(m_outfit.type);
}