Fix: card matching animation bug
This commit is contained in:
@@ -139,6 +139,31 @@ DudeCard.prototype.removeShowAndHideEvent = function() {
|
||||
}
|
||||
}
|
||||
|
||||
DudeCard.prototype.startWaitAndHideAnimation = function() {
|
||||
this.showAndHideEvent = game.time.events.add(
|
||||
DudeCard.WAIT_AND_HIDE_TIME_SECOND * Phaser.Timer.SECOND,
|
||||
this.finishWaitAndHideAnimation,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
DudeCard.prototype.finishWaitAndHideAnimation = function() {
|
||||
this.hide();
|
||||
}
|
||||
|
||||
DudeCard.prototype.startWaitAndFlipToBackAnimation = function() {
|
||||
this.showAndHideEvent = game.time.events.add(
|
||||
DudeCard.WAIT_AND_FLIP_TO_BACK_TIME_SECOND * Phaser.Timer.SECOND,
|
||||
this.finishWaitAndFlipToBackAnimation,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
DudeCard.prototype.finishWaitAndFlipToBackAnimation = function() {
|
||||
this.flipToBack();
|
||||
}
|
||||
|
||||
|
||||
|
||||
DudeCard.MAX_CARD_COLUMN_NO = 5;
|
||||
DudeCard.MAX_CARD_ROW_NO = 4;
|
||||
@@ -147,4 +172,6 @@ DudeCard.CARD_INITIAL_POSITION_X = -100;
|
||||
DudeCard.CARD_INITIAL_POSITION_Y = -100;
|
||||
|
||||
DudeCard.SHOW_AND_HIDE_TIME_SECOND = 0.5;
|
||||
DudeCard.WAIT_AND_HIDE_TIME_SECOND = 0.5;
|
||||
DudeCard.WAIT_AND_FLIP_TO_BACK_TIME_SECOND = 0.5;
|
||||
DudeCard.INIT_LEFT_TIME_MIN = 2;
|
||||
|
||||
@@ -359,9 +359,9 @@ var Game = {
|
||||
|
||||
if(this.isCardSelectEdgeAll() == true) { // selected 2 cards
|
||||
if(this.isSameCharacterCard() == true) // selected same cards
|
||||
this.clearOpenedTwoCards();
|
||||
this.clearSameTwoCards();
|
||||
else // selected different cards
|
||||
this.resetOpenedTwoCards();
|
||||
this.resetDifferentTwoCards();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,13 +398,6 @@ var Game = {
|
||||
this.cards[this.getCardIndex(col, row)].flipToBack();
|
||||
},
|
||||
|
||||
clearCards: function(col, row) {
|
||||
var index = this.getCardIndex(col, row);
|
||||
this.cards[index].hide();
|
||||
index = this.selectedCardRow * DudeCard.MAX_CARD_COLUMN_NO + this.selectedCardCol;
|
||||
this.cards[index].hide();
|
||||
},
|
||||
|
||||
resetCards: function(col, row) {
|
||||
var index = this.getCardIndex(col, row);
|
||||
this.cards[index].show();
|
||||
@@ -428,6 +421,11 @@ var Game = {
|
||||
+ this.openCardInfoIndex[1] + ", " + this.openCardInfoCharacter[1] + ")");
|
||||
},
|
||||
|
||||
showReservedCardInfo: function() {
|
||||
console.log(this.reservedHideCard[0]);
|
||||
console.log(this.reservedHideCard[1]);
|
||||
},
|
||||
|
||||
isCardSelectEdgeActivated: function() {
|
||||
return this.isCardSelected;
|
||||
},
|
||||
@@ -453,59 +451,45 @@ var Game = {
|
||||
return true;
|
||||
},
|
||||
|
||||
clearOpenedTwoCards: function() {
|
||||
clearSameTwoCards: function() {
|
||||
var card1 = this.cards[this.openCardInfoIndex[0]];
|
||||
this.resetOpenCardInfo(card1.getColumnNo(), card1.getRowNo());
|
||||
this.reservedHideCard[0] = card1;
|
||||
card1.setActive(false);
|
||||
card1.startWaitAndHideAnimation();
|
||||
|
||||
var card2 = this.cards[this.openCardInfoIndex[1]];
|
||||
this.resetOpenCardInfo(card2.getColumnNo(), card2.getRowNo());
|
||||
this.reservedHideCard[1] = card2;
|
||||
card2.setActive(false);
|
||||
card2.startWaitAndHideAnimation();
|
||||
|
||||
// to do : show card 2 (flip to front) and wait 1 sec
|
||||
// to do : hide card 1, card 2
|
||||
// to do : add score, score point animation
|
||||
var tempPlusScore = new PlusScore(card2.x, card2.y, this.getScore());
|
||||
this.plusScoreGroup.add(tempPlusScore);
|
||||
|
||||
// card1.hide();
|
||||
// card2.hide();
|
||||
var hideOpenedCardTimeEvent = game.time.events.add(Phaser.Timer.SECOND * 0.5, this.hideOpenedCard, this);
|
||||
this.gameTimeEvents[this.gameTimeEvents.length + 1] = hideOpenedCardTimeEvent;
|
||||
},
|
||||
|
||||
hideOpenedCard: function() {
|
||||
this.reservedHideCard[0].hide();
|
||||
this.reservedHideCard[1].hide();
|
||||
|
||||
this.scoreManager.plusScore(this.getScore());
|
||||
|
||||
// to do : check clear stage
|
||||
var checkStageClearedEvent = game.time.events.add(Phaser.Timer.SECOND * 0.5, this.checkStageCleared, this);
|
||||
this.gameTimeEvents[this.gameTimeEvents.length + 1] = checkStageClearedEvent;
|
||||
},
|
||||
|
||||
checkStageCleared: function() {
|
||||
this.clearedCardCount += 2;
|
||||
if(this.activatedCardCount == this.clearedCardCount)
|
||||
this.startNextStage();
|
||||
},
|
||||
|
||||
resetOpenedCard: function() {
|
||||
resetDifferentTwoCards: function() {
|
||||
var card1 = this.cards[this.openCardInfoIndex[0]];
|
||||
if(card1 == null)
|
||||
return;
|
||||
this.resetOpenCardInfo(card1.getColumnNo(), card1.getRowNo());
|
||||
card1.flipToBack();
|
||||
card1.startWaitAndFlipToBackAnimation();
|
||||
|
||||
var card2 = this.cards[this.openCardInfoIndex[1]];
|
||||
if(card2 == null)
|
||||
return;
|
||||
this.resetOpenCardInfo(card2.getColumnNo(), card2.getRowNo());
|
||||
card2.flipToBack();
|
||||
|
||||
},
|
||||
|
||||
resetOpenedTwoCards: function() {
|
||||
var resetOpenedCardTimeEvent = game.time.events.add(Phaser.Timer.SECOND * 0.5, this.resetOpenedCard, this);
|
||||
this.gameTimeEvents[this.gameTimeEvents.length + 1] = resetOpenedCardTimeEvent;
|
||||
card2.startWaitAndFlipToBackAnimation();
|
||||
},
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user