1 Reply Latest reply on Dec 1, 2007 9:54 AM by kglad

    Tetris clone

    Anim9or
      I really wanted to figure this out on my own but i can't appararently, so i came here for help (again).
      I'm working on a new game that will be like a re-designed and formatted Tetris. However I ran into trouble about 15 minutes into it. I can't get get a new brick to appear when the last one hits the ground. Rigt now, I'm working with attachmovie, but I never really learned how to use it. So far I have this:

      stop();
      for (i=0; i<20; i++) {
      _root.attachMovie("bricks", "newbricks", 200);
      newbricks._x = 200;
      newbricks._y = 250;
      this.enterframe = function() {
      power = 6;
      radius = 10;
      };
      this.enterframe = function() {
      if (Key.isDown(Key.LEFT)) {
      _x -= power;
      }
      if (Key.isDown(Key.RIGHT)) {
      _x += power;
      }
      if (Key.isDown(Key.UP)) {
      _y -= 5;
      }
      _y += power;
      while (_root.wall.hitTest(_x, _y+radius, true)) {
      _y--;
      }
      while (_root.wall.hitTest(_x, _y-radius, true)) {
      _y++;
      }
      while (_root.wall.hitTest(_x-radius, _y, true)) {
      _x++;
      }
      while (_root.wall.hitTest(_x+radius, _y, true)) {
      _x--;
      }
      };
      }

      It's re-written from a tutorial so it probably has some unnecessary stuff in there too.
      Some things to know:
      "bricks and new bricks"- the bricks, right only one brick at a time is being used(no patterns or other things).
      wall-the border that the bricks must stay in
      This is not tile based.

      Basicall, I'm asking what do I need to do to make the "bricks" or "brick" land on the bottom, and when they do, the next brick appears at the top?

      Thanks in Advanced!
        • 1. Re: Tetris clone
          kglad Adobe Community Professional & MVP
          first, while-loops and for-loops cannot be used to display animation: they execute from beginning to end before anything is updated on stage. so, whatever you're trying to do with those while-loops isn't going to work

          2nd, put your attachMovie() code into a function that you can call whenever you want a new brick to appear. assign it whatever properties you want it to have and add it to an update list: ie, a list of objects whose _x,_y and possiblly other properties needs updating.

          3rd, use some test to determine if your bricks have hit a wall. if so, you no longer need to update their _x and/or _y properties so you can remove it from update list.

          4th, create one loop (like onEnterFrame or setInterval) that will update the objects in your update list.