| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- function CCard(iX,iY,iType,fScalingFactor,oContainer){
- var _bSuspendUpdates = false;
- var _bFolded;
- var _sType;
- var _iX;
- var _iY;
- var _fScaleFactor;
- var _oSprite;
- var _scope;
- var _oContainer;
-
- this._init = function(iX,iY,iType,fScalingFactor,oContainer){
- _iX = iX;
- _iY = iY;
- _bEliminated = false;
- _bFolded = true;
- _sType = iType;
- _oContainer = oContainer;
-
- _oSprite = createSprite(s_oGame.spriteSheet,"back",CARD_WIDTH/2,CARD_HEIGHT/2,CARD_WIDTH,CARD_HEIGHT);
- if (_iX < CANVAS_WIDTH/2) {
- _oSprite.x = _iX - CANVAS_WIDTH;
- } else {
- _oSprite.x = CANVAS_WIDTH + _iX;
- };
- _oSprite.y = _iY + Math.floor((Math.random()-0.5)*0);
- _fScaleFactor = fScalingFactor;
- _oSprite.scaleX = _oSprite.scaleY = _fScaleFactor;
- _scope = this;
- _oSprite.on("click", function() {
- this.clicked();
- },_scope);
-
-
- if (!s_bMobile)
- _oSprite.cursor = "pointer";
-
- _bSuspendUpdates = true;
- s_oGame.suspendUpdates();
- _oContainer.addChild(_oSprite);
-
- var oParent = this;
- createjs.Tween.get(_oSprite).to({alpha:1, x:_iX, y:_iY}, 500).call(function handleComplete(){
- _bSuspendUpdates = false;
- s_oGame.restartUpdates();
- if(TIME_SHOW_CARDS > 0){
- oParent.showCardFirstTime();
- }
- });
- };
-
- this.unload = function(){
- _oContainer.removeChild(_oSprite);
- };
- this.update = function(){
-
- };
- this.clicked = function(){
- if (_bSuspendUpdates === false && _bFolded) {
- s_oGame.cardClicked(this,_sType);
- playSound("card", 1, false);
- this.clickListener();
- };
- };
-
- this.showCardFirstTime = function(){
- _bSuspendUpdates = true;
- createjs.Tween.get(_oSprite).to({scaleX:0.1}, 100).call(function(){
- _oContainer.removeChild(_oSprite);
- _oSprite = createSprite(s_oGame.spriteSheet,_sType,CARD_WIDTH/2,CARD_HEIGHT/2,CARD_WIDTH,CARD_HEIGHT);
- _oSprite.x = _iX;
- _oSprite.y = _iY;
- _oSprite.scaleX = _oSprite.scaleY = _fScaleFactor;
- _oContainer.addChild(_oSprite);
- createjs.Tween.get(_oSprite).wait(TIME_SHOW_CARDS).to({scaleX:_fScaleFactor}, 100).call(function(){
- _bSuspendUpdates = false;
- _bFolded = false;
- _scope.clickListener();
- _scope.flipCard();
- },_scope);
- });
- };
-
- this.flipCard = function(){
- if (_bFolded === true) {
- _bSuspendUpdates = true;
- createjs.Tween.get(_oSprite).to({scaleX:0.1}, 100).call(function(){
- _oContainer.removeChild(_oSprite);
- _oSprite = createSprite(s_oGame.spriteSheet,_sType,CARD_WIDTH/2,CARD_HEIGHT/2,CARD_WIDTH,CARD_HEIGHT);
- _oSprite.x = _iX;
- _oSprite.y = _iY;
- _oSprite.scaleX = _oSprite.scaleY = _fScaleFactor;
- _oContainer.addChild(_oSprite);
-
- createjs.Tween.get(_oSprite).to({scaleX:_fScaleFactor}, 100).call(function(){
- _bSuspendUpdates = false;
- _bFolded = false;
- s_oGame.addFlippedCard();
- _scope.clickListener();
- },_scope);
- });
- } else {
- playSound("card", 1, false);
- _bSuspendUpdates = true;
- createjs.Tween.get(_oSprite).to({scaleX:0.1}, 100).call(function(){
- _oContainer.removeChild(_oSprite);
- _oSprite = createSprite(s_oGame.spriteSheet,"back",CARD_WIDTH/2,CARD_HEIGHT/2,CARD_WIDTH,CARD_HEIGHT);
- _oSprite.x = _iX;
- _oSprite.y = _iY;
- _oSprite.scaleX = _oSprite.scaleY = _fScaleFactor;
- _oContainer.addChild(_oSprite);
-
- createjs.Tween.get(_oSprite).to({scaleX:_fScaleFactor}, 100).call(function(){
- _bSuspendUpdates = false;
- s_oGame.restartUpdates();
- _bFolded = true;
- _scope.clickListener();
- return true;
- },_scope);
- });
- };
- }
- this.clickListener = function(){
- if (_bSuspendUpdates === false) {
- _oSprite.on("click", function() {
- this.clicked();
- },_scope);
- };
- };
- this.display = function(){
-
- };
- this.isFolded = function(){
- return _bFolded;
- };
- this.getType = function(){
- return _sType;
- };
- this.eliminateCard = function(){
- _bSuspendUpdates = true;
- s_oGame.suspendUpdates();
- _oSprite.alpha = 1;
- createjs.Tween.get(_oSprite).to({alpha:0}, 400).call(function handleComplete(){
- _oContainer.removeChild(_oSprite);
- _bSuspendUpdates = false;
- s_oGame.restartUpdates();
- });
- };
-
- this._init(iX,iY,iType,fScalingFactor,oContainer);
- }
|