Exemplo n.º 1
0
/*判断跳跃范围,只有在有背景的范围下才能跳跃*/
bool GameStage::inWallBoundaries()
{
	CCDrawNode* drawNode;
	int length = this->frontBgList->count();
	float left;
	float right;
	for (int i = length - 1; i >= 0; i-=1)
	{
		drawNode = static_cast<CCDrawNode *>(this->frontBgList->objectAtIndex(i));
		left = drawNode->getPositionX() - this->pukaManCore->roleVo->width * .5;
		right = left + drawNode->getContentSize().width + this->pukaManCore->roleVo->width * .5;
		if(this->pukaManCore->roleVo->x >= left && 
			this->pukaManCore->roleVo->x <= right)
			return true;
	}
	return false;
}
Exemplo n.º 2
0
/*渲染*/
void GameStage::render()
{
	//人物移动和设置手臂和身体的角度
	this->hand->setRotation(this->pukaManCore->roleVo->handRotation);
	this->role->setRotation(this->pukaManCore->roleVo->bodyRotation);
	this->role->setPosition(ccp(this->pukaManCore->roleVo->x, 
								this->pukaManCore->roleVo->y));
	//运动背景移动
	CCDrawNode* drawNode;
	float dis;
	int length = this->drawBgList->count();
	for (int i = 0; i < length; i+=1)
	{
		drawNode = static_cast<CCDrawNode *>(this->drawBgList->objectAtIndex(i));
		if (drawNode->getPositionX() < -drawNode->getContentSize().width)
		{
			//计算移到出边界后的误差,并取绝对值。 重新设置背景的位置并减轻误差。
			dis = (float) abs(drawNode->getPositionX()) - drawNode->getContentSize().width;
			drawNode->setPositionX(drawNode->getContentSize().width - dis);
		}
		drawNode->setPositionX(drawNode->getPositionX() - this->pukaManCore->vx *.5);
	}
	//前景
	length = this->frontBgList->count();
	CCDrawNode* lastDrawNode;
	CCDrawNode* prevDrawNode;
	for (int i = length - 1; i >= 0; i-=1)
	{
		drawNode = static_cast<CCDrawNode *>(this->frontBgList->objectAtIndex(i));
		if (drawNode->getPositionX() <-drawNode->getContentSize().width - this->stageWidth)
		{
			//计算移到出边界后的误差,并取绝对值。 重新设置背景的位置并减轻误差。
			dis = (float) abs(drawNode->getPositionX()) - (drawNode->getContentSize().width + this->stageWidth);
			lastDrawNode = static_cast<CCDrawNode *>(this->frontBgList->objectAtIndex(length - 1));
			drawNode->setPositionX(lastDrawNode->getPositionX() + this->stageWidth - dis);
			this->frontBgList->removeObjectAtIndex(i);
			this->frontBgList->addObject(drawNode);
		}
		
		if(i > 0)
		{
			prevDrawNode = static_cast<CCDrawNode *>(this->frontBgList->objectAtIndex(i - 1));
			drawNode->setPositionX(prevDrawNode->getPositionX() + this->stageWidth);
		}

		float scale = this->pukaManCore->bgWidth / this->stageWidth;
		drawNode->setContentSize(CCSizeMake(this->pukaManCore->bgWidth, 
											drawNode->getContentSize().height));
		drawNode->setScaleX(scale);
		drawNode->setPositionX(drawNode->getPositionX() - this->pukaManCore->vx);
	}
}
Exemplo n.º 3
0
void GameStage::onEnter()
{
	CCLOG("gamestage onEnter");
	this->stageWidth = 640;
	this->stageHeight = 360;
	//监听失败消息
	CCNotificationCenter::sharedNotificationCenter()->addObserver(
		this,                         
		callfuncO_selector(GameStage::failCallBackFun),  // 处理的消息的回调函数
		FAIL,  // 感兴趣的消息名称
		NULL);   

	//背景
	ccColor4B color4b;
	color4b.r = 42;
	color4b.g = 43;
	color4b.b = 38;
	color4b.a = 0xFF;
	this->background = CCLayerColor::create(color4b);
	this->addChild(this->background);

	//运动背景
	float bgWidth = 43;
	float bgHeigth = this->stageHeight - 140;
	float gapH = 10;
	//使这个数组已经是当前类的成员变量,也必须要做一次retain
	this->drawBgList = CCArray::create();
	this->drawBgList->retain();

	ccColor4F color4f = ColorUtil::getColor4F(56, 57, 51, 255);

	CCDrawNode* drawNode = this->createMotionWall(0, 140, bgWidth, bgHeigth, gapH, color4f);
	float posX = drawNode->getContentSize().width;
	this->drawBgList->addObject(drawNode);
	this->addChild(drawNode);

	drawNode = this->createMotionWall(0, 140, bgWidth, bgHeigth, gapH, color4f);
	drawNode->setPosition(ccp(posX, 0));
	this->drawBgList->addObject(drawNode);
	this->addChild(drawNode);

	//地板
	color4b.r = 116;
	color4b.g = 115;
	color4b.b = 98;
	color4b.a = 0xFF;
	this->floorBg = CCLayerColor::create(color4b);

	CCSize size = CCSizeMake(this->stageWidth, 141);
	this->floorBg->setContentSize(size);
	this->addChild(this->floorBg);
	//地板线条
	color4b.r = 72;
	color4b.g = 66;
	color4b.b = 50;
	color4b.a = 0xFF;
	this->floorLineBg = CCLayerColor::create(color4b);
	size = CCSizeMake(this->stageWidth, 10);
	this->floorLineBg->setContentSize(size);
	this->addChild(this->floorLineBg);
	this->floorLineBg->setPosition(ccp(0, this->floorBg->getContentSize().height));

	//前景
	this->frontBgList = CCArray::create();
	this->frontBgList->retain();

	for (int i = 0; i < 3; i++)
	{
		drawNode = this->createFrontMotionWall(0, 83, this->stageWidth, this->stageHeight - 83, i);
		this->addChild(drawNode);
		drawNode->setPosition(ccp(this->stageWidth * (i - 1), 0));
		this->frontBgList->addObject(drawNode);
	}

	//初始化核心类
	this->pukaManCore = new PukaManCore();
	this->pukaManCore->initGame(17, 2, 10, 15, 0.3, 0, CCDirector::sharedDirector()->getWinSize().height - 35, 70);
	/*初始化人物*/
	this->initRole(this->pukaManCore->roleVo->x, this->pukaManCore->roleVo->y);

	this->uiLayer = CCLayer::create();
	this->uiText = CCSprite::create("uiText.png");
	this->uiText->setAnchorPoint(ccp(0, 0));
	this->uiText->setPosition(ccp(0, this->stageHeight - 50));
	this->uiLayer->addChild(this->uiText);
	this->addChild(this->uiLayer);

	this->bomb = NULL;
	this->comboList = NULL;
	this->scoreList = NULL;
	this->highScoreList = NULL;
	
	//设置最高分记录
	if(Cookie::isSaved())
		this->pukaManCore->highScore = Cookie::getShareUserData()->getIntegerForKey("highScore");

	//设置bombo数字
	this->updateCombo();
	this->updateScore();
	//设置最高分数数字
	this->updateHighScore();
	this->layoutScoreNum(this->highScoreList, 2);

	this->addScoreSpt = CCSprite::create();
	this->addScoreList = CCArray::create();
	this->addScoreList->retain();
	this->updateNumSprite(this->addScoreSpt, 
							this->addScoreList, 
							this->pukaManCore->scoreVar, 0, 0);
	this->uiLayer->addChild(this->addScoreSpt);
	//加号
	CCSprite* addSpt = CCSprite::create("zAdd.png");
	addSpt->setAnchorPoint(ccp(0, 0));
	addSpt->setPosition(ccp(-addSpt->getContentSize().width * .5, 0));
	this->addScoreSpt->addChild(addSpt);
	this->addScoreList->insertObject(addSpt, 0);

	this->layoutScoreNum(this->addScoreList, 0);
	//父sprite执行颜色变化的时候,子sprite也可以执行到这个变化
	this->addScoreSpt->setCascadeOpacityEnabled(true);
	this->addScoreSpt->setVisible(false);

	this->newHighScore = CCSprite::create("newHighScore.png");
	this->newHighScore->setAnchorPoint(ccp(0.5f, 0.5f));
	this->newHighScore->setPosition(ccp(this->stageWidth * .5, this->stageHeight * .5));
	this->newHighScore->setScale(0.0f);
	this->uiLayer->addChild(this->newHighScore);
	//必须覆盖onEnter才能执行 loop监听
	CCScene::onEnter();
}