3 Replies Latest reply on Jun 5, 2011 11:12 AM by kglad

    Help on TD as2 code

    LukeElChul Level 1

      im building a tower defence game this is one of my codes

       

      ive got 7 towers how could i make it so 1 tower could only be placed on a movieClip called water and not on the movieClip grass

       

       

       

       

       

       

      onClipEvent (load)
      {
      active = 0;
      }

      onClipEvent (enterFrame)
      {
      if (active == 1)
      {
      setProperty("", _x, int((_root._xmouse - 10) / 20) * 20 + 20);
      setProperty("", _y, int((_root._ymouse - 10) / 20) * 20 + 20);

      hitTestOnGrassMovieClip = _root.grass.hitTest(_x, _y, 1);

      if (hitTestOnGrassMovieClip) {
      gotoAndStop(1);
      _root.ranger.gotoAndStop(1);
      }
      else {
      gotoAndStop(2);
      _root.ranger.gotoAndStop(2);
      }

      _root.ranger._x = _x;
      _root.ranger._y = _y;
      _root.ranger._width = _root["tower_" + tower].range * 2;
      _root.ranger._height = _root["tower_" + tower].range * 2;
      }
      }


      on (press)
      {
      hitTestOnGrassMovieClip = _root.grass.hitTest(_x, _y, 1);
      hitTestOnDeSelectMovieClip = _root.deselect.hitTest(_x, _y, 1);

      if (hitTestOnGrassMovieClip || hitTestOnDeSelectMovieClip) {
      if (hitTestOnGrassMovieClip && (!_root.hasGameFinished) ) {
      ++_root.towerCount;
      _root["tower_" + tower].duplicateMovieClip("t" + _root.towerCount, 500 + _root.towerCount);
      a = _root["t" + _root.towerCount];
      a._x = _x;
      a._y = _y;
      a.active = 1;
      a.cost = cost;
      _root.gold = _root.gold - cost;
      _root.updateInfoBar();

      // If this is the first tower being placed
      // start the game...
      if (!_root.hasGameStarted) {
      _root.newLevel();
      _root.hasGameStarted = true;
      _root.instructions._visible = false;
      }  

      }

      active = 0;
      setProperty("", _x, 1000);
      _root.selectedTower = "";
      _root.ranger._x = 1000;
      _root.ranger._width = 10;
      _root.ranger._height = 10; 
      }
      }