void HelloWorld::update(float delta)
{
//判断是否按下摇杆及其类型
switch(rocker->rocketDirection)
{
case 1:
//CCLog("move %f %f", hero->getPosition().x, hero->getPosition().y);
hero->SetAnimationAdv("run_animation.plist","run_animation.png", "run_", 2, 8, rocker->rocketRun);
if(hero->getPosition().x+2 + hero->GetHeroSprite()->getContentSize().width/2 < visibleSize.width)
{
if( mymap->JudgeMapNotEnd(visibleSize, true))
{
if(
hero->JudgePositona(visibleSize) //hero in middle
)
{
//下面是移动地图
mymap->MoveMap(hero,visibleSize, true);
break;
}
}
//精灵没到达窗口中间位置或者地图已经移动到边缘了,精灵才可以移动,否则只播放动画
hero->setPosition(ccp(hero->getPosition().x+2,hero->getPosition().y)); //向右走
CCLog("move right");
}
break;
case 2:
//CCLog("move %f %f", rocker->rocketRun);
if(hero->getPosition().y+2 + hero->GetHeroSprite()->getContentSize().height/2 > visibleSize.height)
{
break;
}
hero->setPosition(ccp(hero->getPosition().x, hero->getPosition().y+2)); //向上走
break;
case 3:
//CCLog("move %f %f", rocker->rocketRun);
if(hero->getPosition().x-2 - hero->GetHeroSprite()->getContentSize().width/2 > 0)
{
if( mymap->JudgeMapNotEnd(visibleSize, false))
{
if(
hero->JudgePositona(visibleSize) //hero in middle
)
{
//下面是移动地图
mymap->MoveMap(hero, false);
break;
}
}
hero->setPosition(ccp(hero->getPosition().x-2,hero->getPosition().y)); //向左走
CCLog("move left");
}
break;
case 4:
//CCLog("move %f %f", rocker->rocketRun);
if(hero->getPosition().y-2 - hero->GetHeroSprite()->getContentSize().height/2 < 0)
{
break;
}
hero->setPosition(ccp(hero->getPosition().x,hero->getPosition().y-2)); //向下走
break;
default:
hero->StopAnimation();//停止所有动画和运动
break;
}
if(btn->isTouch)
{
if(hero->IsAttack)//英雄没在攻击
return;
hero->AttackAnimation("attack1_animation.plist","attack1_animation.png","attack_",6,rocker->rocketRun);
m_pProgressView->setCurrentProgress(m_pProgressView->getCurrentProgress()-10); //更改血量
}
}