improved fps

This commit is contained in:
Henrique 2011-08-29 00:05:57 -03:00
parent a8afbf9b3f
commit 1bb89e053a
2 changed files with 49 additions and 33 deletions

View File

@ -26,7 +26,7 @@
#include "map.h" #include "map.h"
#include <framework/platform/platform.h> #include <framework/platform/platform.h>
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>
#include <framework/graphics/fontmanager.h>
Creature::Creature() : Thing(Otc::Creature) Creature::Creature() : Thing(Otc::Creature)
{ {
@ -37,6 +37,7 @@ Creature::Creature() : Thing(Otc::Creature)
m_walkOffsetX = 0; m_walkOffsetX = 0;
m_walkOffsetY = 0; m_walkOffsetY = 0;
m_informationFont = g_fonts.getFont("tibia-12px-rounded");
} }
void Creature::draw(int x, int y) void Creature::draw(int x, int y)
@ -153,33 +154,8 @@ void Creature::drawInformation(int x, int y, bool useGray)
{ {
Color fillColor = Color(96, 96, 96); Color fillColor = Color(96, 96, 96);
if(!useGray) { if(!useGray)
// health bar according to yatc fillColor = m_informationColor;
fillColor = Fw::black;
if(m_healthPercent > 92) {
fillColor.setGreen(188);
}
else if(m_healthPercent > 60) {
fillColor.setRed(80);
fillColor.setGreen(161);
fillColor.setBlue(80);
}
else if(m_healthPercent > 30) {
fillColor.setRed(161);
fillColor.setGreen(161);
}
else if(m_healthPercent > 8) {
fillColor.setRed(160);
fillColor.setGreen(39);
fillColor.setBlue(39);
}
else if(m_healthPercent > 3) {
fillColor.setRed(160);
}
else {
fillColor.setRed(79);
}
}
Rect backgroundRect = Rect(x-(14.5), y, 27, 4); Rect backgroundRect = Rect(x-(14.5), y, 27, 4);
Rect healthRect = backgroundRect.expanded(-1); Rect healthRect = backgroundRect.expanded(-1);
@ -192,8 +168,7 @@ void Creature::drawInformation(int x, int y, bool useGray)
g_graphics.drawFilledRect(healthRect); g_graphics.drawFilledRect(healthRect);
// name // name
FontPtr font = g_fonts.getFont("tibia-12px-rounded"); m_informationFont->renderText(m_name, Rect(x-100, y-15, 200, 15), Fw::AlignTopCenter, fillColor);
font->renderText(m_name, Rect(x-100, y-15, 200, 15), Fw::AlignTopCenter, fillColor);
} }
void Creature::walk(const Position& position) void Creature::walk(const Position& position)
@ -246,7 +221,43 @@ void Creature::walk(const Position& position)
m_lastTicks = g_platform.getTicks(); m_lastTicks = g_platform.getTicks();
} }
void Creature::setHealthPercent(uint8 healthPercent)
{
int oldHealthPercent = m_healthPercent;
m_healthPercent = healthPercent;
onHealthPercentChange(oldHealthPercent);
}
const ThingAttributes& Creature::getAttributes() const ThingAttributes& Creature::getAttributes()
{ {
return g_dat.getCreatureAttributes(m_outfit.type); return g_dat.getCreatureAttributes(m_outfit.type);
} }
void Creature::onHealthPercentChange(int)
{
m_informationColor = Fw::black;
if(m_healthPercent > 92) {
m_informationColor.setGreen(188);
}
else if(m_healthPercent > 60) {
m_informationColor.setRed(80);
m_informationColor.setGreen(161);
m_informationColor.setBlue(80);
}
else if(m_healthPercent > 30) {
m_informationColor.setRed(161);
m_informationColor.setGreen(161);
}
else if(m_healthPercent > 8) {
m_informationColor.setRed(160);
m_informationColor.setGreen(39);
m_informationColor.setBlue(39);
}
else if(m_healthPercent > 3) {
m_informationColor.setRed(160);
}
else {
m_informationColor.setRed(79);
}
}

View File

@ -24,6 +24,7 @@
#define CREATURE_H #define CREATURE_H
#include "thing.h" #include "thing.h"
#include <framework/graphics/fontmanager.h>
struct Outfit { struct Outfit {
uint16 type; uint16 type;
@ -44,7 +45,7 @@ public:
void drawInformation(int x, int y, bool useGray); void drawInformation(int x, int y, bool useGray);
void setName(const std::string& name) { m_name = name; } void setName(const std::string& name) { m_name = name; }
void setHealthPercent(uint8 healthPercent) { m_healthPercent = healthPercent; } void setHealthPercent(uint8 healthPercent);
void setDirection(Otc::Direction direction) { m_direction = direction; } void setDirection(Otc::Direction direction) { m_direction = direction; }
void setOutfit(const Outfit& outfit) { m_outfit = outfit; } void setOutfit(const Outfit& outfit) { m_outfit = outfit; }
void setLight(const Light& light) { m_light = light; } void setLight(const Light& light) { m_light = light; }
@ -64,13 +65,14 @@ public:
uint8 getShield() { return m_shield; } uint8 getShield() { return m_shield; }
uint8 getEmblem() { return m_emblem; } uint8 getEmblem() { return m_emblem; }
bool getImpassable() { return m_impassable; } bool getImpassable() { return m_impassable; }
const ThingAttributes& getAttributes();
void onHealthPercentChange(int);
void walk(const Position& position); void walk(const Position& position);
int getWalkOffsetX() { return m_walkOffsetX; } int getWalkOffsetX() { return m_walkOffsetX; }
int getWalkOffsetY() { return m_walkOffsetY; } int getWalkOffsetY() { return m_walkOffsetY; }
const ThingAttributes& getAttributes();
CreaturePtr asCreature() { return std::static_pointer_cast<Creature>(shared_from_this()); } CreaturePtr asCreature() { return std::static_pointer_cast<Creature>(shared_from_this()); }
private: private:
@ -85,6 +87,9 @@ private:
uint8 m_emblem; uint8 m_emblem;
bool m_impassable; bool m_impassable;
FontPtr m_informationFont;
Color m_informationColor;
int m_lastTicks; int m_lastTicks;
bool m_walking; bool m_walking;
float m_walkTimePerPixel; float m_walkTimePerPixel;