Пример #1
0
void AheadChapter::startGame(cocos2d::extension::UIButton *pSender, TouchEventType type)
{
    switch (type) {
        case TOUCH_EVENT_BEGAN:
        {
            PLAY_EFFECT(TAP_EFFECT);
        }
            break;
        case TOUCH_EVENT_MOVED:
            break;
        case TOUCH_EVENT_ENDED:
        {
            CCScene *scene = CCScene::create();                         //添加场景
            ChapterLayer *chapterLayer = ChapterLayer::create();        //章节
            scene->addChild(chapterLayer);
//            CCTransitionScene *transition = CCTransitionProgressVertical::create(0.2, scene);
            CCTransitionScene *transition = GlobalUserDefault::instance()->randomTransitionScene(scene);
            CCDirector::sharedDirector()->replaceScene(transition);
        }
            break;
        case TOUCH_EVENT_CANCELED:
        {
            
        }
            break;
        default:
            break;
    }
}
Пример #2
0
void CMatchGame::UpdateGameState()
{
	//检查是否匹配
	int iBoomIndex = 0;
	for (int i = 0; i < BRICK_MATCH_NUM; ++i)
	{
		if (m_arrMyBrick[i] != m_arrDestBrick[i])
		{
			m_enGameState = GAMESTATE_OVER;
			PLAY_EFFECT(EFFECT_BOOM);
			m_arrBoomIndex[iBoomIndex++] = i;
		}
	}

	//如果都匹配,则加分,检查是否通过当前等级
	if (iBoomIndex == 0)
	{
		m_iScore += MACTHSUCC_ADDSCORE;
		m_pGameScene->UpdateScore(m_iScore);

		if (++m_iMatchSuccCount >= GAMEPASS_MATCHCOUNT)
		{
			m_enGameState = GAMESTATE_PASS;
		}
		else
		{
			//重新产生目标方块和我方方块
			InitData();
		}
	}
}
Пример #3
0
//上按下
void CFlappyBirdGame::OnUpBtnPressed()
{
	if (m_enGameState != GAMESTATE_RUNNING)
	{
		return;
	}

	//重置按钮刷新时间
	m_fBirdTotalTime = BIRD_DOWN_INTERVAL - 3 * m_iSpeed;

	//按钮音效
	PLAY_EFFECT(EFFECT_CHANGE2);

	m_pGameScene->UpdateBrick(m_iBirdRowIdx, COLUMN_NUM / 2 - 1, false, false);

	if (--m_iBirdRowIdx < 0)
	{
		m_iBirdRowIdx = 0;
		m_enGameState = GAMESTATE_OVER;
	}

	m_pGameScene->UpdateBrick(m_iBirdRowIdx, COLUMN_NUM / 2 - 1, false, true);

	UpdateGameState();
}
Пример #4
0
void AheadChapter::settingGame(cocos2d::extension::UIButton *pSender, TouchEventType type)
{
    switch (type) {
        case TOUCH_EVENT_BEGAN:
        {
            PLAY_EFFECT(TAP_EFFECT);
        }
            break;
        case TOUCH_EVENT_MOVED:
            break;
        case TOUCH_EVENT_ENDED:
        {

            GlobalUserDefault::instance()->show91ToolBar(false);

            CCScene *scene = CCScene::create();                         //添加场景
            UIControlLayer *gameLayer = UIControlLayer::create();        //章节
            scene->addChild(gameLayer);
            
            CCDirector::sharedDirector()->replaceScene(scene);
        }
            break;
        case TOUCH_EVENT_CANCELED:
            break;
        default:
            break;
    }
    
}
Пример #5
0
void AheadChapter::enterAcountManager(cocos2d::extension::UIWidget *pSender, TouchEventType type)
{
    if (type == TOUCH_EVENT_BEGAN)
    {
        PLAY_EFFECT(TAP_EFFECT);
        
    }else if (type == TOUCH_EVENT_ENDED)
    {
        GlobalUserDefault::instance()->enterAccountManage();
    }
}
Пример #6
0
void CTetrisGame::OnRightBtnPressed()
{
	//音效
	PLAY_EFFECT(EFFECT_CHANGE2);

	//移动一次
	m_fBtnCheckTime = BTN_CHECK_INTERVAL;

	//开启持续移动状态
	m_bRightBtnPressed = true;
}
Пример #7
0
bool CTetrisGame::DeleteLine(bool bEnd)
{
	int iDelCount = 0;

	if (!bEnd)
	{
		//仅需检查一行
		int iRowIdx = GetNextAddOrSubRowIdx(m_stCurPos.m_iColIdx);
		for (int i = 0; i < COLUMN_NUM; ++i)
		{
			if (!m_arrBrick[iRowIdx][i])
			{
				return false;
			}
		}

		DeleteSingleLine(iRowIdx);
		iDelCount = 1;
	}
	else
	{
		for (int i = m_stCurPos.m_iRowIdx; i < m_stCurPos.m_iRowIdx + TETRIS_ROWCOUNT[m_iCurShape]; ++i)
		{
			bool bCanDeleteFlag = true;
			for (int j = 0; j < COLUMN_NUM; ++j)
			{
				if (!m_arrBrick[i][j])
				{
					bCanDeleteFlag = false;
					break;
				}
			}

			//消除单行
			if (bCanDeleteFlag)
			{
				DeleteSingleLine(i);
				++iDelCount;
			}
		}

		if (iDelCount == 0)
		{
			return false;
		}
	}

	//加分
	m_iScore += iDelCount * iDelCount * DELETE_LINE_ADD_SCORE;
	m_pGameScene->UpdateScore(m_iScore, false);
	PLAY_EFFECT(EFFECT_DELETE);

	return true;
}
Пример #8
0
//Fire按下
void CSnakeGame::OnFireBtnPressed()
{
	if (m_enGameState != GAMESTATE_RUNNING)
	{
		return;
	}

	//按钮音效
	PLAY_EFFECT(EFFECT_CHANGE2);

	m_bImproveSpeed = true;
}
Пример #9
0
//右
void CRacingGame::OnRightBtnPressed()
{
	if (m_enGameState != GAMESTATE_RUNNING || m_iCarPos == ROAD_COUNT - 1)
	{
		return;
	}

	//按钮音效
	PLAY_EFFECT(EFFECT_CHANGE2);

	++m_iCarPos;

	//检查目标车道是否被占用
	if (m_arrCurBrick[ROW_NUM - 2][m_iCarPos * 3 + 2] == 1)
	{
		m_enGameState = GAMESTATE_OVER;
		PLAY_EFFECT(EFFECT_BOOM);
	}

	m_pGameScene->UpdateBricks(ROW_NUM - 4, (m_iCarPos - 1) * 3 + 1, ROW_NUM, m_iCarPos * 3 + 4);
}
Пример #10
0
//更改方块类型
void CMatchGame::ChangeType(DIRECTION enDirection, bool bPressed)
{
	if (m_enGameState != GAMESTATE_RUNNING)
	{
		return;
	}

	//按钮音效
	if (bPressed)
	{
		PLAY_EFFECT(EFFECT_CHANGE2);
		UpdateMyBricks(enDirection);
	}
}
Пример #11
0
//开始
void CChooseGame::OnStart()
{
	//停止背景音乐
	STOP_BGMUSIC();

	//播放开始音效
	PLAY_EFFECT(EFFECT_PAUSE);

	//设置游戏索引,生命,等级和速度
	SET_INTVALUE("GAME", m_iGameIndex);
	SET_INTVALUE("SPEED", m_iSpeed);
	SET_INTVALUE("LEVEL", m_iLevel);
	SET_INTVALUE("LIFE", 4);			//默认生命:4

	//切换新游戏
	m_pGameScene->RunScene(GAMEIDX_TO_SCENEIDX[m_iGameIndex]);
}
Пример #12
0
//改变方向
void CSnakeGame::ChangeDirection(int iDirection)
{
	//如果是相同方向或者游戏不是运行中状态,则返回
	if (m_enGameState != GAMESTATE_RUNNING || m_iSnakeDirection == iDirection)
	{
		return;
	}

	//按钮音效
	PLAY_EFFECT(EFFECT_CHANGE2);

	//设置方向
	int nOldDirection = m_iSnakeDirection;
	m_iSnakeDirection = iDirection;

	//如果是反方向
	if (iDirection == OPPSITE_DIRECTION[nOldDirection])
	{
		//转换
		int iNodeCount = m_mapSnakeNodes.size();
		for (int i = 0; i < iNodeCount / 2; ++i)
		{
			POSITION stTempPos = m_mapSnakeNodes[i];
			m_mapSnakeNodes[i] = m_mapSnakeNodes[iNodeCount - 1 - i];
			m_mapSnakeNodes[iNodeCount - 1 - i] = stTempPos;
		}

		//获取下一个位置
		POSITION stHeaderPos = m_mapSnakeNodes[0];
		GetNextPos(stHeaderPos);

		//是否可以按照反方向移动,不能则恢复之前的方向
		if (CheckGameOver(stHeaderPos))
		{
			m_iSnakeDirection = nOldDirection;
		}
	}
	
	//移动
	SnakeMove();

	//重置时间
	m_fWaitRefreshTime = 0;
}
Пример #13
0
void AheadChapter::reSetGame(cocos2d::extension::UIButton *pSender, TouchEventType type)
{
    switch (type) {
        case TOUCH_EVENT_BEGAN:
        {
            PLAY_EFFECT(TAP_EFFECT);
        }
            break;
        case TOUCH_EVENT_MOVED:
            break;
        case TOUCH_EVENT_ENDED:
        {
            
        }
            break;
        case TOUCH_EVENT_CANCELED:
            break;
        default:
            break;
    }
}
Пример #14
0
void Arcade::playSoundTake() {
  PLAY_EFFECT(_snd_take.getCString());
}
Пример #15
0
//蛇更新位置
void CSnakeGame::SnakeMove()
{
	PLAY_EFFECT(EFFECT_WALL);

	//记录最后一个节点位置,因为可能需要增加节点
	int iNodeCount = m_mapSnakeNodes.size();
	POSITION stLastPos = m_mapSnakeNodes[iNodeCount - 1];

	//获取头部下个位置
	POSITION stHeaderPos = m_mapSnakeNodes[0];
	GetNextPos(stHeaderPos);

	if (CheckGameOver(stHeaderPos))
	{
		//设置结束状态
		m_enGameState = GAMESTATE_OVER;

		//设置苹果显示状态
		m_bAppleState = true;

		//音效
		PLAY_EFFECT(EFFECT_BOOM);
		return;
	}

	//更新其他节点
	for (int i = iNodeCount - 2; i >= 0; --i)
	{
		POSITION& stSrcPos = m_mapSnakeNodes[i + 1];
		const POSITION& stDestPos = m_mapSnakeNodes[i];
		stSrcPos.m_iRowIdx = stDestPos.m_iRowIdx;
		stSrcPos.m_iColIdx = stDestPos.m_iColIdx;
	}

	//头部位置更新
	m_mapSnakeNodes[0] = stHeaderPos;

	//检查头部位置是否是苹果的位置
	if (stHeaderPos == m_stApplePos)
	{
		//加分
		m_iScore += SNAKE_EAT_ADD_SCORE;
		m_pGameScene->UpdateScore(m_iScore);

		//增加节点
		m_mapSnakeNodes[iNodeCount] = stLastPos;

		//检查是否通过
		/*if (iNodeCount + 1 == SNAKE_MAX_LEN)
		{
			m_enGameState = GAMESTATE_PASS;
			return;
		}*/

		//苹果不显示
		m_pGameScene->UpdateBrick(m_stApplePos.m_iRowIdx, m_stApplePos.m_iColIdx, false, false);

		//重新随机苹果位置
		RandApplePos();
	}
}
Пример #16
0
void CTetrisGame::OnBrickDoneMove()
{
	//处理非特殊方块以及点特殊方块
	if (m_iCurShape < 19 || m_iCurShape == 22)
	{
		if (m_iCurShape == 22)
		{
			//设置行索引
			m_stCurPos.m_iRowIdx = GetEmptyPosRowIdx();
		}

		//已无法再往下移动或已到达最后一行,保存当前方块
		for (int i = 0; i < 4 && m_stCurPos.m_iRowIdx + i < ROW_NUM; ++i)
		{
			for (int j = 0; j < 4 && m_stCurPos.m_iColIdx + j < COLUMN_NUM; ++j)
			{
				if (TETRIS_SHAPE[m_iCurShape][i][j])
				{
					m_arrBrick[m_stCurPos.m_iRowIdx + i][m_stCurPos.m_iColIdx + j] = true;
				}
			}
		}
	}
	else
	{
		//如果是爆炸方块,消除底下的指定行数
		if (m_iCurShape == 21)
		{
			int iStartRowIdx = m_stCurPos.m_iRowIdx;
			int iEndRowIdx = iStartRowIdx + TETRIS_ROWCOUNT[m_iCurShape] + BOMB_DELETE_LINE_COUNT + (m_bFastMoveDown ? m_iSpeed / 4 + 1 : 0);
			iEndRowIdx = (iEndRowIdx > ROW_NUM ? ROW_NUM : iEndRowIdx);
			for (int i = iStartRowIdx; i < iEndRowIdx; ++i)
			{
				for (int j = m_stCurPos.m_iColIdx; j < m_stCurPos.m_iColIdx + TETRIS_COLCOUNT[m_iCurShape]; ++j)
				{
					m_arrBrick[i][j] = false;
					m_pGameScene->UpdateBrick(i, j, false, false);
				}
			}

			//音效
			PLAY_EFFECT(EFFECT_BOOM);

			//更新炸弹位置,需要显示在最底下消除的那一行
			//修改:炸弹改为3行,但爆炸时需要显示四行,所以需要上移一行
			m_stCurPos.m_iRowIdx = iEndRowIdx - TETRIS_ROWCOUNT[m_iCurShape] - 1;

			//进入暂停状态
			m_enGameState = GAMESTATE_PAUSE;
			m_iSelfFlashCount = 0;
			return;
		}
	}

	//检查消行
	if (!DeleteLine(true) && m_iCurShape < 19)
	{
		PLAY_EFFECT(EFFECT_ADD);
	}

	//产生新的方块
	RandNewShape();
}
Пример #17
0
void CTetrisGame::OnFireBtnPressed()
{
	PLAY_EFFECT(EFFECT_CHANGE2);

	//处理特殊方块
	if (m_iCurShape == 19 || m_iCurShape == 20)
	{
		bool bAddFlag = (m_iCurShape == 19);

		//获取当前位置对应列包含的方块数量
		int iRowIdx = GetNextAddOrSubRowIdx(m_stCurPos.m_iColIdx);
		
		//要操作的方块位置
		iRowIdx += (bAddFlag ? -1 : 0);
		if (iRowIdx < m_stCurPos.m_iRowIdx + TETRIS_ROWCOUNT[m_iCurShape] || iRowIdx > ROW_NUM - 1)
		{
			return;
		}
		int iColIdx = m_stCurPos.m_iColIdx;

		//设置状态
		m_arrBrick[iRowIdx][iColIdx] = bAddFlag;
		m_pGameScene->UpdateBrick(iRowIdx, iColIdx, false, bAddFlag);

		//如果是加方块,需要检查是否可以消除行
		if (bAddFlag)
		{
			DeleteLine(false);
		}

		return;
	}


	//检查当前形状所属类型
	int iAllTypeCount = sizeof(TETRIS_TYPE_START_IDX) / sizeof(int);
	int iStartIdx = TETRIS_TYPE_START_IDX[iAllTypeCount - 1];
	int iEndIdx = GetShapeCount();
	for (int i = 0; i < iAllTypeCount; ++i)
	{
		if (m_iCurShape < TETRIS_TYPE_START_IDX[i])
		{
			iStartIdx = TETRIS_TYPE_START_IDX[i - 1];
			iEndIdx = TETRIS_TYPE_START_IDX[i];
			break;
		}
	}
	
	int iShape = m_iCurShape;
	if (++iShape >= iEndIdx)
	{
		iShape = iStartIdx;
	}

	//检查是否可以变换
	if (CheckBrickPos(iShape, m_stCurPos.m_iRowIdx, m_stCurPos.m_iColIdx))
	{
		//更新当前形状
		m_iCurShape = iShape;

		//位置修正
		if (m_stCurPos.m_iColIdx + TETRIS_COLCOUNT[m_iCurShape] > COLUMN_NUM)
		{
			m_stCurPos.m_iColIdx = COLUMN_NUM - TETRIS_COLCOUNT[m_iCurShape];
		}

		//更新显示
		m_pGameScene->UpdateBricks(m_stCurPos.m_iRowIdx, m_stCurPos.m_iColIdx,
			m_stCurPos.m_iRowIdx + 4, m_stCurPos.m_iColIdx + 4);
	}
}
Пример #18
0
void CTetrisGame::OnDownBtnPressed()
{
	PLAY_EFFECT(EFFECT_CHANGE2);
	m_bFastMoveDown = true;
}
Пример #19
0
void Arcade::playSoundCollide() {
  PLAY_EFFECT(_snd_collide.getCString());
}
Пример #20
0
void Arcade::playSoundDrop() {
  PLAY_EFFECT(_snd_drop.getCString());
}
Пример #21
0
//更新
void CRacingGame::Play(float dt)
{
	if (!m_bFirstShow)
	{
		m_fWaitTime += dt;
		if (m_fWaitTime < GetWaitInterval())
		{
			return;
		}

		//重置时间
		m_fWaitTime = 0;
	}
	else
	{
		RandCreateCars();
		m_bFirstShow = false;
	}

	if (m_enGameState == GAMESTATE_RUNNING)
	{
		UpdateBricks();

		//检查是否游戏结束
		if (m_arrCurBrick[ROW_NUM - 4][m_iCarPos * 3 + 2] == 1 && m_arrCurBrick[ROW_NUM - 5][m_iCarPos * 3 + 2] == 1)
		{
			m_enGameState = GAMESTATE_OVER;
			PLAY_EFFECT(EFFECT_BOOM);
		}
	}
	
	if (m_enGameState == GAMESTATE_OVER)
	{
		if (m_iShowBoomCount < BOOM_SHOWCOUNT)
		{
			m_bShowBoom = !m_bShowBoom;
			++m_iShowBoomCount;
		}
		else
		{
			//设置剩余生命
			--m_iLife;
			m_pGameScene->UpdateSmallBricks();

			//检查是否有剩余生命,没有则返回游戏结束界面
			if (m_iLife <= 0)
			{
				m_pGameScene->RunScene(SCENE_GAMEOVER);
				return;
			}

			//重置数据
			InitData();
		}
	}
	else if (m_enGameState == GAMESTATE_PASS)
	{
		if (m_iAddScoreCount < GAMEPASS_ADDCOUNT)
		{
			++m_iAddScoreCount;
			m_iScore += GAMEPASS_ADDSCORE;
			m_pGameScene->UpdateScore(m_iScore);
			return;
		}
		else
		{
			//更新速度和等级
			if (++m_iSpeed > 10)
			{
				m_iSpeed = 0;
				if (++m_iLevel > 10)
				{
					m_iLevel = 0;
				}
			}

			//更新显示
			m_pGameScene->UpdateLevel(m_iLevel);
			m_pGameScene->UpdateSpeed(m_iSpeed);

			//重置数据
			InitData();
		}
	}

	m_pGameScene->UpdateBricks();
}