コード例 #1
0
ファイル: GamePlay.cpp プロジェクト: reddevil138/NineGaps
bool GamePlay::onTouchBegan(Touch *touch, Event *unused_event) {
//touch number button
	if (gameState == Playing) {
		for (int i = 0; i < SUM_NUM; i++) {
			TouchSprite* test = (TouchSprite*) this->getChildByTag(
					TAG_NUMBER + i);
			if (test->isTouchingSprite(touch) == true
					&& test->isHidden == false) {
				test->isTouch = true;
				test->setZOrder(20);
				return true;
			}
		}
	}
}
コード例 #2
0
ファイル: GamePlay.cpp プロジェクト: reddevil138/NineGaps
void GamePlay::onTouchEnded(Touch *touch, Event *unused_event) {
//touch end number button
	if (gameState == Playing) {
		for (int i = 0; i < SUM_NUM; i++) {
			TouchSprite* test = (TouchSprite*) this->getChildByTag(
					TAG_NUMBER + i);
			if (test->isTouch == true) {
				//in frame
				for (int j = 0; j < SUM_NUM; j++) {
					TouchSprite* frame = (TouchSprite*) this->getChildByTag(
							TAG_FRAME_PLAY + j);
					if (frame->isTouchingSprite(touch)
							&& frame->isFixed == false) {
						//di chuyen den o da co so
						if (frame->score != 0 && frame->score != (i + 1)) {
							TouchSprite* transform =
									(TouchSprite*) this->getChildByTag(
											TAG_NUMBER + (frame->score) - 1);
							if (test->posframe != NULL
									&& test->posframe->score != 0) {
								auto actionTo = MoveTo::create(0.2,
										test->posframe->getPosition());
								transform->runAction(actionTo);
								transform->posframe = test->posframe;
								test->posframe->score = frame->score;
							} else {
								auto actionTo =
										MoveTo::create(0.2,
												frameReady[(frame->score - 1)]->getPosition());
								transform->runAction(actionTo);
								transform->posframe = NULL;
							}
						} else {
							//set lai gia tri frame da chuyen
							if (test->posframe != NULL) {
								test->posframe->score = 0;
							}
						}

						//set gia tri frame moi
						frame->score = i + 1;
						auto actionTo = MoveTo::create(0.2,
								frame->getPosition());
						test->isTouch = false;
						test->posframe = frame;
						test->runAction(actionTo);
						test->setZOrder(10);
						if (onSound)
							CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
									"sound/tapNumber.mp3");
						return;
					}
				}

				//out frame
				test->setPosition(touch->getLocation());
				test->isTouch = false;
				test->setZOrder(10);

				//set frame score = 0
				if (test->posframe != NULL) {
					test->posframe->score = 0;
					test->posframe = NULL;
				}
			}
		}
	}
}