9 Replies Latest reply on Jan 21, 2013 8:23 AM by mandar vedak

    i am making game where fruits are falling from the sky and man underneath he collect the fruits. Eve

    mandar vedak

      FLASH AS2 CODE

       

      stop();

       

      count=0;

      lives = 3;

      gameover = "";

      _global.seconds = 10;

      //this produces random fruits that fall from the sky

      depth = 0;

      allBalls = new Array();

      pBalls = new Array();

      nBalls = new Array();

      goldenBalls = new Array();

      function fast(){

        fr.speed = (Math.random()*3)+2;

      }

       

       

       

      function makeOne() {

        if (seconds>0) {

        clearInterval(ranOneID);

        ran = (Math.random()*100000+1000;

        ranOneID = setInterval(makeOne, ran);

        One = _root.attachMovie('n_red', 'n_red'+depth, depth++);

        nBalls.push(One);

        //trace(allBalls);

        One._x = Math.random()*670;

        One._y = -350;

        One.speed = (Math.random()*3)+2;

        }

       

        One.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+100) {

        //updateScore(-5);

        black=black+1;

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 60);

        }

        }

        this.removeMovieClip();

        }

        if(this.hitTest(slider_mc.kat)){

       

        red = red+1;

        }

        };

      }

       

       

       

       

      function makeTwo() {

        if (seconds>0) {

        clearInterval(ranTwoID);

        ranTwoID = setInterval(makeTwo, ran);

        Two = _root.attachMovie('n_black', 'n_black'+depth, depth++);

        nBalls.push(Two);

        //trace(allBalls);

        Two._x = Math.random()*670;

        Two._y = -250;

        Two.speed = (Math.random()*3)+2;

        }

        //spin = (Math.random()*6)-1;

        //Two._rotation = random(360)+1;

        Two.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+100) {

        //updateScore(-5);

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 1);

        }

        }

        this.removeMovieClip();

        }

        if(this.hitTest(slider_mc.kat)){

       

        bk = bk+1;

        }

        };

      }

       

       

       

       

       

       

      function makeThree() {

        if (seconds>0) {

        clearInterval(ranThreeID);

        ranThreeID = setInterval(makeThree, ran);

        Three = _root.attachMovie('n_purple', 'n_purple'+depth, depth++);

        nBalls.push(Three);

        //trace(allBalls);

        Three._x = Math.random()*670;

        Three._y = -600;

        Three.speed = (Math.random()*3)+2;

        }

        Three.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+300) {

        //updateScore(-5);

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 1);

        }

        }

        this.removeMovieClip();

        }

        if(this.hitTest(slider_mc.kat)){

       

        purple = purple+1;

        }

        };

      }

       

       

       

       

      function makeFour() {

        if (seconds>0) {

        clearInterval(ranFourID);

        ranFourID = setInterval(makeFour, ran);

        Four = _root.attachMovie('n_gray', 'n_gray'+depth, depth++);

        nBalls.push(Four);

        //trace(allBalls);

        Four._x = Math.random()*670;

        Four._y = -800;

        Four.speed = (Math.random()*3)+2;

        }

        Four.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+100) {

        //updateScore(-5);

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 1);

        }

        }

        this.removeMovieClip();

        }

        if(this.hitTest(slider_mc.kat)){

       

        gray = gray+1;

        }

        };

      }

       

       

       

       

      function makeFive() {

        if (seconds>0) {

        clearInterval(ranFiveID);

        ranFiveID = setInterval(makeFive, ran);

        Five = _root.attachMovie('n_maroon', 'n_maroon'+depth, depth++);

        nBalls.push(Five);

        //trace(allBalls);

        Five._x = Math.random()*670;

        Five._y = -1200;

        Five.speed = (Math.random()*3)+2;

        }

        Five.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+100) {

        //updateScore(-5);

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 1);

        }

        }

        this.removeMovieClip();

        }

        if(this.hitTest(slider_mc.kat)){

       

        maroon = maroon+1;

        }

        };

      }

       

       

       

       

      function makeSix() {

        if (seconds>0) {

        clearInterval(ranSixID);

        ranSixID = setInterval(makeSix, ran);

        Six = _root.attachMovie('p_blue', 'p_blue'+depth, depth++);

        pBalls.push(Six);

        //trace(allBalls);

        Six._x = Math.random()*670;

        Six._y = -1500;

        Six.speed = (Math.random()*3)+2;

        }

        Six.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+100) {

        //updateScore(-5);

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 1);

        }

        }

        this.removeMovieClip();

        }

        if(this.hitTest(slider_mc.kat)){

       

        blue = blue+1;

        }

        };

      }

       

       

       

       

      function makeSeven() {

        if (seconds>0) {

        clearInterval(ranSevenID);

        ranSevenID = setInterval(makeSeven, ran);

        Seven = _root.attachMovie('p_orange', 'p_orange'+depth, depth++);

        pBalls.push(Seven);

        //trace(allBalls);

        Seven._x = Math.random()*670;

        Seven._y = -1800;

        Seven.speed = (Math.random()*3)+2;

        }

        Seven.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+100) {

        //updateScore(-5);

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 1);

        }

        }

        this.removeMovieClip();

        }

        if(this.hitTest(slider_mc.kat)){

       

        orange = orange+1;

        }

        };

      }

       

       

       

       

      function makeEight() {

        if (seconds>0) {

        clearInterval(ranEightID);

        ranEightID = setInterval(makeEight, ran);

        Eight = _root.attachMovie('p_pink', 'p_pink'+depth, depth++);

        pBalls.push(Eight);

        //trace(allBalls);

        Eight._x = Math.random()*670;

        Eight._y = -700;

        Eight.speed = (Math.random()*3)+2;

        }

        Eight.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+100) {

        //updateScore(-5);

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 1);

        }

        }

        this.removeMovieClip();

        }

        if(this.hitTest(slider_mc.kat)){

       

        pink = pink+1;

        }

        };

      }

       

       

       

       

      function makeNine() {

        if (seconds>0) {

        clearInterval(ranNineID);

        ranNineID = setInterval(makeNine, ran);

        Nine = _root.attachMovie('p_green', 'p_green'+depth, depth++);

        pBalls.push(Nine);

        //trace(allBalls);

        Nine._x = Math.random()*670;

        Nine._y = -500;

        Nine.speed = (Math.random()*3)+2;

        }

        Nine.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+100) {

        //updateScore(-5);

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 1);

        }

        }

        this.removeMovieClip();

        }

        if(this.hitTest(slider_mc.kat)){

       

        green = green+1;

        }

        };

      }

       

       

       

       

      function makeTen() {

        if (seconds>0) {

        clearInterval(ranTenID);

        ranTenID = setInterval(makeTen, ran);

        Ten = _root.attachMovie('p_yellow', 'p_yellow'+depth, depth++);

        pBalls.push(Ten);

        //trace(allBalls);

        Ten._x = Math.random()*670;

        Ten._y = -100;

        Ten.speed = (Math.random()*3)+2;

        }

        Ten.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+100) {

        //updateScore(-5);

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 1);

        }

        }

        this.removeMovieClip();

        }

        if(this.hitTest(slider_mc.kat)){

       

        yellow = yellow+1;

        }

        };

      }

       

       

       

       

       

      function makegd() {

        if (seconds>0) {

        clearInterval(rangdID);

        rangdID = setInterval(makegd, ran);

        gd = _root.attachMovie('golden', 'golden'+depth, depth++);

        goldenBalls.push(gd);

        //trace(allBalls);

        gd._x = Math.random()*670;

        gd._y = -100;

        gd.speed = (Math.random()*3)+2;

        }

        gd.onEnterFrame = function() {

        this._y += this.speed;

        if (this._y>Stage.height+100) {

        //updateScore(-5);

        for (i=0; i<allBalls.length; i++) {

        if (this == allBalls[i]) {

        allBalls.splice(i, 1);

        }

        }

        this.removeMovieClip();

        }

        return false;

        };

      }

       

       

       

       

      makeOne();

      makeTwo();

      makeThree();

      makeFour();

      makeFive();

      makeSix();

      makeSeven();

      makeEight();

      makeNine();

      makeTen();

      setInterval(makegd,5000);

       

       

       

       

       

       

       

      _root.attachMovie('slider', 'slider_mc', -1);

      slider_mc._y = Stage.height-182;

      var speed:Number = 12;

      slider_mc.onEnterFrame = function() {

        // LEFT Arrow or A

        if (Key.isDown(Key.LEFT) || Key.isDown(65)) {

        slider_mc._x -= speed;

        }

        if (slider_mc._x>=60.0) {

        slider_mc._x -= speed;

        }

        if (slider_mc._x<=695) {

        slider_mc._x += speed;

        }

        // RIGHT Arrow or D   

        if (Key.isDown(Key.RIGHT) || Key.isDown(68)) {

        slider_mc._x += speed;

        }

      };

      _root.createEmptyMovieClip('watchCollision', -2);

      watchCollision.onEnterFrame = function() {

        for (i=0; i<pBalls.length; i++) {

        var tempBall = pBalls[i];

        if (tempBall.hitTest(slider_mc.kat)) {

        //trace('we hit the cocktail');

        var dupedBall = circle.duplicateMovieClip(tempBall, "circle"+slider_mc.getNextHighestDepth(), slider_mc.getNextHighestDepth());

        dupedBall._x = circle._x-tempBall._x;

        dupedBall._y = circle._y-tempBall._y;

        tempBall.removeMovieClip();

        pBalls.splice(i, 1);

        updateScore(100);

        

        }

        }

      };

       

       

       

       

       

       

      _root.createEmptyMovieClip('watchgdCollision', -4);

      watchgdCollision.onEnterFrame = function() {

        for (i=0; i<goldenBalls.length; i++) {

        var tempBall = goldenBalls[i];

        if (tempBall.hitTest(slider_mc.kat)) {

        //trace('we hit the cocktail');

        var dupedBall = circle.duplicateMovieClip(tempBall, "circle"+slider_mc.getNextHighestDepth(), slider_mc.getNextHighestDepth());

        dupedBall._x = circle._x-tempBall._x;

        dupedBall._y = circle._y-tempBall._y;

        tempBall.removeMovieClip();

        goldenBalls.splice(i, 1);

        lives=lives+1;

        delete makegd;

        }

       

        }

      };

       

       

       

       

       

       

      _root.createEmptyMovieClip('watchnCollision', -3);

      watchnCollision.onEnterFrame = function() {

        for (i=0; i<nBalls.length; i++) {

        var tempnBall = nBalls[i];

        if (tempnBall.hitTest(slider_mc.kat)) {

        count=count+1;

        //trace('we hit the cocktail');

        var dupedBall = circle.duplicateMovieClip(tempnBall, "circle"+slider_mc.getNextHighestDepth(), slider_mc.getNextHighestDepth());

        dupedBall._x = circle._x-tempnBall._x;

        dupedBall._y = circle._y-tempnBall._y;

        tempnBall.removeMovieClip();

        nBalls.splice(i, 1);

        neg=neg+1;

        if(neg==5){

        neg=0;

        }

        if(count==5)

        {

        lives=lives-1;

        count=0;

        slider_mc._x=-180

       

        }

       

        }

       

       

        if (lives == 0) {

        gotoAndPlay(2);

        

       

        }

        }

      };

       

      score = 0;

      function updateScore(amount) {

        score += amount;

        score_txt.text = 'Score is '+score;

      }

      updateScore(0);