Guest User

Untitled

a guest
Aug 23rd, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var lives = 3
  2. var score = 0
  3. var currentMoles = new Array(0,0,0)
  4. var moleDelay = 12
  5. var moleI = 0
  6. var moleLife = 24
  7. var gameOver = true
  8. var clickCount = 0
  9.  
  10. gameOverOverlay._visible = false
  11.  
  12. //when the start button is clicked
  13. startOverlay.btStart.onRelease = function(){
  14.     startOverlay._visible = false
  15.     gameOver = false
  16. }
  17.  
  18. //when the game over start button is clicked
  19. gameOverOverlay.btStart.onRelease = function(){
  20.     //reset all variables
  21.     lives = 3
  22.     score = 0
  23.     for(i=0;i<=12;i++){
  24.         grid["spot" + i].gotoAndStop("Idle")
  25.     }
  26.     for(a=0;a<=3;a++){
  27.         currentMoles[a] = 0
  28.     }
  29.    
  30.     moleDelay = 24
  31.     moleI = 0
  32.     moleLife = 36
  33.     //restart the game
  34.     gameOver = false
  35.     gameOverOverlay._visible = false
  36. }
  37.  
  38. //when player clicks the game grid
  39. grid.onRelease = function(){
  40.     if(gameOver == false){
  41.         var confHit = false
  42.         //loop through the panels
  43.         for(i=1;i<=9;i++){
  44.             //if the mouse is clicking one
  45.             if(grid["spot" + i].hitTest(_xmouse, _ymouse)){
  46.                 //loop through the currently up moles
  47.                 for(a=0;a<=3;a++){
  48.                     //if any of the moles are on that tile
  49.                     if(currentMoles[a] == i){
  50.                         confHit = true
  51.                         switch(a){
  52.                             //Boris
  53.                             case 0:
  54.                                 score += 10
  55.                                 currentMoles[0] = 0
  56.                                 grid["spot" + i].gotoAndStop("Idle")
  57.                                 break;
  58.                             //Norman
  59.                             case 1:
  60.                                 score += 10
  61.                                 currentMoles[1] = 0
  62.                                 grid["spot" + i].gotoAndStop("Idle")
  63.                                 break;
  64.                             //Didi
  65.                             case 2:
  66.                                 lives --
  67.                                 if(lives == 0){
  68.                                     isGameOver();
  69.                                 }
  70.                                 currentMoles[2] = 0
  71.                                 grid["spot" + i].gotoAndStop("Idle")
  72.                                 break;
  73.                         }
  74.                     }
  75.                 }
  76.             }
  77.         }
  78.         if(confHit == false){
  79.             score -= 5
  80.         }
  81.         moleDelay -= 0.1
  82.         moleLife -= 0.5
  83.        
  84.         if(moleLife < 12){
  85.             moleLife = 12
  86.         }
  87.     }
  88. }
  89.  
  90. spawnMole = function(){
  91.     //sets the type of the spawn
  92.     var type = Math.floor(Math.random() * 3)
  93.     //sets the location of the spawn
  94.     var tile = Math.floor(Math.random() * 9) + 1
  95.    
  96.     //if that tile is already full
  97.     for(i=0;i<=3;i++){
  98.         if(currentMoles[i] == tile){
  99.             //no mole will spawn
  100.             type = 5
  101.         }
  102.     }
  103.    
  104.     //if there isnt a mole of that type up
  105.     if (currentMoles[type] == 0){
  106.         switch(type){
  107.             //Boris
  108.             case 0:
  109.                 //spawns the karp and assigns the vars
  110.                 grid["spot" + tile].gotoAndStop("Karp");
  111.                 grid["spot" + tile].life = moleLife
  112.                 currentMoles[0] = tile
  113.                 break;
  114.             //Norman   
  115.             case 1:
  116.                 grid["spot" + tile].gotoAndStop("Karp");
  117.                 grid["spot" + tile].life = moleLife
  118.                 currentMoles[1] = tile
  119.                 break;
  120.             //Didi 
  121.             case 2:
  122.                 grid["spot" + tile].gotoAndStop("Shrew");
  123.                 grid["spot" + tile].life = moleLife
  124.                 currentMoles[2] = tile
  125.                 break;
  126.         }
  127.     }
  128. }
  129.  
  130. isGameOver = function(){
  131.     gameOver = true
  132.     gameOverOverlay._visible = true
  133. }
  134.  
  135. killMoles = function(){
  136.     //loops through spawned tiles
  137.     for(i=0;i<=3;i++){
  138.         //deducts one from life
  139.         grid["spot" + currentMoles[i]].life --
  140.         //if its dead
  141.         if(grid["spot" + currentMoles[i]].life <= 0){
  142.             //reset        
  143.             grid["spot" + currentMoles[i]].gotoAndStop("Idle")
  144.             currentMoles[i] = 0
  145.         }
  146.     }
  147. }
  148.  
  149. onEnterFrame = function(){
  150.     if(gameOver == false){
  151.         //if next mole is ready to spawn
  152.         if(moleI >= moleDelay){
  153.             moleI = 0;
  154.             spawnMole();
  155.         }
  156.        
  157.         //deals with moles dissapearing
  158.         killMoles();
  159.         //incriment counters
  160.         moleI ++
  161.     }
  162. }
  163.  
  164. stop();
Add Comment
Please, Sign In to add comment