From 63112267be277e38224b510ec5745421dd7d4917 Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Fri, 21 Jan 2011 23:23:16 +0200
Subject: Add diagonal animations.

New animation names: upleft, upright, downleft, downright
Tested atleast at mobs.
---
 src/being.cpp               | 22 ++++++++++++++++++++--
 src/resources/action.cpp    | 16 +++++++++++++---
 src/resources/spritedef.cpp |  8 ++++++++
 src/resources/spritedef.h   |  4 ++++
 4 files changed, 45 insertions(+), 5 deletions(-)

(limited to 'src')

diff --git a/src/being.cpp b/src/being.cpp
index f382253e2..8cde401f2 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -947,13 +947,31 @@ void Being::setDirection(Uint8 direction)
 
     SpriteDirection dir;
     if (mFaceDirection & UP)
-        dir = DIRECTION_UP;
+    {
+        if (mFaceDirection & LEFT)
+            dir = DIRECTION_UPLEFT;
+        else if (mFaceDirection & RIGHT)
+            dir = DIRECTION_UPRIGHT;
+        else
+            dir = DIRECTION_UP;
+    }
     else if (mFaceDirection & DOWN)
-        dir = DIRECTION_DOWN;
+    {
+        if (mFaceDirection & LEFT)
+            dir = DIRECTION_DOWNLEFT;
+        else if (mFaceDirection & RIGHT)
+            dir = DIRECTION_DOWNRIGHT;
+        else
+            dir = DIRECTION_DOWN;
+    }
     else if (mFaceDirection & RIGHT)
+    {
         dir = DIRECTION_RIGHT;
+    }
     else
+    {
         dir = DIRECTION_LEFT;
+    }
     mSpriteDirection = dir;
 
     CompoundSprite::setDirection(dir);
diff --git a/src/resources/action.cpp b/src/resources/action.cpp
index 923aa72c9..b8cfde611 100644
--- a/src/resources/action.cpp
+++ b/src/resources/action.cpp
@@ -22,6 +22,7 @@
 #include "resources/action.h"
 
 #include "resources/animation.h"
+#include "resources/spritedef.h"
 
 #include "utils/dtor.h"
 
@@ -38,10 +39,19 @@ Animation *Action::getAnimation(int direction) const
 {
     Animations::const_iterator i = mAnimations.find(direction);
 
-    // When the given direction is not available, return the first one.
-    // (either DEFAULT, or more usually DOWN).
     if (i == mAnimations.end())
-        i = mAnimations.begin();
+    {
+        if (direction == DIRECTION_UPLEFT || direction == DIRECTION_UPRIGHT)
+            direction = DIRECTION_UP;
+        else if (direction == DIRECTION_DOWNLEFT || direction == DIRECTION_DOWNRIGHT)
+            direction = DIRECTION_DOWN;
+        i = mAnimations.find(direction);
+
+        // When the given direction is not available, return the first one.
+        // (either DEFAULT, or more usually DOWN).
+        if (i == mAnimations.end())
+            i = mAnimations.begin();
+    }
 
     return (i == mAnimations.end()) ? NULL : i->second;
 }
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index dddee575f..edd7b6a74 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -334,6 +334,14 @@ SpriteDirection SpriteDef::makeSpriteDirection(const std::string &direction)
         return DIRECTION_RIGHT;
     else if (direction == "down")
         return DIRECTION_DOWN;
+    else if (direction == "upleft")
+        return DIRECTION_UPLEFT;
+    else if (direction == "upright")
+        return DIRECTION_UPRIGHT;
+    else if (direction == "downleft")
+        return DIRECTION_DOWNLEFT;
+    else if (direction == "downright")
+        return DIRECTION_DOWNRIGHT;
     else
         return DIRECTION_INVALID;
 }
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index 5ab4bcc2b..34786d783 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -90,6 +90,10 @@ enum SpriteDirection
     DIRECTION_DOWN,
     DIRECTION_LEFT,
     DIRECTION_RIGHT,
+    DIRECTION_UPLEFT,
+    DIRECTION_UPRIGHT,
+    DIRECTION_DOWNLEFT,
+    DIRECTION_DOWNRIGHT,
     DIRECTION_INVALID
 };
 
-- 
cgit v1.2.3-70-g09d2