Ejemplo n.º 1
0
void Hero::onMoveDone(CCNode *pTarget, void *data)
{
	int direction = (int)data;
	setFaceDirection((HeroDirection)direction);
	isHeroMoving = false;
	//sGlobal->gameLayer->setSceneScrollPosition(this->getPosition());
}
Ejemplo n.º 2
0
void Hero::onMoveDone(Node* pTarget, void* data)
{
	//将void*先转换为int,再从int转换到枚举类型
	int direction = (int) data;
	setFaceDirection((HeroDirection)direction);
	isHeroMoving = false;
	sGlobal->gameLayer->setSceneScrollPosition(this->getPosition());
}
Ejemplo n.º 3
0
void Hero::move(HeroDirection direction) 
{
	if (isHeroMoving)
		return;

	//移动的距离
	Point moveByPosition;
	//根据方向计算移动的距离
	switch (direction)
	{
	case kDown:
		moveByPosition = Vec2(0, -32);
		break;
	case kLeft:
		moveByPosition = Vec2(-32, 0);
		break;
	case kRight:
		moveByPosition = Vec2(32, 0);
		break;
	case kUp:
		moveByPosition = Vec2(0, 32);
		break;
	}
	//计算目标坐标,用当前勇士坐标加上移动距离
	targetPosition = ccpAdd(this->getPosition(), moveByPosition);
	//调用checkCollision检测碰撞类型,如果是墙壁、怪物、门,则只需要设置勇士的朝向
	CollisionType collisionType = checkCollision(targetPosition);
	if (collisionType == kWall || collisionType == kEnemy || collisionType == kDoor || collisionType == kNPC)
	{
		setFaceDirection((HeroDirection)direction);
		return;
	}
	//heroSprite仅播放行走动画
	heroSprite->runAction(sAnimationMgr->createAnimate(direction));
	//主体进行位移,结束时调用onMoveDone方法
	Action *action = Sequence::create(
		MoveBy::create(0.20f, moveByPosition),
		//把方向信息传递给onMoveDone方法
		CCCallFuncND::create(this, callfuncND_selector(Hero::onMoveDone), (void*)direction),
		NULL);
	this->runAction(action);
	isHeroMoving = true;
}
Ejemplo n.º 4
0
void TurningMan::respond(int dir)
{
	setFaceDirection(dir);
	sprite->stopAllActions();
}