0 Replies Latest reply on Jul 21, 2009 3:24 AM by codeBeastAdobe

    Whole game from freelancer: Looking for a different way of loading objects

    codeBeastAdobe Level 1

      Hi.

      I'm not sure if I'm supposed to paste all the code to this game or zip a fla etc... Please advise if I am not following procedure.

       

      A freelancer kindly wrote me a game (I paid of course). However, I don't like his code very much or rather what it does. I am able to follow most of his code BUT there are bits that evade me.

       

      Animal mcs are loaded wih attachmovie to my main scene BUT they give bad results. A cursor moves around the screen and when you hear the animal sound you must click the animals which float across the screen.

      BUT

      1. Sometimes you can't even see tha animal for 5 seconds. ie: There are 5 animals and various copies of them floating around

      2. Sometimes you get loads bunched together

       

      My idea would be to use 5 " horizontal line paths" so no animals overlap each other. ie: x at 100,  300,  500 etc...

      Also, down each path would float the animals at slightly different intervals to give random effect and a DIFFERENT animal would float down each at any given time. ie: You will always see the animal the sounds.

       

      There is a lot of code: If you want me to post the bits I think do the job just tell me. If you want the fla just tell me. Thanks

       

      Here is the code:

       

      #include "global.as"
      _root.score._visible = false;
      _root.ponepuntos = true;
      _root.puedeok = true;
      stop();
      //variables
      _root.pulsado = true;
      //Mouse.hide();
      var mouseListener:Object = new Object();
      mouseListener.onMouseMove = function() {
      _root.recoge._x = _xmouse;
      _root.recoge._y = _ymouse;
      };
      //Mouse.addListener(_root.mouseListener);
      var velo:Number = 0;
      if (_root.velo>_root.veloi) {
      } else {
      _root.velo = Number(_root.veloi);
      //trace("velocicdad="+_root.velo);
      }
      _root.conta = 0;
      _root.cont = 0;
      _root.con = 0;
      _root.ina = 0;
      vCount = 0;
      if (_root.nnivel>1) {
      } else {
      _root.nnivel = 1;
      }
      if (_root.conta>0) {
      } else {
      _root.conta = 0;
      }
      var s:Sound = new Sound();
      var s2:Sound = new Sound();
      var x_, y_;
      var num = 0;
      //-----------------
      //eleige secuencia
      function crea_array() {
      _root.camino = [];
      for (a=0; a<cont_item; a++) {
        _root.camino.push(a);
      }
      desordenarray(_root.camino);
      //trace(_root.camino);
      carga();
      }
      //------------------
      function desordenar() {
      _root.dx = [];
      for (a=1; a<5; a++) {
        donde = eval("conte"+a);
        //trace(donde._x);
        _root.dx.push(donde._x);
      }
      desordenarray(_root.dx);
      _root.nada._visible = false;
      }
      //------------------
      function inicio() {
      _root.recoge.swapDepths(_root.getNextHighestDepth());
      if (_root.ina>4) {
        _root.ina = 0;
      }
      clearInterval(_root.id);
      _root.id = setInterval(sonidos, 5000, _root.articles[_root.camino[_root.ina]].sonido);
      _root.sonidos(_root.articles[_root.camino[_root.ina]].sonido);
      _root.obj = animals[_root.ina];
      _root.ina++;
      }
      // Carga de sonidos
      function sonidos(path) {
      //s.stop()
      //trace(path);
      s.onLoad = function(success:Boolean) {
        this.start();
        this.setVolume(100);
      };
      s.onSoundComplete = function() {
        //seguir();
      };
      s.loadSound(path, false);
      }
      function sonidos2(path) {
      //s.stop()
      s2.onLoad = function(success:Boolean) {
        this.start();
        this.setVolume(100);
      };
      s2.onSoundComplete = function() {
        //seguir();
      };
      s2.loadSound(path, false);
      }
      // seguir
      _root.animals = [];
      function carga() {
      numAnimal = 0;
      x_ = 50*num;
      for (a=0; a<=cont_item-1; a++) {
        b = _root.camino[a]+1;
        carga0 = _root.articles[_root.camino[a]].imagen;
        ini = carga0.indexOf("/")+1;
        fin = carga0.indexOf(".")-ini;
        carga1 = carga0.substr(ini, fin);
        _root.animals.push(carga1);
        dept = this.getNextHighestDepth();
        //for (b=0; b<5; b++) {
        x_ = _root.randomRange(500, 1000);
        numAnimal++;
        //if(_root.velo< 3){
        // ini= 300
        // fin = 400
        //}else{
        ini = 800;
        fin = 3500;
        //}
        x_ = _root.randomRange(ini, fin);
        trace(x_);
        for (b=0; b<_root.number_animals; b++) {
         attachMovie("contenedor", carga1+numAnimal+b, dept++, {_x:_root.randomRange(ini, x_), _y:_root.randomRange(100, 475)});
         mc = eval(carga1+numAnimal+b);
         //trace(mc);
         loadMovie(_root.articles[_root.camino[a]].imagen, mc.cont);
         mc._xscale = 35;
         mc._yscale = 35;
         //}
        }
      }
      _root.marco.swapDepths(dept++);
      num++;
      //if (num<_root.number_animals) {
      //carga();
      //}
      }
      function cargab() {
      //trace("cargaBBBBB");
      clearInterval(_root.Inter);
      opc = _root.randomRange(1, 2);
      opc = 2;
      //for (a=0; a<=opc; a++) {
      _root.con++;
      attachMovie("contenedor1", "bien"+_root.con, 10, {_x:_root.randomRange(10, 500), _y:_root.randomRange(-100, -150)});
      mc = eval("bien"+_root.con);
      //trace("mc="+mc);
      loadMovie("images/bote.swf", mc.cont);
      }
      function cargac() {
      //trace("cargaccccc");
      clearInterval(_root.Inter);
      opc = _root.randomRange(1, 2);
      opc = 2;
      //for (a=0; a<=opc; a++) {
      _root.con++;
      attachMovie("contenedor2", "mal"+_root.con, this.getNextHighestDepth(), {_x:_root.randomRange(10, 500), _y:_root.randomRange(-100, -150)});
      mc = eval("mal"+_root.con);
      //trace("mc="+mc);
      loadMovie("images/bom.swf", mc.cont);
      }
      function clearFall() {
      //trace("entra en borrar");
      for (var _loc2 in this) {
        //trace(this[_loc2].cont);
        if (this[_loc2].cont != undefined) {
         trace(_loc2);
         this[_loc2].removeMovieClip(_loc2);
        }
      }
      _root.tablero.gotoAndPlay(2);
      }
      //----------- leer xml datos ---------------
      function Article(imagen, sonido) {
      this.imagen = imagen;
      this.sonido = sonido;
      }
      function makeArray1(success) {
      var i, j, mainTag, palabra;
      if (success) {
        for (i=0; i<=moXML1.childNodes.length; i++) {
         if (this.childNodes[i].nodeValue == null && this.childNodes[i].nodeName == "appear") {
          mainTag = this.childNodes[i];
         }
        }
        num_reg = mainTag.childNodes.length;
        // numero de ejercicios
        for (i=0; i<=mainTag.childNodes.length; i++) {
         if (mainTag.childNodes[i].nodeName == "T_Item") {
          articleTag = mainTag.childNodes[i];
          for (j=0; j<articleTag.childNodes.length; j++) {
           if (articleTag.childNodes[j].nodeName != null) {
            if (articleTag.childNodes[j].nodeName == "imagen") {
             imagen = articleTag.childNodes[j].firstChild.nodeValue;
            }
            if (articleTag.childNodes[j].nodeName == "sonido") {
             sonido = articleTag.childNodes[j].firstChild.nodeValue;
            }
           }
          }
          thisArticle = new Article(imagen, sonido);
          cont_item = articles.push(thisArticle);
          delete thisArticle;
         }
        }
      }
      }
      //*********************************
      var articles = [];
      moXML1 = new XML();
      moXML1.ignoreWhite = true;
      moXML1.onLoad = makeArray1;
      moXML1.load("data/animal_catch.xml");
      // ------ leer configuracion -----
      function makeArray(success) {
      var i, j, mainTag, palabra;
      if (success) {
        for (i=0; i<=moXML.childNodes.length; i++) {
         if (this.childNodes[i].nodeValue == null && this.childNodes[i].nodeName == "config") {
          mainTag = this.childNodes[i];
         }
        }
        num_reg = mainTag.childNodes.length;
        // numero de ejercicios
        for (i=0; i<=mainTag.childNodes.length; i++) {
         if (mainTag.childNodes[i].nodeName == "T_Item") {
          articleTag = mainTag.childNodes[i];
          for (j=0; j<articleTag.childNodes.length; j++) {
           if (articleTag.childNodes[j].nodeName != null) {
            if (articleTag.childNodes[j].nodeName == "time_game") {
             _root.time_game = articleTag.childNodes[j].firstChild.nodeValue;
            }
            if (articleTag.childNodes[j].nodeName == "number_animals") {
             _root.number_animals = articleTag.childNodes[j].firstChild.nodeValue;
            }
            if (articleTag.childNodes[j].nodeName == "speed") {
             var velo1:Number = articleTag.childNodes[j].firstChild.nodeValue;
            }
            if (articleTag.childNodes[j].nodeName == "speed_ball") {
             _root.speed_ball = Number(articleTag.childNodes[j].firstChild.nodeValue);
            }
            if (articleTag.childNodes[j].nodeName == "more_speed") {
             _root.masvelo = Number(articleTag.childNodes[j].firstChild.nodeValue);
            }
            if (articleTag.childNodes[j].nodeName == "score") {
             _root.pon_score = articleTag.childNodes[j].firstChild.nodeValue;
             trace(_root.pon_score);
             _root.masvelo;
            }
           }
          }
         }
        }
        crea_array();
        a = 0;
        _root.velo = Number(velo1);
        _root.velo_i = Number(velo1);
        _root.mcTimer.startTimer(_root.time_game, _root, "onEndTimer");
        _root.inicio();
        //Mouse.addListener(_root.mouseListener);
      }
      }
      var articles = [];
      moXML = new XML();
      moXML.ignoreWhite = true;
      moXML.onLoad = makeArray;
      moXML.load("data/config_catch.xml");
      // ----------  fin leer configuracion -------
      //cookie
      function order(b, a):Number {
      var name1 = (a.split(":")[0])*1;
      var name2 = (b.split(":")[0])*1;
      if (name1<name2) {
        return -1;
      } else if (name1>name2) {
        return 1;
      } else {
        return 0;
      }
      }
      var datos = new Array();
      function poner_datos() {
      nombre = _root.score.name.text;
      punto = _root.puntos;
      dat = punto+":"+nombre;
      //thisArti = {puntos:puntos, nombre:nombre};
      if (datos.length<10) {
        datos[datos.length] = dat;
        datos.sort(order);
      } else {
        datos[datos.length] = dat;
        var temp:Array = [];
        datos.sort(order);
        for (a=0; a<10; a++) {
         temp[a] = datos[a];
        }
        datos = [];
        datos = temp;
      }
      carga_score(datos);
      escribe();
      }
      var mySharedObject = SharedObject.getLocal("score");
      leer_cookie();
      //poner_datos();
      // Escribir -----------
      function escribe() {
      mySharedObject.data.valor = datos;
      var status = mySharedObject.flush();
      }
      function carga_score(dat) {
      _root.score.puntos.text = "";
      _root.score.nombre.text = "";
      num = [];
      _root.total = dat.length;
      trace("total="+_root.total);
      for (a=0; a<dat.length; a++) {
        var tem = dat[a].split(":");
        num.push(tem[0]);
        num.push(tem[1]);
      }
      for (a=0; a<num.length; a++) {
        _root.score.puntos.text = _root.score.puntos.text+num[a]+chr(13);
        a++;
      }
      _root.menor = num[a-2];
      if (_root.menor == undefined) {
        _root.menor = 0;
      }
      trace("mayor="+_root.menor);
      for (a=1; a<num.length; a++) {
        _root.score.nombre.text = _root.score.nombre.text+num[a]+chr(13);
        a++;
      }
      }
      // leer configuración
      function leer_cookie() {
      _global.cookie = true;
      if (mySharedObject.data.valor) {
        datos = mySharedObject.data.valor;
        datos.sort(order);
        carga_score(datos);
      } else {
        datos = [];
        /*for (a=0; a<10; a++) {
        datos[a] = "";
        }*/
        _root.menor = 0;
        mySharedObject.data.valor = datos;
        var status = mySharedObject.flush();
      }
      //poner_datos()
      }