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);
}
Example #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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);
	}
}