Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var lives = 3
- var score = 0
- var currentMoles = new Array(0,0,0)
- var moleDelay = 12
- var moleI = 0
- var moleLife = 24
- var gameOver = true
- var clickCount = 0
- gameOverOverlay._visible = false
- //when the start button is clicked
- startOverlay.btStart.onRelease = function(){
- startOverlay._visible = false
- gameOver = false
- }
- //when the game over start button is clicked
- gameOverOverlay.btStart.onRelease = function(){
- //reset all variables
- lives = 3
- score = 0
- for(i=0;i<=12;i++){
- grid["spot" + i].gotoAndStop("Idle")
- }
- for(a=0;a<=3;a++){
- currentMoles[a] = 0
- }
- moleDelay = 24
- moleI = 0
- moleLife = 36
- //restart the game
- gameOver = false
- gameOverOverlay._visible = false
- }
- //when player clicks the game grid
- grid.onRelease = function(){
- if(gameOver == false){
- var confHit = false
- //loop through the panels
- for(i=1;i<=9;i++){
- //if the mouse is clicking one
- if(grid["spot" + i].hitTest(_xmouse, _ymouse)){
- //loop through the currently up moles
- for(a=0;a<=3;a++){
- //if any of the moles are on that tile
- if(currentMoles[a] == i){
- confHit = true
- switch(a){
- //Boris
- case 0:
- score += 10
- currentMoles[0] = 0
- grid["spot" + i].gotoAndStop("Idle")
- break;
- //Norman
- case 1:
- score += 10
- currentMoles[1] = 0
- grid["spot" + i].gotoAndStop("Idle")
- break;
- //Didi
- case 2:
- lives --
- if(lives == 0){
- isGameOver();
- }
- currentMoles[2] = 0
- grid["spot" + i].gotoAndStop("Idle")
- break;
- }
- }
- }
- }
- }
- if(confHit == false){
- score -= 5
- }
- moleDelay -= 0.1
- moleLife -= 0.5
- if(moleLife < 12){
- moleLife = 12
- }
- }
- }
- spawnMole = function(){
- //sets the type of the spawn
- var type = Math.floor(Math.random() * 3)
- //sets the location of the spawn
- var tile = Math.floor(Math.random() * 9) + 1
- //if that tile is already full
- for(i=0;i<=3;i++){
- if(currentMoles[i] == tile){
- //no mole will spawn
- type = 5
- }
- }
- //if there isnt a mole of that type up
- if (currentMoles[type] == 0){
- switch(type){
- //Boris
- case 0:
- //spawns the karp and assigns the vars
- grid["spot" + tile].gotoAndStop("Karp");
- grid["spot" + tile].life = moleLife
- currentMoles[0] = tile
- break;
- //Norman
- case 1:
- grid["spot" + tile].gotoAndStop("Karp");
- grid["spot" + tile].life = moleLife
- currentMoles[1] = tile
- break;
- //Didi
- case 2:
- grid["spot" + tile].gotoAndStop("Shrew");
- grid["spot" + tile].life = moleLife
- currentMoles[2] = tile
- break;
- }
- }
- }
- isGameOver = function(){
- gameOver = true
- gameOverOverlay._visible = true
- }
- killMoles = function(){
- //loops through spawned tiles
- for(i=0;i<=3;i++){
- //deducts one from life
- grid["spot" + currentMoles[i]].life --
- //if its dead
- if(grid["spot" + currentMoles[i]].life <= 0){
- //reset
- grid["spot" + currentMoles[i]].gotoAndStop("Idle")
- currentMoles[i] = 0
- }
- }
- }
- onEnterFrame = function(){
- if(gameOver == false){
- //if next mole is ready to spawn
- if(moleI >= moleDelay){
- moleI = 0;
- spawnMole();
- }
- //deals with moles dissapearing
- killMoles();
- //incriment counters
- moleI ++
- }
- }
- stop();
Add Comment
Please, Sign In to add comment