예제 #1
0
bool GameJoyStick::initWithFile(const char*bkName,
	const char* beads, float maxRadis, float minRadis)
{
	if (this->Node::init() == false) {
		return false;
	}
	
	Sprite* bk = Sprite::create(bkName);
	if (bk == NULL) {
		return false;
	}

	this->addChild(bk);

	TouchSprite* beadsSprite = TouchSprite::create(beads);
	if (beadsSprite == NULL) {
		return false;
	}
	this->addChild(beadsSprite);
	beadsSprite->addCaptureEventListener(CALL_CAPTURE_FUNC_SELECTOR(GameJoyStick::onCaptureEventHandler), this);
	this->beadsSprite = beadsSprite;

	this->maxRadis = maxRadis;
	this->minRadis = minRadis;
	return true;
}
void HelloWorld::createSprite()
{
  // ask director the window size
  CCSize size = CCDirector::sharedDirector()->getWinSize();
  
  CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("ic_paintroid_logo.png");
  
  TouchSprite* pSprite = new TouchSprite(this);
  pSprite->initWithTexture(texture);
  
  // position the sprite on the center of the screen
  //pSprite->setPosition( ccp(size.width/2, size.height/2) );
  
  int startPos = (int)std::rand() % (int)size.height;
  pSprite->setPosition( ccp(0, startPos) );
  
  // add the sprite as a child to this layer
  this->addChild(pSprite, 0);
  
  CCFiniteTimeAction* actionMove = CCMoveTo::actionWithDuration((rand() % 3) + 2, ccp(size.width, startPos));
  pSprite->runAction(actionMove);
  
  CCFiniteTimeAction* moveFinished = CCCallFuncN::actionWithTarget(this, callfuncN_selector(HelloWorld::moveFinished));
  pSprite->runAction(CCSequence::actions(actionMove, moveFinished, NULL));
}
예제 #3
0
void GamePlay::onTouchMoved(Touch *touch, Event *unused_event) {
	if (gameState == Playing) {
		for (int i = 0; i < SUM_NUM; i++) {
			TouchSprite* test = (TouchSprite*) this->getChildByTag(
					TAG_NUMBER + i);
			if (test->isTouch == true)
				test->setPosition(touch->getLocation());
		}
	}
}
예제 #4
0
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;
			}
		}
	}
}
예제 #5
0
void GameLayer::CheckWin()
{
	int iWin = 0;
	TouchSprite* Card;
	for (int k = 0; k< spCard.size(); k++)
	{
		Card = (TouchSprite*)spCard.at(k);
		if (Card->getTag() == 999){
			iWin++;
		}
	}
	if (iWin == spCard.size())
	{
		//well , you win
		//Card->GameWinJump();
		Card->unschedule(schedule_selector(GameLayer::updateTimeLabel));
		Card->scheduleOnce(schedule_selector(TouchSprite::GameWinJump), 1.0f);
	}
}
예제 #6
0
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;
				}
			}
		}
	}
}
예제 #7
0
void GameLayer::UseTips()
{
	//Find a set of matched cards, Game them
	int iCardNo = 0;
	int iCardMatch = 0;

	TouchSprite* Card;
	TouchSprite* MatchCard;
	for (int i = 0; i < iMaxCard; i++)
	{
		Card = (TouchSprite*)spCard.at(i);
		if (Card->getTag() != 999)
		{
			iCardNo = i;
			break;
		}
	}
	for (int i = iCardNo + 1; i < iMaxCard; i++)
	{
		MatchCard = (TouchSprite*)spCard.at(i);
		if (Card->getTag() == MatchCard->getTag() || Card->getTag() - 1000 == MatchCard->getTag() || Card->getTag() + 1000 == MatchCard->getTag())
		{
			iCardMatch = i;
			break;
		}
	}
	//iCardMatch=FindMatch(iCardNo);
	if (iCardMatch>iCardNo)//found
	{
		int i = Card->getTag() % 1000;
		char file[100];
		//sprintf(file, "match_game_img_%d.jpg", i);
		//file[20] = '\0';
		sprintf(file, "%s", sFile[i - 1]);
		//Card = (TouchSprite*)spCard.at(iCardNo);
		//MatchCard = (TouchSprite*)spCard.at(iCardMatch);
		Card->setTag(999);
		MatchCard->setTag(999);
		Card->setDisplayFrame(SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(file));
		Card->setScaleX(0.9);
		Card->setScaleY(0.97);
		MatchCard->setDisplayFrame(SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(file));
		MatchCard->setScaleX(0.9);
		MatchCard->setScaleY(0.97);
	}
	CheckWin();
}