Example #1
0
void GameScene::drawCard(Card card){
	//hide the deck sprite, if it is empty.
	if(gameLogic->isDeckEmpty())
		cardDeckSprite->hide();

	Vec2 targetPos = Vec2(50+uncollectedCardsNum*120, cardDeckSprite->pos.y);

	//shows the card drawn
	if((int)card.type<CARD_ITEM_TYPES_NUM){
		uncolldectedCards[uncollectedCardsNum]
			= new SpriteObject(cardDeckSprite->pos+Vec2(cardDeckSprite->size.x/2, 0), Vec2(0, cardDeckSprite->size.y), "./assets/gamescene/cards.png", Vec2(0, 0), Vec2(100, 150));
		uncolldectedCards[uncollectedCardsNum]->tileIndex.y = (int)card.type+1;
		switch(card.quantity){
			case 2: uncolldectedCards[uncollectedCardsNum]->tileIndex.x = 0; break;
			case 4: uncolldectedCards[uncollectedCardsNum]->tileIndex.x = 1; break;
			case 6: uncolldectedCards[uncollectedCardsNum]->tileIndex.x = 2; break;
			default: assert(false);
		}
	}else{
		//the card is a special character card.
		uncolldectedCards[uncollectedCardsNum]
			= new AnimatedSprite(cardDeckSprite->pos+Vec2(cardDeckSprite->size.x/2, 0), Vec2(0, cardDeckSprite->size.y), "./assets/gamescene/cards.png", Vec2(100, 150), 0.05, 3);
		uncolldectedCards[uncollectedCardsNum]->tileIndex.y = (int)card.type+1;
	}
	gameBoardPanel->add(uncolldectedCards[uncollectedCardsNum]);
	//show the flip in effect
	this->add(new Animator<double>(uncolldectedCards[uncollectedCardsNum]->pos.x, 0.25, targetPos.x));
	this->add(new Animator<double>(uncolldectedCards[uncollectedCardsNum]->size.x, 0.25, cardDeckSprite->size.x));

	//play flip card sfx
	if(card.type==CARD_WLCHAN||card.type==CARD_NOBEL)
		playSfx("./assets/gamescene/holy.wav");
	else
		playSfx("./assets/gamescene/flip.wav");

	//adjust the position of flipMoreButton and collectCardsButton, hide it until the card drawing animation is completed.
	uncollectedCardsNum++;
	flipMoreButton->hide();
	collectCardsButton->hide();
	if(uncollectedCardsNum>=MAX_CARD_UNCOLLECTED){
		hideButtons = true;
	}else{
		flipMoreButton->pos.x = 50+uncollectedCardsNum*CARD_MARGIN;
		collectCardsButton->pos.x = 50+uncollectedCardsNum*CARD_MARGIN;
		this->add(
			new Timer([=](){
				if(!hideButtons){
					if(!gameDb->isAi(gameLogic->getCurrentPlayerIndex())){
						flipMoreButton->show();
						collectCardsButton->show();
					}else{
						processAi();
					}
				}
			}, 0.3)
		);
	}

	this->updateDeckCardsNum();
}
Example #2
0
/**
  * Event handler for when a cube is moved away from a neighbour
  */
void Phonemic::onNeighborRemove(unsigned firstID, unsigned firstSide, unsigned secondID, unsigned secondSide)
{
    // When all cubes are disconnected, we 
    if(state == WORD_FOUND && noNeighbors())
        nextWord();
    
    if((firstSide == LEFT && secondSide == RIGHT) || 
	   (firstSide == RIGHT && secondSide == LEFT))
		playSfx(SfxDetach);
}
Example #3
0
/**
  * Event handler for cube neighboring
  */
