Example #1
0
void HeroJumpingAttack::enter(Hero *object)
{
	Animation *animation = AnimationManger::instance()->getAnimation("hero_jumpattack");
	Animate *animate = Animate::create(animation);
	animate->setTag(ActionTags::kHeroJumpAttcak);
	object->runAction(animate);
}
void YHCCActionHelper::runIntervalForeverAnimation2(float interval, cocos2d::CCAnimation * animation,
                                                    cocos2d::CCSprite * pSprite,
                                                    const std::function<void ()> & begin_callback,
                                                    const std::function<void ()> & end_callback)
{
    Vector<FiniteTimeAction *> actions;
    Animate * animate = Animate::create(animation);
    Hide * hide = Hide::create();
    DelayTime * delay = DelayTime::create(interval);
    Show * show = Show::create();
    
    if (begin_callback != nullptr)
    {
        CallFunc * callfunc = CallFunc::create(begin_callback);
        actions.pushBack(callfunc);
    }
    actions.pushBack(animate);
    actions.pushBack(hide);
    actions.pushBack(delay);
    actions.pushBack(show);
    if (end_callback != nullptr)
    {
        CallFunc * callfunc = CallFunc::create(end_callback);
        actions.pushBack(callfunc);
    }
    
    Sequence * sequence = Sequence::create(actions);
    RepeatForever * repeatForever = RepeatForever::create(sequence);
    AnimationFrame * frame = animate->getAnimation()->getFrames().at(0);
    pSprite->setDisplayFrame(frame->getSpriteFrame());
    pSprite->runAction(repeatForever);
}
Example #3
0
//
// Animate
//
Animate* Animate::create(Animation *pAnimation)
{
    Animate *pAnimate = new Animate();
    pAnimate->initWithAnimation(pAnimation);
    pAnimate->autorelease();

    return pAnimate;
}
Example #4
0
void HeroGetup::enter(Hero *object)
{
	Animation *animation = AnimationManger::instance()->getAnimation("hero_getup");
	animation->setRestoreOriginalFrame(false);
	Animate *animate = Animate::create(animation);
	animate->setTag(ActionTags::kheroGetup);
	object->runAction(animate);
}
Example #5
0
void HeroSprite::run() {
    if (mRunAnimate == NULL) {
        Animation *animation = Animation::create();
        animation->setDelayPerUnit(0.03f);
        char name[64];
        for (int i=1; i <=11; i++) {
            snprintf(name, sizeof(name), "heroRun_%04d.png", i);
    		SpriteFrame *frame = SpriteFrameCache::getInstance()
				->getSpriteFrameByName(name);
            animation->addSpriteFrame(frame);
        }
        Animate *animate = Animate::create(animation);
        Sequence *seq = Sequence::create(
				animate,
				DelayTime::create(0.1),
				animate->reverse(),
				DelayTime::create(0.1),
				nullptr);
        RepeatForever *repeat = RepeatForever::create(seq);
        mRunAnimate = repeat;
        mRunAnimate->retain();
    }
	runAction(mRunAnimate);

    if (mSmokeRunAnimate == NULL) {
        Animation *animation = Animation::create();
        animation->setDelayPerUnit(0.03f);
        for (int i=1; i <=22; i++) {
            char name[64];
            snprintf(name, sizeof(name), "effectSmokeRun_%04d.png", i);
            SpriteFrame *frame = SpriteFrameCache::getInstance()
                ->getSpriteFrameByName(name);
            animation->addSpriteFrame(frame);
        }
        Animate *animate = Animate::create(animation);
        Sequence *seq = Sequence::create(animate, RemoveSelf::create(), nullptr);
        mSmokeRunAnimate = seq;
        mSmokeRunAnimate->retain();
    }

    CallFunc *callback = CallFunc::create([&]() {
            Sprite *smoke = Sprite::createWithSpriteFrameName("effectSmokeRun_0022.png");
            smoke->setOpacity(160);
            smoke->setScale(0.8);
            smoke->setAnchorPoint(Vec2(0, 0));
            smoke->setPosition(getPosition() - getContentSize()/2);
            smoke->runAction(mSmokeRunAnimate->clone());
            auto move = MoveBy::create(1, Vec2(-300, 0));
            smoke->runAction(move);
            getParent()->addChild(smoke, 0, "smokeRun");
            });
    auto seq = Sequence::create(callback, DelayTime::create(0.30f), nullptr);
    runAction(RepeatForever::create(seq));

	mState = STATE_RUN;
}
Example #6
0
void AnimateGenealogy::addAnimate (const Animate& animate, size_t ancestor_)
{
  animates_.emplace(animate.id(), Animate(animate));
  auto descendant = descendants_.find(ancestor_);
  if (descendant == descendants_.end()) {
    descendants_[ancestor_].insert(animate.id());
  } else {
    descendants_[ancestor_].insert(animate.id());
  }

}
Example #7
0
void HeroRun::enter(Hero *object)
{
	Animation *animation = AnimationManger::instance()->getAnimation("hero_run");
	animation->setLoops(-1);
	animation->setDelayPerUnit(0.08f);
	Animate *animate = Animate::create(animation);
	animate->setTag(ActionTags::kHeroRun);
	object->runAction(animate);

	if (object->hasWeapon())
	{
		auto current_level = object->getEntityManger()->getCurrentLevel();
		current_level->dropWeapon(object);
	}
}
Example #8
0
void HeroHurt::enter(Hero *object)
{
	// 面向对你造成伤害者
	int entity_id = object->getStateMachine()->userdata().hurt_source;
	BaseGameEntity *entity = object->getEntityManger()->getEntityByID(entity_id);
	if (entity != nullptr)
	{
		if (entity->getPositionX() < object->getPositionX())
		{
			object->setDirection(BaseGameEntity::kLeftDirection);
		}
		else
		{
			object->setDirection(BaseGameEntity::kRightDirection);
		}
	}

	system_clock::time_point current_time = system_clock::now();
	system_clock::time_point last_hurt_time = object->getStateMachine()->userdata().was_hit_time;
	system_clock::duration duration = current_time - last_hurt_time;
	if (duration_cast<milliseconds>(duration).count() < 1000)
	{
		++object->getStateMachine()->userdata().was_hit_count;
	}
	else
	{
		object->getStateMachine()->userdata().was_hit_count = 1;
	}

	if (object->getStateMachine()->userdata().was_hit_count < 3)
	{
		Animation *animation = AnimationManger::instance()->getAnimation("hero_hurt");
		Animate *animate = Animate::create(animation);
		animate->setTag(ActionTags::kHeroHurt);
		object->runAction(animate);
		object->getStateMachine()->userdata().was_hit_time = system_clock::now();
	}
	else
	{
		object->getStateMachine()->change_state(HeroKnockout::instance());
	}

	if (object->hasWeapon())
	{
		auto current_level = object->getEntityManger()->getCurrentLevel();
		current_level->dropWeapon(object);
	}
}
Example #9
0
void HeroJump::enter(Hero *object)
{
	object->getStateMachine()->userdata().jump_up = true;
	object->getStateMachine()->userdata().before_jump_y = object->getPositionY();
	Animation *animation = AnimationManger::instance()->getAnimation("hero_jump");
	animation->setRestoreOriginalFrame(false);
	Animate *animate = Animate::create(animation);
	animate->setTag(ActionTags::kHeroJump);
	object->runAction(animate);

	if (object->hasWeapon())
	{
		auto current_level = object->getEntityManger()->getCurrentLevel();
		current_level->dropWeapon(object);
	}
}
Example #10
0
 void AnimateContainer::OnTimer()
 {
     _animates::iterator iter = animates_.begin();
     while (iter != animates_.end())
     {
         Animate* animate = *iter;
         animate->Step();
         if (animate->IsFinished())
         {
             iter = animates_.erase(iter);
         }
         else
         {
             ++iter;
         }
     }
 }
