1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

* better code handling attack animation in battles

This commit is contained in:
mateuszb 2008-06-06 13:53:33 +00:00
parent 92525f6d31
commit d0798670ad
2 changed files with 184 additions and 93 deletions

View File

@ -18,7 +18,7 @@ extern SDL_Color zwykly;
SDL_Surface * CBattleInterface::cellBorder, * CBattleInterface::cellShade; SDL_Surface * CBattleInterface::cellBorder, * CBattleInterface::cellShade;
CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2) CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2)
: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL) : printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL)
{ {
//initializing armies //initializing armies
this->army1 = army1; this->army1 = army1;
@ -243,6 +243,9 @@ void CBattleInterface::show(SDL_Surface * to)
{ {
stackByHex[j->second.position] = j->second.ID; stackByHex[j->second.position] = j->second.ID;
} }
attackingShowHelper(); // handle attack animation
for(int b=0; b<187; ++b) for(int b=0; b<187; ++b)
{ {
if(stackByHex[b]!=-1) if(stackByHex[b]!=-1)
@ -559,134 +562,97 @@ void CBattleInterface::stackAttacking(int ID, int dest)
switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
{ {
case 0: case 0:
//reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(10);
for(int i=0; i<creAnims[ID]->framesInGroup(10); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
//reverseCreature(ID, aStack.position, true); //reverseCreature(ID, aStack.position, true);
break; break;
case 1: case 1:
creAnims[ID]->setType(10);
for(int i=0; i<creAnims[ID]->framesInGroup(10); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break; break;
case 2: case 2:
creAnims[ID]->setType(11);
for(int i=0; i<creAnims[ID]->framesInGroup(11); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break; break;
case 3: case 3:
creAnims[ID]->setType(12);
for(int i=0; i<creAnims[ID]->framesInGroup(12); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break; break;
case 4: case 4:
//reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(12);
for(int i=0; i<creAnims[ID]->framesInGroup(12); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
//reverseCreature(ID, aStack.position, true); //reverseCreature(ID, aStack.position, true);
break; break;
case 5: case 5:
reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(11);
for(int i=0; i<creAnims[ID]->framesInGroup(11); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
reverseCreature(ID, aStack.position, true); reverseCreature(ID, aStack.position, true);
break; break;
} }
creAnims[ID]->setType(2);
} }
else //else for if(aStack.creature->isDoubleWide()) else //else for if(aStack.creature->isDoubleWide())
{ {
switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
{ {
case 0: case 0:
reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(10);
for(int i=0; i<creAnims[ID]->framesInGroup(10); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
reverseCreature(ID, aStack.position, true); reverseCreature(ID, aStack.position, true);
break; break;
case 1: case 1:
creAnims[ID]->setType(10);
for(int i=0; i<creAnims[ID]->framesInGroup(10); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break; break;
case 2: case 2:
creAnims[ID]->setType(11);
for(int i=0; i<creAnims[ID]->framesInGroup(11); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break; break;
case 3: case 3:
creAnims[ID]->setType(12);
for(int i=0; i<creAnims[ID]->framesInGroup(12); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break; break;
case 4: case 4:
reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(12);
for(int i=0; i<creAnims[ID]->framesInGroup(12); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
reverseCreature(ID, aStack.position, true); reverseCreature(ID, aStack.position, true);
break; break;
case 5: case 5:
reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(11);
for(int i=0; i<creAnims[ID]->framesInGroup(11); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
reverseCreature(ID, aStack.position, true); reverseCreature(ID, aStack.position, true);
break; break;
} }
creAnims[ID]->setType(2); }
attackingInfo = new CAttHelper;
attackingInfo->dest = dest;
attackingInfo->frame = 0;
attackingInfo->ID = ID;
attackingInfo->reversing = false;
if(aStack.creature->isDoubleWide())
{
switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
{
case 0:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(10);
break;
case 1:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(10);
break;
case 2:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
break;
case 3:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
break;
case 4:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
break;
case 5:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
break;
}
}
else //else for if(aStack.creature->isDoubleWide())
{
switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
{
case 0:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(10);
break;
case 1:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(10);
break;
case 2:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
break;
case 3:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
break;
case 4:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
break;
case 5:
attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
break;
}
} }
} }
@ -729,6 +695,121 @@ void CBattleInterface::showRange(SDL_Surface * to, int ID)
} }
} }
void CBattleInterface::attackingShowHelper()
{
if(attackingInfo && !attackingInfo->reversing)
{
if(attackingInfo->frame == 0)
{
CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
if(aStack.creature->isDoubleWide())
{
switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
{
case 0:
creAnims[attackingInfo->ID]->setType(10);
break;
case 1:
creAnims[attackingInfo->ID]->setType(10);
break;
case 2:
creAnims[attackingInfo->ID]->setType(11);
break;
case 3:
creAnims[attackingInfo->ID]->setType(12);
break;
case 4:
creAnims[attackingInfo->ID]->setType(12);
break;
case 5:
creAnims[attackingInfo->ID]->setType(11);
break;
}
}
else //else for if(aStack.creature->isDoubleWide())
{
switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
{
case 0:
creAnims[attackingInfo->ID]->setType(10);
break;
case 1:
creAnims[attackingInfo->ID]->setType(10);
break;
case 2:
creAnims[attackingInfo->ID]->setType(11);
break;
case 3:
creAnims[attackingInfo->ID]->setType(12);
break;
case 4:
creAnims[attackingInfo->ID]->setType(12);
break;
case 5:
creAnims[attackingInfo->ID]->setType(11);
break;
}
}
}
else if(attackingInfo->frame == (attackingInfo->maxframe - 1))
{
attackingInfo->reversing = true;
CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
if(aStack.creature->isDoubleWide())
{
switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
{
case 0:
//reverseCreature(ID, aStack.position, true);
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
//reverseCreature(ID, aStack.position, true);
break;
case 5:
reverseCreature(attackingInfo->ID, aStack.position, true);
break;
}
}
else //else for if(aStack.creature->isDoubleWide())
{
switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
{
case 0:
reverseCreature(attackingInfo->ID, aStack.position, true);
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
reverseCreature(attackingInfo->ID, aStack.position, true);
break;
case 5:
reverseCreature(attackingInfo->ID, aStack.position, true);
break;
}
}
attackingInfo->reversing = false;
creAnims[attackingInfo->ID]->setType(2);
delete attackingInfo;
attackingInfo = NULL;
}
if(attackingInfo)
{
attackingInfo->frame++;
}
}
}
void CBattleHero::show(SDL_Surface *to) void CBattleHero::show(SDL_Surface *to)
{ {
//animation of flag //animation of flag

View File

@ -81,6 +81,16 @@ private:
int activeStack; //number of active stack; -1 - no one int activeStack; //number of active stack; -1 - no one
void showRange(SDL_Surface * to, int ID); //show helper funtion ot mark range of a unit void showRange(SDL_Surface * to, int ID); //show helper funtion ot mark range of a unit
class CAttHelper
{
public:
int ID; //attacking stack
int dest; //atacked hex
int frame, maxframe; //frame of animation, number of frames of animation
bool reversing;
} * attackingInfo;
void attackingShowHelper();
public: public:
CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor
~CBattleInterface(); //d-tor ~CBattleInterface(); //d-tor