tenentenen

explained (hopefully) better

Mar 8th, 2016
465
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /**
  2.      * Function that is called once every frame.
  3.      */
  4.     override public function update():Void
  5.     {
  6.         super.update();
  7.        
  8.         var inputP1:Int = player1.touchEvents();
  9.         var inputP2:Int = player2.touchEvents();
  10.        
  11.         switch(gameState) {
  12.             case GAME_BEGIN:
  13.                 gameState = PLAYER_1_TURN;
  14.                 player2.controller.disableButtons(false, true);
  15.                 player1.controller.enableButtons(true, true);
  16.             case PLAYER_1_TURN:
  17.                 //check to see if Anyone slapped
  18.                 if (inputP1 == ControllerBox.SLAP_BUTTON_DOWN) {
  19.                     playerSlapped(Player.PLAYER_ONE);
  20.                 }
  21.                 if (inputP2 == ControllerBox.SLAP_BUTTON_DOWN) {
  22.                     playerSlapped(Player.PLAYER_TWO);
  23.                 }
  24.                 //check to see if player 1 played a card
  25.                 if (inputP1 == ControllerBox.NEXT_BUTTON_DOWN) {
  26.                     playerPlayCard(Player.PLAYER_ONE);
  27.                 }
  28.             case PLAYING_CARD_1:
  29.                 //wait until timer is done, then switch to player 2 turn
  30.             case PLAYER_2_TURN:
  31.                 //check to see if Anyone slapped
  32.                 if (inputP1 == ControllerBox.SLAP_BUTTON_DOWN) {
  33.                     playerSlapped(Player.PLAYER_ONE);
  34.                 }
  35.                 if (inputP2 == ControllerBox.SLAP_BUTTON_DOWN) {
  36.                     playerSlapped(Player.PLAYER_TWO);
  37.                 }
  38.                 //check if player 2 played a card
  39.                 if (inputP2 == ControllerBox.NEXT_BUTTON_DOWN) {
  40.                     playerPlayCard(Player.PLAYER_TWO);
  41.                 }
  42.             case PLAYING_CARD_2:
  43.                 //wait for timer, then switch to player 1 turn;
  44.             case SLAP_IN_PROGRESS:
  45.                 //check to see if Anyone slapped
  46.                 if (inputP1 == ControllerBox.SLAP_BUTTON_DOWN) {
  47.                     playerSlapped(Player.PLAYER_ONE);
  48.                 }
  49.                 if (inputP2 == ControllerBox.SLAP_BUTTON_DOWN) {
  50.                     playerSlapped(Player.PLAYER_TWO);
  51.                 }
  52.                 //check to see if the slap is closed. and if it is, initiate slap end mechanics/animations
  53.                 if (cardStack.slapManager.state == SlapManager.SLAP_CLOSED) {
  54.                     this.gameState = (cardStack.slapManager.firstSlap.playerID == Player.PLAYER_ONE) ? PLAYING_CARD_2: PLAYING_CARD_1;
  55.                     giveStack(cardStack.slapManager.firstSlap.playerID);
  56.                 }else {
  57.                     //wait for the timer to finish or the other player to slap
  58.                 }
  59.             case GAME_END:
  60.                 //game over
  61.                 //display stats
  62.                 //play again?
  63.         }
  64.     }
  65.    
  66.     function giveStack(playerID:Int)
  67.     {
  68.         var playerWhoGetsTheStack:Player = (playerID == Player.PLAYER_ONE) ? player1 : player2;
  69.         var otherPlayer:Player = (playerID == Player.PLAYER_ONE) ? player2 : player1;
  70.        
  71.         //destroy the cards in player 2's queue because they lost them in the capture
  72.         playerWhoGetsTheStack.deckMan.addCardsToDiscard(this.cardStack.stack);
  73.         playerWhoGetsTheStack.cardDisplay.collectCardsWon();
  74.                
  75.         //for now, destroy those in p1's as well
  76.         otherPlayer.cardDisplay.destroyCards();
  77.                
  78.         //set a timer to give control back to player after animation is done
  79.         new FlxTimer(CardDisplayArea.DESTROY_DURATION_SECS + CardDisplayArea.DESTROY_DELAY_MAX_SECS + CardDisplayArea.DESTROY_BUFFER_SECS, afterCaptureAnimationComplete, 1);  
  80.     }
  81.    
  82.     private function playerSlapped(playerID:Int)
  83.     {
  84.  
  85. !       //check here if the capture manager is in a complete state. use the capture manager's player id to see
  86. !       // if it was the capturing player who slapped, or if the non-capturing player thought there might be a match on the final card.
  87. !       // if it was a valid take (the former case), just disable all player buttons and call givestack()
  88. !       // if the player id in the captureManager doesn't patch the player who slapped, then it's the 'penalty' case
  89. !       // where they give a card to the bottom (same thing happens below in the
  90. !       // matchState check in the "you done fucked up" comment branch)
  91.        
  92.         //see if the stack had a match or not
  93.         var matchState:Int = cardStack.getMatchState();
  94.         if (matchState != CardStackMatchState.NONE) {
  95.             this.gameState = SLAP_IN_PROGRESS;
  96.             var slapData = new SlapData();
  97.             var reactionTimeSecs:Float = (FlxG.game.ticks / 1000) - cardStack.slapManager.cardPlayedBaseTime;
  98.             slapData.setData(playerID, reactionTimeSecs, matchState, cardStack.topCard().value);
  99.            
  100.             cardStack.slapManager.playerSlapped(slapData);
  101.            
  102.             ///check if this is the 1st player who slapped or the second
  103.             if (cardStack.slapManager.state == SlapManager.ONE_SLAP_IN) {
  104.                 var playerWhoSlapped:Player = (playerID == Player.PLAYER_ONE) ? player1 : player2;
  105.                 var otherPlayer:Player = (playerID == Player.PLAYER_ONE) ? player2 : player1;
  106.                
  107.                 //remove control for the player who slapped, and other player can only slap
  108.                 playerWhoSlapped.controller.disableButtons(true, true);
  109.                 otherPlayer.controller.disableButtons(false, true);
  110.                 otherPlayer.controller.enableButtons(true, false);
  111.             }else if (cardStack.slapManager.state == SlapManager.SLAP_CLOSED) {
  112.                 //remove all control while the slap end animations play out
  113.                 player1.controller.disableButtons(true, true);
  114.                 player2.controller.disableButtons(true, true);
  115.             }
  116.         }else {
  117.             //you done fucked up. give A card to the bottom of the stack
  118.         }
  119.     }
  120.    
  121.    
  122.     public function updateTurnAfterCardDonePlaying(timer:FlxTimer):Void {
  123.         //set the time (in seconds) this card was played in the slap manager in case someone slaps (to get reaction time)
  124.         cardStack.slapManager.cardPlayedBaseTime = FlxG.game.ticks / 1000;
  125.        
  126.         //check if there is a capture in progess, and change to player1 turn or player2 turn
  127.         if (gameState == PLAYING_CARD_1) {
  128.             //check capture state
  129.             if (cardStack.captureManager.state == CaptureManager.NO_ACTIVE_CAPTURE) {
  130.                 giveControl(Player.PLAYER_TWO);
  131.             }else if (cardStack.captureManager.state == CaptureManager.CAPTURE_IN_PROGRESS) {
  132.                 if (cardStack.captureManager.playerCapturing == Player.PLAYER_ONE) {
  133.                     //this means the Capture JUST started and player 1 is capturing
  134.                     giveControl(Player.PLAYER_TWO);
  135.                 }else {
  136.                     //not the 1st card in the capture, p2 capturing
  137.                     giveControl(Player.PLAYER_ONE);
  138.                 }
  139.             }else {
  140. !               //here, you should remove this call, since we moved it to playerSlapped()
  141. !               //you do want to disable both player's 'play' buttons here though, because the capture is complete,
  142. !               //and the only way to resolve is for the capturing player to press their slap button.
  143.                 giveStack(Player.PLAYER_TWO);  
  144.             }
  145.         }else if (gameState == PLAYING_CARD_2){
  146.             //check capture state
  147.             if (cardStack.captureManager.state == CaptureManager.NO_ACTIVE_CAPTURE) {
  148.                 giveControl(Player.PLAYER_ONE);
  149.             }else if (cardStack.captureManager.state == CaptureManager.CAPTURE_IN_PROGRESS) {
  150.                 if (cardStack.captureManager.playerCapturing == Player.PLAYER_TWO) {
  151.                     //this means the Capture JUST started and player 2 is capturing
  152.                     giveControl(Player.PLAYER_ONE);
  153.                 }else {
  154.                     //not the 1st card in the capture, p1 capturing
  155.                     giveControl(Player.PLAYER_TWO);
  156.                 }
  157.             }else {
  158.                 //Capture Complete
  159.                 giveStack(Player.PLAYER_ONE);      
  160.             }          
  161.         }
  162.     }
  163.    
  164.     function afterCaptureAnimationComplete(timer:FlxTimer)
  165.     {
  166.         if (gameState == PLAYING_CARD_1) {
  167.             //this means that player 2 captured, and p1 lost, so control goes back to p2
  168.             //control always goes to the person who captured
  169.             cardStack.captureManager.reset();
  170.             cardStack.slapManager.reset();
  171.             cardStack.clear();
  172.            
  173.             player2.updateDeckSizeMeter();
  174.  
  175.             giveControl(Player.PLAYER_TWO);
  176.         }else if (gameState == PLAYING_CARD_2) {
  177.             //this means that player 1 captured, and p2 lost, so control goes back to p1
  178.             cardStack.captureManager.reset();
  179.             cardStack.slapManager.reset();
  180.             cardStack.clear();//clear stack because it was just captured
  181.            
  182.             player1.updateDeckSizeMeter();
  183.  
  184.             giveControl(Player.PLAYER_ONE);
  185.         }
  186.     }
  187.    
  188.     private function giveControl(playerID:Int) {
  189.         if (playerID == Player.PLAYER_ONE) {
  190.             //player 1 controls the play
  191.             gameState = PLAYER_1_TURN;
  192.             player2.controller.disableButtons(false, true);
  193.             player2.controller.enableButtons(true, false);
  194.             player1.controller.enableButtons(true, true);
  195.         }else {
  196.             //change back to player 2 control the play
  197.             gameState = PLAYER_2_TURN;
  198.             player1.controller.disableButtons(false, true);
  199.             player1.controller.enableButtons(true, false);
  200.             player2.controller.enableButtons(true, true);
  201.         }
  202.     }
  203.    
  204. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×