]> git.localhorst.tv Git - l2e.git/commitdiff
reworked gauges to better reflect the original ones
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 10 Aug 2012 16:01:41 +0000 (18:01 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 10 Aug 2012 16:01:41 +0000 (18:01 +0200)
at least I think that's how they behave,
might need some further investigation

src/battle/HeroTag.cpp
src/graphics/Gauge.cpp
src/graphics/Gauge.h
src/main.cpp

index a83ba8b9fc1f019dd5695816db09388cb653d5fe..3f9be08557fc45696dc4831f3cc54a6137fc351e 100644 (file)
@@ -37,13 +37,13 @@ void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> posi
        int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * res->heroTagFont->CharWidth());
        // health gauge, second line
        Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + res->heroTagFont->CharHeight());
-       res->healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth));
+       res->healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(255));
        // mana gauge, third line
        Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight());
-       res->manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth));
+       res->manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(255));
        // ikari gauge, fourth line
        Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
-       res->ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth));
+       res->ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(255));
 
        // labels
        int labelX((align == LEFT ? 5 : 1) * res->heroTagFont->CharWidth());
index 65535f5d2436f4b0664c430370a2e4bb5f032093..09405a2069ca15da6b560df6a9328d95e0ceec71 100644 (file)
@@ -11,109 +11,56 @@ using geometry::Point;
 
 namespace graphics {
 
-// TODO: add start and end "ignore" offsets
-void Gauge::Draw(SDL_Surface *dest, Point<int> position, int width, int fullWidth) const {
+void Gauge::Draw(SDL_Surface *dest, Point<int> position, int width, Uint8 fill) const {
        SDL_Rect srcRect, destRect;
 
+       int filledWidth = fill * (width - startWidth - endWidth) / 255;
+       int emptyWidth = (255 - fill) * (width - startWidth - endWidth) / 255;
+
        // start
+       srcRect.w = startWidth;
        srcRect.h = height;
        destRect.x = position.X();
        destRect.y = position.Y();
        // full part
-       if (fullWidth >= startWidth) { // completely filled
-               srcRect.x = fullX;
-               srcRect.y = fullY;
-               srcRect.w = startWidth;
-               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-       } else if (fullWidth > 0) { // partially filled
-               srcRect.x = fullX;
-               srcRect.y = fullY;
-               srcRect.w = fullWidth;
-               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-       }
-       // empty part
-       if (fullWidth == 0) { // completely empty
+       if (fill == 0) {
                srcRect.x = emptyX;
                srcRect.y = emptyY;
-               srcRect.w = startWidth;
                SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-       } else if (fullWidth < startWidth) { // partially empty
-               srcRect.x = emptyX + fullWidth;
-               srcRect.y = emptyY;
-               srcRect.w = startWidth - fullWidth;
-               destRect.x = position.X() + fullWidth;
+       } else {
+               srcRect.x = fullX;
+               srcRect.y = fullY;
                SDL_BlitSurface(surface, &srcRect, dest, &destRect);
        }
 
        destRect.x = position.X() + startWidth;
 
        // fill
-       if (fullWidth >= width - endWidth) { // completely filled
-               srcRect.x = fullX + startWidth;
-               srcRect.y = fullY;
-               srcRect.w = repeatWidth;
-               int fillWidth(width - startWidth - endWidth);
-               int fillCursor(0);
-               while (fillCursor < fillWidth) {
-                       SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-                       destRect.x += repeatWidth;
-                       fillCursor += repeatWidth;
-               }
-       } else if (fullWidth <= startWidth) { // completely empty
-               srcRect.x = emptyX + startWidth;
-               srcRect.y = emptyY;
-               srcRect.w = repeatWidth;
-               int fillWidth(width - startWidth - endWidth);
-               int fillCursor(0);
-               while (fillCursor < fillWidth) {
-                       SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-                       destRect.x += repeatWidth;
-                       fillCursor += repeatWidth;
-               }
-       } else { // partially filled/empty
-               srcRect.x = fullX + startWidth;
-               srcRect.y = fullY;
-               srcRect.w = repeatWidth;
-               int fillCursor(0);
-               while (fillCursor < fullWidth) {
-                       SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-                       destRect.x += repeatWidth;
-                       fillCursor += repeatWidth;
-               }
-               srcRect.x = emptyX + startWidth;
-               srcRect.y = emptyY;
-               int remaining(width - startWidth - endWidth);
-               while (fillCursor < remaining) {
-                       SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-                       destRect.x += repeatWidth;
-                       fillCursor += repeatWidth;
-               }
+       srcRect.x = fullX + startWidth;
+       srcRect.y = fullY;
+       srcRect.w = repeatWidth;
+       while (filledWidth > repeatWidth) {
+               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+               destRect.x += repeatWidth;
+               filledWidth -= repeatWidth;
+       }
+       srcRect.x = emptyX + startWidth;
+       srcRect.y = emptyY;
+       while (emptyWidth > repeatWidth) {
+               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+               destRect.x += repeatWidth;
+               emptyWidth -= repeatWidth;
        }
 
        // end
-       // full part
-       if (fullWidth >= width) { // completely filled
+       srcRect.w = endWidth;
+       if (fill == 255) {
                srcRect.x = fullX + startWidth + repeatWidth;
                srcRect.y = fullY;
-               srcRect.w = endWidth;
                SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-       } else if (fullWidth > (width - endWidth)) { // partially filled
-               srcRect.x = fullX + startWidth + repeatWidth;
-               srcRect.y = fullY;
-               srcRect.w = endWidth - width + fullWidth;
-               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-       }
-       // empty part
-       if (fullWidth <= width - endWidth) { // completely empty
+       } else {
                srcRect.x = emptyX + startWidth + repeatWidth;
                srcRect.y = emptyY;
-               srcRect.w = startWidth;
-               SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-       } else if (fullWidth > (width - endWidth) && fullWidth < width) { // partially empty
-               srcRect.x = emptyX + startWidth + repeatWidth + fullWidth - width + endWidth;
-               srcRect.y = emptyY;
-               srcRect.w = width - fullWidth;
-               destRect.x = position.X() + fullWidth;
                SDL_BlitSurface(surface, &srcRect, dest, &destRect);
        }
 
index 95b4b5b580cf738cd2a22c7296a5819fac2561fa..01b7aeb7970d778a118afc46f1f44486e5c4bea1 100644 (file)
@@ -23,7 +23,7 @@ public:
 public:
        int MinWidth() const { return startWidth + endWidth; }
        int Height() const { return height; }
-       void Draw(SDL_Surface *dest, geometry::Point<int> position, int width, int filled) const;
+       void Draw(SDL_Surface *dest, geometry::Point<int> position, int width, Uint8 fill) const;
 
 private:
        SDL_Surface *surface;
index 3e3da000c468c891b330bd98cb88308ae8f6d992..6baf82770e762318ffc27b34a126f0fd056b77a4 100644 (file)
@@ -95,7 +95,7 @@ int main(int argc, char **argv) {
                maxim.SetHealth(33);
                maxim.SetMaxMana(20);
                maxim.SetMana(20);
-               maxim.SetIP(140);
+               maxim.SetIP(0);
 
                SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
                Sprite selanSprite(selanImg, 64, 64);
@@ -107,7 +107,7 @@ int main(int argc, char **argv) {
                selan.SetHealth(28);
                selan.SetMaxMana(23);
                selan.SetMana(23);
-               selan.SetIP(204);
+               selan.SetIP(1);
 
                SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
                Sprite guySprite(guyImg, 64, 64);
@@ -119,7 +119,7 @@ int main(int argc, char **argv) {
                guy.SetHealth(38);
                guy.SetMaxMana(0);
                guy.SetMana(0);
-               guy.SetIP(216);
+               guy.SetIP(254);
 
                SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
                Sprite dekarSprite(dekarImg, 64, 64);
@@ -131,7 +131,7 @@ int main(int argc, char **argv) {
                dekar.SetHealth(38);
                dekar.SetMaxMana(0);
                dekar.SetMana(0);
-               dekar.SetIP(127);
+               dekar.SetIP(255);
 
                battle::Resources battleRes;