Example #11
0
void CLifeObject::SetAttackAnimation()
{
	// TODO : delete
	auto animationCashe = AnimationCache::getInstance();
	auto spriteFrameCashe = SpriteFrameCache::getInstance();
	////

	int idAnimation = GetIndexAttackAnimation(m_direction);
	if (getActionByTag(idAnimation) == nullptr)
	{
		Animate *oldAnimate = GetOldAnimate();

		Animation *animation = m_type->GetAttackAnimations().at(idAnimation - rangesDirections.size());
		Animate *newAnimate = Animate::create(animation);

		newAnimate->setTag(idAnimation);

		if (oldAnimate != nullptr)
		{
			if (oldAnimate->getTag() != newAnimate->getTag())
			{
				newAnimate->setDuration(oldAnimate->getDuration());
			}
		}

		runAction(newAnimate);


	}

}
Example #12
0
void HeroIdle::enter(Hero *object)
{
	Animation *animation = AnimationManger::instance()->getAnimation("hero_idle");
	animation->setLoops(-1);
	Animate *animate = Animate::create(animation);
	animate->setTag(ActionTags::kHeroIdle);
	object->runAction(animate);

	if (object->hasWeapon())
	{
		animation = AnimationManger::instance()->getAnimation("weapon_idle");
		animation->setLoops(-1);
		animate = Animate::create(animation);
		animate->setTag(ActionTags::kWeaponIdle);
		object->getWeaponSkin()->runAction(animate);
		object->getWeaponSkin()->setVisible(true);
	}
}
Example #13
0
void HeroAttack::enter(Hero *object)
{
	if (object->getEntityManger()->getCurrentLevel()->pickUpWeapon(object))
	{
		object->getStateMachine()->userdata().hit_target_count = 0;
		object->getStateMachine()->change_state(HeroIdle::instance());
	}
	else
	{
		system_clock::time_point current_time = system_clock::now();
		system_clock::time_point last_hurt_time = object->getStateMachine()->userdata().hit_target_time;
		system_clock::duration duration = current_time - last_hurt_time;
		if (duration_cast<milliseconds>(duration).count() < 1000)
		{
			++object->getStateMachine()->userdata().hit_target_count;
		}
		else
		{
			object->getStateMachine()->userdata().hit_target_count = 1;
		}

		char str[32];
		sprintf(str, "hero_attack_0%d", object->getStateMachine()->userdata().hit_target_count - 1);
		Animation *animation = AnimationManger::instance()->getAnimation(str);
		Animate *animate = Animate::create(animation);
		animate->setTag(ActionTags::kHeroAttcak);
		object->runAction(animate);

		if (object->hasWeapon())
		{
			sprintf(str, "weapon_attack_0%d", object->getStateMachine()->userdata().hit_target_count - 1);
			animation = AnimationManger::instance()->getAnimation(str);
			animate = Animate::create(animation);
			animate->setTag(ActionTags::kWeaponAttack);
			object->getWeaponSkin()->runAction(animate);
			object->getWeaponSkin()->setVisible(true);
		}
	}
}
Example #14
0
bool SGSHero::initActions()
{
  std::string hero_res_file_full_path = getHeroResFile(SG_SKIRMISH_SCENE_HERO_RES_PATH);
  // Init hero start picture
  if (!Sprite::initWithFile(hero_res_file_full_path, Rect(0, 0, SG_SKIRMISH_SCENE_HERO_WALK_RES_WIDTH, SG_SKIRMISH_SCENE_HERO_WALK_RES_HEIGHT))) {
    return false;
  }

  Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(hero_res_file_full_path);
  for (int i = 0; i < 11; i++) {
    SpriteFrame* frame = SpriteFrame::createWithTexture(
      texture, Rect(0, SG_SKIRMISH_SCENE_HERO_WALK_RES_HEIGHT * i, 
      SG_SKIRMISH_SCENE_HERO_WALK_RES_WIDTH, SG_SKIRMISH_SCENE_HERO_WALK_RES_HEIGHT));
    frame->retain();
    __sprite_frames.pushBack(frame);
  }

  Vector<SpriteFrame*>* animFrames = new Vector<SpriteFrame*>;
  animFrames->pushBack(__sprite_frames.at(0));
  animFrames->pushBack(__sprite_frames.at(1));
  Animation* animation = Animation::createWithSpriteFrames(*animFrames, 0.2f);
  Animate* animate = Animate::create(animation);
  animate->retain();
  std::string animate_name = "face_south";
  __animate_map[animate_name] = animate;

  Vector<SpriteFrame*>* animFrames_north = new Vector<SpriteFrame*>;
  animFrames_north->pushBack(__sprite_frames.at(2));
  animFrames_north->pushBack(__sprite_frames.at(3));
  Animation* animation_north = Animation::createWithSpriteFrames(*animFrames_north, 0.2f);
  Animate* animate_north = Animate::create(animation_north);
  animate_north->retain();
  animate_name = "face_north";
  __animate_map[animate_name] = animate_north;

  Vector<SpriteFrame*>* animFrames_west = new Vector<SpriteFrame*>;
  animFrames_west->pushBack(__sprite_frames.at(4));
  animFrames_west->pushBack(__sprite_frames.at(5));
  Animation* animation_west = Animation::createWithSpriteFrames(*animFrames_west, 0.2f);
  Animate* animate_west = Animate::create(animation_west);
  animate_west->retain();
  animate_name = "face_west";
  __animate_map[animate_name] = animate_west;

  Vector<SpriteFrame*>* fragile = new Vector<SpriteFrame*>;
  fragile->pushBack(__sprite_frames.at(9));
  Animation* animation_fragile = Animation::createWithSpriteFrames(*fragile, 1.0f);
  Animate* animate_fragile = Animate::create(animation_fragile);
  animate_fragile->retain();
  animate_name = "fragile";
  __animate_map[animate_name] = animate_fragile;


  Vector<SpriteFrame*>* wheeze = new Vector<SpriteFrame*>;
  wheeze->pushBack(__sprite_frames.at(9));
  wheeze->pushBack(__sprite_frames.at(10));
  Animation* animation_wheeze = Animation::createWithSpriteFrames(*wheeze, 0.2f);
  Animate* animate_wheeze = Animate::create(animation_wheeze);
  animate_wheeze->retain();
  animate_name = "wheeze";
  __animate_map[animate_name] = animate_wheeze;
  return true;
}
Example #15
0
void SkillEffectShow::playExplosionSpecific(const char *path)
{
	m_explosionSprite = Sprite::create();

	if (m_skillInfo.getIsThirdParty() == true)
	{
		Point point = m_showSprite->getPosition();
		m_explosionSprite->setPosition(point);
		GAME_SCENE->getCurrBgMap()->addChild(m_explosionSprite);
		Point high = ((Monomer*)m_attacker->getParent())->getHurtPointRelativeFootOffset();
		//setZOrder 
		m_explosionSprite->setLocalZOrder(BgMap::getZOrder(ccpSub(point, high)) + 1);

	}
	else
	{
		Monomer* victim = (Monomer*)m_victim->getParent();
		if (victim == NULL)
		{
			this->releaseThis();
			return;
		}

		float x = victim->getContentSize().width * victim->getFigure()->getAnchorPointCenter().x;
		float y = victim->getContentSize().height * victim->getFigure()->getAnchorPointCenter().y;
		m_explosionSprite->setPosition(Point(x, y));
		m_victim->addChild(m_explosionSprite);
	}

	int flag = 0;

	//CCArray* array = CCArray::createWithCapacity(4);
	Vector<SpriteFrame*> array ;
	do
	{
		CCString* string = CCString::createWithFormat("%s_%02d.png", path, flag);
		SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(string->getCString());
		CC_BREAK_IF(spriteFrame == NULL);
		array.pushBack(spriteFrame);
		flag++;
	}
	while (1);

	if (array.size() > 0)
	{
		Animation* movie = Animation::createWithSpriteFrames(array, 1 / (float)24);
		Animate* animate = Animate::create(movie);
		CallFunc* finish = CallFunc::create(this, callfunc_selector(SkillEffectShow::releaseThis));
		Sequence* actions1 = Sequence::create(animate, finish, NULL);

		DelayTime* delay = DelayTime::create(animate->getDuration()/2);
		CallFunc* callFunc = CallFunc::create(this, callfunc_selector(SkillEffectShow::sendMessage));
		Sequence* actions2 = Sequence::create(delay, callFunc, NULL);
		Spawn* spawn = Spawn::create(actions1, actions2, NULL);

		m_explosionSprite->runAction(spawn);
	}
	else
	{
		this->sendMessage();
		this->releaseThis();
	}
}