summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-04-13 03:36:00 +0300
committerAndrei Karas <akaras@inbox.ru>2011-04-13 03:36:00 +0300
commitc978b7f0d9de1bb6bd84cd299ed80c27c5147927 (patch)
tree8f1edc2be0816693761ba58aa7c7c554040a7db6 /src/resources
parentda1b2d8311ca78eccd3e9875598562ce6bf05cab (diff)
downloadmv-c978b7f0d9de1bb6bd84cd299ed80c27c5147927.tar.gz
mv-c978b7f0d9de1bb6bd84cd299ed80c27c5147927.tar.bz2
mv-c978b7f0d9de1bb6bd84cd299ed80c27c5147927.tar.xz
mv-c978b7f0d9de1bb6bd84cd299ed80c27c5147927.zip
Impliment new tags in sprites animations and random condition.
Tags: <label>, <goto>
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/animation.cpp27
-rw-r--r--src/resources/animation.h13
-rw-r--r--src/resources/mapreader.cpp3
-rw-r--r--src/resources/spritedef.cpp23
4 files changed, 51 insertions, 15 deletions
diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp
index 98ea19f2a..1154d9c9d 100644
--- a/src/resources/animation.cpp
+++ b/src/resources/animation.cpp
@@ -29,25 +29,38 @@ Animation::Animation():
{
}
-void Animation::addFrame(Image *image, int delay, int offsetX, int offsetY)
+void Animation::addFrame(Image *image, int delay, int offsetX, int offsetY,
+ int rand)
{
- Frame frame = { image, delay, offsetX, offsetY, Frame::ANIMATION, "" };
+ Frame frame = { image, delay, offsetX, offsetY, rand, Frame::ANIMATION, "" };
mFrames.push_back(frame);
mDuration += delay;
}
-void Animation::addTerminator()
+void Animation::addTerminator(int rand)
{
- addFrame(NULL, 0, 0, 0);
+ addFrame(NULL, 0, 0, 0, rand);
}
bool Animation::isTerminator(const Frame &candidate)
{
- return (candidate.image == NULL);
+ return (candidate.image == NULL && candidate.type == Frame::ANIMATION);
}
-void Animation::addJump(std::string name)
+void Animation::addJump(std::string name, int rand)
{
- Frame frame = { 0, 0, 0, 0, Frame::JUMP, name };
+ Frame frame = { 0, 0, 0, 0, rand, Frame::JUMP, name };
+ mFrames.push_back(frame);
+}
+
+void Animation::addLabel(std::string name)
+{
+ Frame frame = { 0, 0, 0, 0, 100, Frame::LABEL, name };
+ mFrames.push_back(frame);
+}
+
+void Animation::addGoto(std::string name, int rand)
+{
+ Frame frame = { 0, 0, 0, 0, rand, Frame::GOTO, name };
mFrames.push_back(frame);
}
diff --git a/src/resources/animation.h b/src/resources/animation.h
index 5130bc8dd..0c6f45681 100644
--- a/src/resources/animation.h
+++ b/src/resources/animation.h
@@ -39,12 +39,14 @@ struct Frame
{
ANIMATION = 0,
JUMP,
+ GOTO,
LABEL
};
Image *image;
int delay;
int offsetX;
int offsetY;
+ int rand;
FrameType type;
std::string nextAction;
};
@@ -61,13 +63,14 @@ class Animation
/**
* Appends a new animation at the end of the sequence.
*/
- void addFrame(Image *image, int delay, int offsetX, int offsetY);
+ void addFrame(Image *image, int delay, int offsetX, int offsetY,
+ int rand);
/**
* Appends an animation terminator that states that the animation
* should not loop.
*/
- void addTerminator();
+ void addTerminator(int rand);
/**
* Returns the frame at the specified index.
@@ -87,7 +90,11 @@ class Animation
int getDuration() const
{ return mDuration; }
- void addJump(std::string name);
+ void addJump(std::string name, int rand);
+
+ void addLabel(std::string name);
+
+ void addGoto(std::string name, int rand);
/**
* Determines whether the given animation frame is a terminator.
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index d2bcde06d..3bd77315a 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -705,11 +705,12 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path,
"animation-frame" + toString(i));
iDelay = tileProperties.find(
"animation-delay" + toString(i));
+ // possible need add random attribute?
if (iFrame != tileProperties.end()
&& iDelay != tileProperties.end())
{
ani->addFrame(set->get(iFrame->second),
- iDelay->second, 0, 0);
+ iDelay->second, 0, 0, 100);
}
else
{
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index e6a65926e..1eea6547d 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -225,6 +225,8 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode,
imageSet->getOffsetX();
int offsetY = XML::getProperty(frameNode, "offsetY", 0) +
imageSet->getOffsetY();
+ int rand = XML::getProperty(frameNode, "rand", 100);
+
offsetY -= imageSet->getHeight() - 32;
offsetX -= imageSet->getWidth() / 2 - 16;
@@ -246,7 +248,7 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode,
continue;
}
- animation->addFrame(img, delay, offsetX, offsetY);
+ animation->addFrame(img, delay, offsetX, offsetY, rand);
}
else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence"))
{
@@ -282,7 +284,7 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode,
continue;
}
- animation->addFrame(img, delay, offsetX, offsetY);
+ animation->addFrame(img, delay, offsetX, offsetY, rand);
pos ++;
}
repeat --;
@@ -290,11 +292,24 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode,
}
else if (xmlStrEqual(frameNode->name, BAD_CAST "end"))
{
- animation->addTerminator();
+ animation->addTerminator(rand);
}
else if (xmlStrEqual(frameNode->name, BAD_CAST "jump"))
{
- animation->addJump(XML::getProperty(frameNode, "action", ""));
+ animation->addJump(XML::getProperty(
+ frameNode, "action", ""), rand);
+ }
+ else if (xmlStrEqual(frameNode->name, BAD_CAST "label"))
+ {
+ std::string name = XML::getProperty(frameNode, "name", "");
+ if (!name.empty())
+ animation->addLabel(name);
+ }
+ else if (xmlStrEqual(frameNode->name, BAD_CAST "goto"))
+ {
+ std::string name = XML::getProperty(frameNode, "label", "");
+ if (!name.empty())
+ animation->addGoto(name, rand);
}
} // for frameNode
}