void Phonemic::onNeighborAdd(unsigned firstID, unsigned firstSide, unsigned secondID, unsigned secondSide)
{	
    // Behaviour is dependent on the current app state
    if(state == PLAY)
        // Only allow left-to-right (reading order) connections
        if((firstSide == LEFT && secondSide == RIGHT)||(firstSide == RIGHT && secondSide == LEFT)) 
        {
            playSfx(SfxAttach);
            soundOut(leftmostNeighbor(firstID));
            checkForWord(firstID);
        }
}
Example #4
0
void GameScene::cardsLost(){
	//hide the all cards at the same time, with zoom out animation
	for(int i=0; i<uncollectedCardsNum; i++){
		assert(uncolldectedCards[i]!=nullptr);
		this->add(new Animator<double>(uncolldectedCards[i]->size.y, 0.3, uncolldectedCards[i]->size.y, 0.5, 0));
		this->add(new Animator<double>(uncolldectedCards[i]->pos.y, 0.3, uncolldectedCards[i]->pos.y, 0.5, uncolldectedCards[i]->pos.y+uncolldectedCards[i]->size.y*0.5));
	}
	nextTurnDelay += 0.5;
	hideButtons = true;
	playSfx("./assets/gamescene/lost.wav");
	this->updateDeckCardsNum();
}
Example #5
0
void GameScene::showDeltaItem(int playerIndex, int itemType, int oldNum, int newNum){
	if(newNum==oldNum)
		return;

	//new item is added.
	if(newNum>oldNum){
		for(int i=oldNum; i<newNum; i++){
			sp[playerIndex].item[itemType][i] = new SpriteObject(itemPos[itemType]+Vec2(i*30, 0), Vec2(30, 30),
				"./assets/gamescene/items.png", Vec2(itemType, 0), Vec2(30, 30));
			sp[playerIndex].statusPlate->add(sp[playerIndex].item[itemType][i]);
			//zoom animation for items being shown
			this->add(new Animator<Vec2>(sp[playerIndex].item[itemType][i]->size, 0.25*collectedCardNum, Vec2(0, 0), 0.2+0.25*collectedCardNum, sp[playerIndex].item[itemType][i]->size));
			this->add(new Animator<Vec2>(sp[playerIndex].item[itemType][i]->pos, 0.25*collectedCardNum, sp[playerIndex].item[itemType][i]->pos+sp[playerIndex].item[itemType][i]->size*0.5, 0.2+0.25*collectedCardNum, sp[playerIndex].item[itemType][i]->pos));
			sp[playerIndex].item[itemType][i]->size = Vec2(0, 0);
		}
		//play sfx. Note: CARD_ITEM_TYPES_NUM menas silver merit
		this->add( new Timer([=](){
			if(itemType==CARD_ITEM_TYPES_NUM)
				playSfx("./assets/gamescene/silverMerit.wav");
			else
				playSfx("./assets/gamescene/add.wav");
		}, 0.25*collectedCardNum));
	}else{
		for(int i=oldNum; i-->newNum; ){
			//remove the items with zoom out effect
			SpriteObject* itemPtr = sp[playerIndex].item[itemType][i];
			this->add(new Animator<Vec2>(itemPtr->pos, 0.25*collectedCardNum, itemPtr->pos, 0.2+0.25*collectedCardNum, itemPtr->pos+itemPtr->size*0.5));
			this->add(new Animator<Vec2>(itemPtr->size, 0.25*collectedCardNum, itemPtr->size, 0.2+0.25*collectedCardNum, Vec2(0, 0)));
			this->add( new Timer([=](){
				sp[playerIndex].statusPlate->remove(itemPtr);
			}, 0.25+0.25*collectedCardNum));
		}
		//play sfx of removel of item
		this->add( new Timer([=](){
			playSfx("./assets/gamescene/remove.wav");
		}, 0.25*collectedCardNum));
	}
}
Example #6
0
void SoundMan_ns::execute(int command, const char *parm = 0) {
	uint32 n = strtoul(parm, 0, 10);
	bool b = (n == 1) ? true : false;

	switch (command) {
	case SC_PLAYMUSIC:
		if (_musicType == MUSIC_CHARACTER) playCharacterMusic(parm);
		else if (_musicType == MUSIC_LOCATION) playLocationMusic(parm);
		else playMusic();
		break;
	case SC_STOPMUSIC:
		stopMusic();
		break;
	case SC_SETMUSICTYPE:
		_musicType = n;
		break;
	case SC_SETMUSICFILE:
		setMusicFile(parm);
		break;

	case SC_PLAYSFX:
		playSfx(parm, _sfxChannel, _sfxLooping, _sfxVolume);
		break;
	case SC_STOPSFX:
		stopSfx(n);
		break;

	case SC_SETSFXCHANNEL:
		_sfxChannel = n;
		break;
	case SC_SETSFXLOOPING:
		_sfxLooping = b;
		break;
	case SC_SETSFXVOLUME:
		_sfxVolume = n;
		break;

	case SC_PAUSE:
		pause(b);
		break;
	}
}
Example #7
0
void PCSound::playSong(int16 songNum) {
	if (songNum <= 0) {
		_music->stopSong();
		return;
	}

	int16 newTune;
	if (_vm->resource()->isDemo()) {
		if (songNum == 17) {
			_music->stopSong();
			return;
		}
		newTune = _songDemo[songNum - 1].tuneList[0] - 1;
	} else {
		newTune = _song[songNum - 1].tuneList[0] - 1;
	}

	if (_tune[newTune].sfx[0]) {
		playSfx(_tune[newTune].sfx[0]);
		return;
	}

	if (!musicOn())
		return;

	int overrideCmd = (_vm->resource()->isDemo()) ? _songDemo[songNum - 1].overrideCmd : _song[songNum - 1].overrideCmd;
	switch (overrideCmd) {
	// Override all songs
	case  1:
		break;
	// Alter song settings (such as volume) and exit
	case  2:
		_music->toggleVChange();
	default:
		return;
	}

	_lastOverride = songNum;

	_music->queueTuneList(newTune);
	_music->playMusic();
}
Example #8
0
int boardCheckConnection(stone *A, stone *B)
{
	line lineA;
	line lineB;

	int i;
	int j;

	if (A == NULL || B == NULL || A->type == STONE_EMPTY || B->type == STONE_EMPTY)
	{
		return 0;
	}

	if (!stoneCheckMatchingTypes(A->type, B->type))
	{
		return 0;
	}

	stones[A->x][A->y].type = STONE_EMPTY;
	stones[B->x][B->y].type = STONE_EMPTY;

	// Horizontal field of view.
	lineA.x1 = A->x;
	lineA.y1 = A->y;
	lineA.x2 = A->x;
	lineA.y2 = A->y;

	for (i = A->x, j = A->y; i >= 0; --i)
	{
		if (stones[i][j].type != STONE_EMPTY)
		{
			break;
		}

		lineA.x1 = i;
	}
	for (i = A->x, j = A->y; i < BOARD_W; ++i)
	{
		if (stones[i][j].type != STONE_EMPTY)
		{
			break;
		}

		lineA.x2 = i;
	}

	lineB.x1 = B->x;
	lineB.y1 = B->y;
	lineB.x2 = B->x;
	lineB.y2 = B->y;

	for (i = B->x, j = B->y; i >= 0; --i)
	{
		if (stones[i][j].type != STONE_EMPTY)
		{
			break;
		}

		lineB.x1 = i;
	}
	for (i = B->x, j = B->y; i < BOARD_W; ++i)
	{
		if (stones[i][j].type != STONE_EMPTY)
		{
			break;
		}

		lineB.x2 = i;
	}

	crossing = boardCheckVerticalIntersection(&lineA, &lineB, A, B);

	if (!crossing)
	{
		// Vertical field of view.
		lineA.x1 = A->x;
		lineA.y1 = A->y;
		lineA.x2 = A->x;
		lineA.y2 = A->y;

		for (i = A->x, j = A->y; j >= 0; --j)
		{
			if (stones[i][j].type != STONE_EMPTY)
			{
				break;
			}

			lineA.y1 = j;
		}
		for (i = A->x, j = A->y; j < BOARD_H; ++j)
		{
			if (stones[i][j].type != STONE_EMPTY)
			{
				break;
			}

			lineA.y2 = j;
		}

		lineB.x1 = B->x;
		lineB.y1 = B->y;
		lineB.x2 = B->x;
		lineB.y2 = B->y;

		for (i = B->x, j = B->y; j >= 0; --j)
		{
			if (stones[i][j].type != STONE_EMPTY)
			{
				break;
			}

			lineB.y1 = j;
		}
		for (i = B->x, j = B->y; j < BOARD_H; ++j)
		{
			if (stones[i][j].type != STONE_EMPTY)
			{
				break;
			}

			lineB.y2 = j;
		}

		crossing = boardCheckHorizontalIntersection(&lineA, &lineB, A, B);
	}

	if (crossing)
	{
		if (!generating && !checkingMoves)
		{
			fadeOutTimer = showAnimations ? FADE_DELAY : 1;
			stones[A->x][A->y].type = A->type;
			stones[B->x][B->y].type = B->type;

			playSfx(clearSfx);
		}

		A->type = STONE_EMPTY;
		B->type = STONE_EMPTY;

		return 1;
	}
	else
	{
		stones[A->x][A->y].type = A->type;
		stones[B->x][B->y].type = B->type;
	}

	return 0;
}