313 lines
7.6 KiB
C++
313 lines
7.6 KiB
C++
#include "13S_GameOverAni.h"
|
|
#include "SimpleAudioEngine.h"
|
|
|
|
CGameOverAni::CGameOverAni()
|
|
{
|
|
m_pAnimation = NULL;
|
|
m_bIsPlaying = false;
|
|
}
|
|
|
|
CGameOverAni::~CGameOverAni()
|
|
{
|
|
m_pAnimation->release();
|
|
}
|
|
|
|
bool CGameOverAni::init()
|
|
{
|
|
if (!Node::init())
|
|
{
|
|
return false;
|
|
}
|
|
SpriteFrameCache * pCache = SpriteFrameCache::getInstance();
|
|
pCache->addSpriteFramesWithFile("Games/13S/Ani/NewAnimation20.plist");
|
|
|
|
Vector<SpriteFrame*> animations;
|
|
char str[32] = { 0 };
|
|
for (int i = 1; i <= 4; i++)
|
|
{
|
|
sprintf(str, "shoot_boom_00%d.png", i);
|
|
SpriteFrame *frame = pCache->getSpriteFrameByName(str);
|
|
animations.pushBack(frame);
|
|
}
|
|
m_pAnimation = Animation::createWithSpriteFrames(animations, 0.05f);
|
|
m_pAnimation->retain();
|
|
|
|
return true;
|
|
}
|
|
|
|
void CGameOverAni::showAnimation(const std::function<void(tagSSSTwoGunInfos*)>& fnCallback)
|
|
{
|
|
if (m_VecGunInfos.empty())
|
|
{
|
|
fnCallback(nullptr);
|
|
return;
|
|
}
|
|
|
|
if (!m_bIsPlaying)
|
|
{
|
|
m_bIsPlaying = true;
|
|
|
|
tagSSSTwoGunInfos* pInfo = m_VecGunInfos[0];
|
|
if (nullptr == pInfo || pInfo->isPlayed || nullptr == pInfo->pLoserInfo || nullptr == pInfo->pWinnerInfo)
|
|
{
|
|
fnCallback(nullptr);
|
|
return;
|
|
}
|
|
|
|
pInfo->isPlayed = true;
|
|
tagSSSGunInfo* pWinnerInfo = pInfo->pWinnerInfo;
|
|
tagSSSGunInfo* pLoserInfo = pInfo->pLoserInfo;
|
|
|
|
std::string strPath;
|
|
if (pWinnerInfo->cbGender == 0)
|
|
{
|
|
strPath = "man/m_daqiang";
|
|
}
|
|
else
|
|
{
|
|
strPath = "woman/f_daqiang";
|
|
}
|
|
|
|
CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance();
|
|
std::string strAudioRes = StringUtils::format("Games/13S/Sound/%s.mp3", strPath.c_str());
|
|
pAudio->playEffect(strAudioRes.c_str());
|
|
|
|
//枪火动画;
|
|
Animate *ani = Animate::create(m_pAnimation);
|
|
Repeat* bomb = Repeat::create(ani, 3);
|
|
|
|
//枪火精灵;
|
|
Sprite* sprBoom = Sprite::createWithSpriteFrameName("shoot_boom_001.png");
|
|
sprBoom->setScale(0.5f);
|
|
addChild(sprBoom);
|
|
|
|
//枪精灵;
|
|
Sprite* sprGun = Sprite::createWithSpriteFrameName("shoot_gun.png");
|
|
sprGun->setPosition(pWinnerInfo->ptPos);
|
|
sprGun->setScale(0.8f);
|
|
addChild(sprGun);
|
|
|
|
RotateBy* rota1 = RotateBy::create(GunTime, -10);
|
|
RotateBy* rota2 = RotateBy::create(GunTime, 10);
|
|
Repeat* repeat = Repeat::create(Sequence::create(rota1, rota2, NULL), 3);
|
|
|
|
//auto playSound = CallFunc::create([](){
|
|
// CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance();
|
|
pAudio->playEffect("Games/13S/Sound/spe_shooting.mp3");
|
|
//});
|
|
|
|
//this->runAction(Sequence::create(DelayTime::create(0.5f), playSound, nullptr));
|
|
|
|
switch (pWinnerInfo->wViewID)
|
|
{
|
|
case 0:
|
|
switch (pLoserInfo->wViewID)
|
|
{
|
|
case 1:
|
|
sprGun->setFlippedX(true);
|
|
sprGun->setRotation(-35);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x - 145, pWinnerInfo->ptPos.y - 65));
|
|
break;
|
|
case 2:
|
|
sprGun->setRotation(95);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x + 25, pWinnerInfo->ptPos.y - 145));
|
|
break;
|
|
case 3:
|
|
sprGun->setRotation(40);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x + 128, pWinnerInfo->ptPos.y - 65));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
case 1:
|
|
switch (pLoserInfo->wViewID)
|
|
{
|
|
case 0:
|
|
sprGun->setRotation(-25);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x + 100, pWinnerInfo->ptPos.y + 95));
|
|
break;
|
|
case 2:
|
|
sprGun->setRotation(45);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x + 132, pWinnerInfo->ptPos.y - 70));
|
|
break;
|
|
case 3:
|
|
sprGun->setRotation(5);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x + 145, pWinnerInfo->ptPos.y + 20));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
case 2:
|
|
switch (pLoserInfo->wViewID)
|
|
{
|
|
case 1:
|
|
sprGun->setFlippedX(true);
|
|
sprGun->setRotation(30);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x - 105, pWinnerInfo->ptPos.y + 95));
|
|
break;
|
|
case 0:
|
|
sprGun->setRotation(280);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x - 20, pWinnerInfo->ptPos.y + 132));
|
|
break;
|
|
case 3:
|
|
sprGun->setRotation(-30);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x + 90, pWinnerInfo->ptPos.y + 110));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
case 3:
|
|
switch (pLoserInfo->wViewID)
|
|
{
|
|
case 1:
|
|
sprGun->setFlippedX(true);
|
|
sprGun->setRotation(0);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x - 150, pWinnerInfo->ptPos.y + 20));
|
|
break;
|
|
case 2:
|
|
sprGun->setFlippedX(true);
|
|
sprGun->setRotation(-30);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x - 145, pWinnerInfo->ptPos.y - 50));
|
|
break;
|
|
case 0:
|
|
sprGun->setFlippedX(true);
|
|
sprGun->setRotation(30);
|
|
sprBoom->setPosition(Vec2(pWinnerInfo->ptPos.x - 105, pWinnerInfo->ptPos.y + 95));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
sprBoom->runAction(Sequence::create(bomb, RemoveSelf::create(true), NULL));
|
|
sprGun->runAction(Sequence::create(repeat, RemoveSelf::create(true), NULL));
|
|
|
|
//子弹痕迹;
|
|
Sprite* danHen3 = Sprite::create("Games/13S/Ani/dong.png");
|
|
danHen3->setVisible(false);
|
|
danHen3->setPosition(Vec2(pLoserInfo->ptPos.x + DanHenPadding, pLoserInfo->ptPos.y + DanHenPadding));
|
|
FadeOut* fade3 = FadeOut::create(FadeOutTime);
|
|
fade3->retain();
|
|
addChild(danHen3);
|
|
|
|
Sprite* danHen2 = Sprite::create("Games/13S/Ani/dong.png");
|
|
danHen2->setPosition(pLoserInfo->ptPos);
|
|
danHen2->setVisible(false);
|
|
FadeOut* fade2 = FadeOut::create(FadeOutTime);
|
|
fade2->retain();
|
|
addChild(danHen2);
|
|
|
|
Sprite* danHen1 = Sprite::create("Games/13S/Ani/dong.png");
|
|
FadeOut* fade1 = FadeOut::create(FadeOutTime);
|
|
CallFunc* callFuc = CallFunc::create([=]() {
|
|
CallFunc * callFuc1 = CallFunc::create([=]() {
|
|
fade2->release();
|
|
auto callEnd = CallFunc::create([=]()
|
|
{
|
|
fade3->release();
|
|
m_bIsPlaying = false;
|
|
|
|
if (fnCallback != nullptr)
|
|
{
|
|
fnCallback(pInfo);
|
|
}
|
|
|
|
deleteInfo(pInfo);
|
|
m_VecGunInfos.erase(m_VecGunInfos.begin());
|
|
});
|
|
danHen3->setVisible(true);
|
|
danHen3->runAction(Sequence::create(fade3, callEnd, RemoveSelf::create(true), NULL));
|
|
});
|
|
danHen2->setVisible(true);
|
|
danHen2->runAction(Sequence::create(fade2, callFuc1, RemoveSelf::create(true), NULL));
|
|
});
|
|
danHen1->setPosition(Vec2(pLoserInfo->ptPos.x - DanHenPadding, pLoserInfo->ptPos.y + DanHenPadding));
|
|
addChild(danHen1);
|
|
danHen1->runAction(Sequence::create(fade1, callFuc, RemoveSelf::create(true), NULL));
|
|
}
|
|
}
|
|
|
|
void CGameOverAni::addGunPlay(tagSSSTwoGunInfos* pTwoGunInfo)
|
|
{
|
|
m_VecGunInfos.push_back(pTwoGunInfo);
|
|
}
|
|
|
|
bool CGameOverAni::deleteInfo(tagSSSTwoGunInfos* pInfo)
|
|
{
|
|
if (pInfo != NULL)
|
|
{
|
|
if (pInfo->pLoserInfo != NULL)
|
|
{
|
|
delete pInfo->pLoserInfo;
|
|
pInfo->pLoserInfo = NULL;
|
|
}
|
|
if (pInfo->pWinnerInfo != NULL)
|
|
{
|
|
delete pInfo->pWinnerInfo;
|
|
pInfo->pWinnerInfo = NULL;
|
|
}
|
|
delete pInfo;
|
|
pInfo = NULL;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool CGameOverAni::eraseInfo(int index)
|
|
{
|
|
int beganIndex = 0;
|
|
vector<tagSSSTwoGunInfos*>::iterator iter;
|
|
for (iter = m_VecGunInfos.begin(); iter!=m_VecGunInfos.end();++iter)
|
|
{
|
|
if (beganIndex== index)
|
|
{
|
|
if ((*iter) != NULL)
|
|
{
|
|
deleteInfo((*iter));
|
|
m_VecGunInfos.erase(iter);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
++beganIndex;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
bool CGameOverAni::isExist(int winId, int loseId)
|
|
{
|
|
for (tagSSSTwoGunInfos* pInfo:m_VecGunInfos)
|
|
{
|
|
if (pInfo !=NULL)
|
|
{
|
|
if ((pInfo->pWinnerInfo&&pInfo->pWinnerInfo->wViewID== winId)&&(pInfo->pLoserInfo&&pInfo->pLoserInfo->wViewID==loseId))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
tagSSSTwoGunInfos* CGameOverAni::getNoPlayInfo()
|
|
{
|
|
for (int i=0;i<m_VecGunInfos.size();i++)
|
|
{
|
|
if (m_VecGunInfos[i]!=NULL&&!m_VecGunInfos[i]->isPlayed)
|
|
{
|
|
return m_VecGunInfos[i];
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|