0 Replies Latest reply on Aug 30, 2007 3:23 AM by kirbycorps

    Help with Actionscript Memory Flash Game

    kirbycorps
      Hi there,

      I am new here and I recently designed a simple Memory pairs game, the problem I have is that when you click too fast on the cards they simply get stuck or rotate three cards at a time.

      I was wondering if anyone can help me!!

      Ill paste code here:

      // Gamefield settings

      // EDIT HERE
      card_w = 90;
      card_h = 110;
      card_wdistance = 10;
      card_hdistance = 10;

      // STOP EDIT
      card_dw = card_w + card_wdistance;
      card_dh = card_h + card_hdistance;
      row_card = Math.floor((Stage.width - card_wdistance) / card_dw);
      col_card = Math.floor((Stage.height - card_hdistance) / card_dh);
      n_card = col_card * row_card % 2 == 0 ? col_card * row_card : (col_card - 1) * row_card;
      imgs_n = n_card / 2;

      // CENTER THE IMAGE IN THE CARD
      centerImage = function(target){
      target.front._visible = false
      target.front.container._x -= target.front.container._width / 2
      target.front.container._y -= target.front.container._height / 2
      }
      // ---------------------------------------------

      empty = new Array();
      function createCard(n, w, h) {
      empty.push(n);
      this.createEmptyMovieClip('card' + n, n);
      with (this['card' + n]) {
      lineStyle(0, 0x000000, 100);
      beginFill(0x000099, 60);
      moveTo(w / 2, 0);
      lineTo(w / 2, h / 2);
      lineTo(-w / 2, h / 2);
      lineTo(-w / 2, -h / 2);
      lineTo(w / 2, -h / 2);
      lineTo(w / 2, 0);
      endFill();
      createEmptyMovieClip('front', 1);
      front.createEmptyMovieClip('container', 2);
      front.createEmptyMovieClip('backgr', 1);
      with (front.backgr) {
      moveTo(-w / 2, -h / 2);
      lineStyle(0, 0x000000, 0);
      beginFill(0x333333, 100);
      lineTo(w / 2, -h / 2);
      lineTo(w / 2, h / 2);
      lineTo(-w / 2, h / 2);
      lineTo(-w / 2, -h / 2);
      endFill();
      }
      front.onEnterFrame = function() {
      tot = this.container.getBytesTotal();
      car = this.container.getBytesLoaded();
      if (tot == car && tot > 200) {
      this._parent._parent.centerImage(this._parent);
      delete this.onEnterFrame;
      }
      };
      }
      }
      selcards = [];
      function placeImages() {
      act_img = 0;
      for (img = 0; img < imgs_n; img++) {
      for (k = 0; k < 2; k++) {
      act = Math.round(Math.random() * (empty.length - 1));
      this['card' + empty[act]].img_id = act_img;
      this['card' + empty[act]].front.container.loadMovie("imgs/img" + act_img + ".jpg");
      this['card' + empty[act]].onRelease = function() {
      this.rotateCard(0, 0);
      this.enabled = false;
      MovieClip.prototype.enabled = false;
      };
      empty.splice(act, 1);
      }
      act_img++;
      }
      }
      MovieClip.prototype.rotateCard = function(v, i) {

      this.operazione = v == 0 ? +0.1 : -0.1;
      this.incremento = i == 0 ? 100 : 10;
      selcards.push(this._name);
      this.onEnterFrame = function() {
      this.incremento += this.operazione;
      this._xscale = (100 * Math.sin(this.incremento));
      if (this._xscale > 0) {
      this.front._visible = v == 1 ? false : true;
      }
      if (this._xscale >= 99) {
      delete this.onEnterFrame;
      selcards.length < 2 ? MovieClip.prototype.enabled = true : null;
      v == 0 && selcards.length > 1 ? checkCards() : null;
      }
      };
      };
      function generateGameField(cards, distance, hdistance) {
      Ypos = card_h / 2 + hdistance;
      Xpos = card_w / 2 + distance;
      for (c = 0; c < cards; c++) {
      createCard(c, card_w, card_h);
      if (c % row_card == 0 && c > 0) {
      Ypos += this['card' + c]._height + hdistance;
      Xpos = card_w / 2 + distance;
      }
      this['card' + c]._x = Xpos;
      this['card' + c]._y = Ypos;
      Xpos += this['card' + c]._width + distance;
      }
      placeImages();
      }
      generateGameField(n_card, card_wdistance, card_hdistance);

      score = 0;
      this.createTextField('punti', -1, 600, 485, 0, 0);
      punti.autoSize = true;
      punti.text = 0;
      function checkCards() {
      if (this[selcards[0]].img_id == this[selcards[1]].img_id) {
      score++;
      punti.text = score;
      eval(selcards[0])._visible = eval(selcards[1])._visible = false;
      } else {
      eval(selcards[0]).rotateCard(1, 1);
      eval(selcards[1]).rotateCard(1, 1);
      eval(selcards[0]).enabled = eval(selcards[1]).enabled = true;
      }
      selcards = [];
      MovieClip.prototype.enabled = true;
      }



      Any help is welcomed many thanks :)

      Also, if you want to see the fla file please ask and I try and figure out how to send it to you! Thanks :)