home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / climatechaos.swf / scripts / __Packages / Environment.as < prev    next >
Encoding:
Text File  |  2008-09-12  |  16.4 KB  |  470 lines

  1. class Environment extends MovieClip
  2. {
  3.    var music;
  4.    var start;
  5.    var hit_center;
  6.    var inside;
  7.    var pos_x;
  8.    var pos_y;
  9.    var strips;
  10.    var objects;
  11.    var ground_bms;
  12.    var camera_offset;
  13.    var camera_depth;
  14.    var map_bm;
  15.    var weather;
  16.    var last_env;
  17.    var environment_map;
  18.    var clickable;
  19.    var distanceTo;
  20.    var environment;
  21.    var radius;
  22.    var pickup;
  23.    var useItemFunc;
  24.    var showPhotoFunc;
  25.    var level_list;
  26.    var low_x;
  27.    var high_x;
  28.    var low_y;
  29.    var high_y;
  30.    var control;
  31.    function Environment(p_camera_offset, p_camera_depth)
  32.    {
  33.       super();
  34.       this.music = new Sound();
  35.       this.music.onSoundComplete = function()
  36.       {
  37.          this.start();
  38.       };
  39.       this.music.setVolume(40);
  40.       this.hit_center = null;
  41.       this.inside = false;
  42.       this.pos_x = 0;
  43.       this.pos_y = 0;
  44.       this.strips = [];
  45.       this.objects = [];
  46.       this.ground_bms = [];
  47.       this.camera_offset = p_camera_offset;
  48.       this.camera_depth = p_camera_depth;
  49.       var _loc6_ = 3.3;
  50.       var _loc7_ = 0;
  51.       _root.attachMovie("grounds","tg",2);
  52.       this.map_bm = new flash.display.BitmapData(_root.tg._width,_root.tg._height,true,16777215);
  53.       this.map_bm.draw(_root.tg);
  54.       _root.tg.removeMovieClip();
  55.       var _loc8_ = 10;
  56.       var _loc5_ = 0;
  57.       while(_loc5_ < 70)
  58.       {
  59.          var _loc4_ = _root.createEmptyMovieClip("strip" + _loc5_,_loc8_ = _loc8_ + 1);
  60.          this.strips[this.strips.length] = _loc4_;
  61.          _loc4_.attachMovie("m_strip","mask_strip",2);
  62.          _loc4_.createEmptyMovieClip("texture_hold",3);
  63.          _loc4_.texture_hold.createEmptyMovieClip("texture_hold2",2);
  64.          _loc4_.texture_hold.texture_hold2.createEmptyMovieClip("texture",2);
  65.          _loc4_.texture_hold.setMask(_loc4_.mask_strip);
  66.          _loc4_._x = 275;
  67.          _loc4_._y = 300 - _loc7_;
  68.          _loc4_.mask_strip._height = _loc6_ + 0.28;
  69.          _loc4_.z_scale = (_loc4_._y - _loc6_ / 2 - 100) / this.camera_offset;
  70.          _loc4_.z = this.camera_depth / _loc4_.z_scale - this.camera_depth;
  71.          _loc4_.texture_hold._yscale = 100 * _loc4_.z_scale;
  72.          _loc4_.texture_hold._xscale = 100 * _loc4_.z_scale;
  73.          _loc4_.texture_hold.texture_hold2._y = _loc4_.z;
  74.          _loc6_ *= 0.991;
  75.          _loc7_ += _loc6_;
  76.          _loc5_ = _loc5_ + 1;
  77.       }
  78.       this.weather = _root.attachMovie("weather","weather",999997);
  79.    }
  80.    function setEnvironmentMap(env_map)
  81.    {
  82.       var _loc7_ = env_map;
  83.       if((env_map == "hotel" || env_map == "hotel_sun") && Story.sun)
  84.       {
  85.          this.music.stop();
  86.          this.music.attachSound("sun");
  87.          this.music.setVolume(40);
  88.          this.music.start();
  89.          _loc7_ = "hotel_sun";
  90.       }
  91.       else if((env_map == "spring" || env_map == "spring_thunder") && Story.thunder)
  92.       {
  93.          this.music.stop();
  94.          this.music.attachSound("thunder");
  95.          this.music.setVolume(40);
  96.          this.music.start();
  97.          _loc7_ = "spring_thunder";
  98.       }
  99.       else if((env_map == "shrine" || env_map == "shrine_snow") && Story.snow)
  100.       {
  101.          this.music.stop();
  102.          this.music.attachSound("snow");
  103.          this.music.setVolume(40);
  104.          this.music.start();
  105.          _loc7_ = "shrine_snow";
  106.       }
  107.       else if((env_map == "tribal" || env_map == "tribal_rain") && Story.rain)
  108.       {
  109.          this.music.stop();
  110.          this.music.attachSound("rain");
  111.          this.music.setVolume(40);
  112.          this.music.start();
  113.          _loc7_ = "tribal_rain";
  114.       }
  115.       else if(env_map == "tunnel")
  116.       {
  117.          this.music.stop();
  118.       }
  119.       else
  120.       {
  121.          this.music.stop();
  122.          this.music.attachSound("main_loop");
  123.          this.music.setVolume(40);
  124.          this.music.start();
  125.       }
  126.       var _loc3_ = Story[_loc7_];
  127.       this.last_env = _loc7_;
  128.       this.environment_map = _loc3_;
  129.       _root.attachMovie("grounds","tg",_root.getNextHighestDepth()).gotoAndStop(_loc3_.ground);
  130.       if(_loc3_.ground == 2 || _loc3_.ground == 6)
  131.       {
  132.          if(!Story.drained)
  133.          {
  134.             _root.tg.map.pond._visible = false;
  135.          }
  136.          if(!Story.dug_up)
  137.          {
  138.             _root.tg.map.hole._visible = false;
  139.          }
  140.       }
  141.       this.map_bm = new flash.display.BitmapData(_root.tg._width,_root.tg._height,true,16777215);
  142.       this.map_bm.draw(_root.tg);
  143.       _root.tg.removeMovieClip();
  144.       var _loc8_ = 0;
  145.       while(_loc8_ < 70)
  146.       {
  147.          this.strips[_loc8_].texture_hold.texture_hold2.texture.attachBitmap(this.map_bm,2,"auto",true);
  148.          _loc8_ = _loc8_ + 1;
  149.       }
  150.       for(_loc8_ in this.objects)
  151.       {
  152.          _root.createEmptyMovieClip("deleter",this.objects[_loc8_].getDepth());
  153.          this.objects[_loc8_].removeMovieClip();
  154.       }
  155.       _root.bg.gotoAndStop(_loc3_.weather_num);
  156.       this.weather.gotoAndStop(_loc3_.weather_num);
  157.       _root.deleter.removeMovieClip();
  158.       this.setLimits(_loc3_.low_x,_loc3_.high_x,_loc3_.low_y,_loc3_.high_y);
  159.       this.objects = [];
  160.       this.clickable = [];
  161.       var _loc5_ = 100;
  162.       for(_loc8_ in _loc3_.objects)
  163.       {
  164.          _loc5_;
  165.          _root.attachMovie(_loc3_.objects[_loc8_].clip,_loc3_.objects[_loc8_].clip + this.objects.length,_loc5_++);
  166.          _root[_loc3_.objects[_loc8_].clip + this.objects.length].photo_name = _loc3_.objects[_loc8_].photo;
  167.          _root[_loc3_.objects[_loc8_].clip + this.objects.length].pos_x = _loc3_.objects[_loc8_].x;
  168.          _root[_loc3_.objects[_loc8_].clip + this.objects.length].pos_y = _loc3_.objects[_loc8_].y;
  169.          _root[_loc3_.objects[_loc8_].clip + this.objects.length].radius = _loc3_.objects[_loc8_].radius;
  170.          _root[_loc3_.objects[_loc8_].clip + this.objects.length].pickup = this.environment_map.objects[_loc8_].pickup;
  171.          _root[_loc3_.objects[_loc8_].clip + this.objects.length].movable = _loc3_.objects[_loc8_].movable;
  172.          if(_loc3_.objects[_loc8_].pickup != undefined)
  173.          {
  174.             _root[_loc3_.objects[_loc8_].clip + this.objects.length].onRelease = function()
  175.             {
  176.                if(this.distanceTo(this.environment.pos_x,this.environment.pos_y) < 40 + this.radius)
  177.                {
  178.                   this.pickup(this);
  179.                }
  180.             };
  181.             if(_root[_loc3_.objects[_loc8_].clip + this.objects.length].photo_name == "a rowing boat")
  182.             {
  183.                _root[_loc3_.objects[_loc8_].clip + this.objects.length].onRollOver = function()
  184.                {
  185.                   _root.hud.setText("A Rowing Boat");
  186.                };
  187.                _root[_loc3_.objects[_loc8_].clip + this.objects.length].onRollOut = function()
  188.                {
  189.                   _root.hud.setText("");
  190.                };
  191.             }
  192.          }
  193.          if(_root[_loc3_.objects[_loc8_].clip + this.objects.length].onRelease != undefined)
  194.          {
  195.             this.clickable[this.clickable.length] = _root[_loc3_.objects[_loc8_].clip + this.objects.length];
  196.          }
  197.          if(_root[_loc3_.objects[_loc8_].clip + this.objects.length].photo_name == "a bucket and spade")
  198.          {
  199.             Story.bucket_link = _root[_loc3_.objects[_loc8_].clip + this.objects.length];
  200.          }
  201.          if(_root[_loc3_.objects[_loc8_].clip + this.objects.length].photo_name == "a very large sea shell")
  202.          {
  203.             if(Story.snow)
  204.             {
  205.                _root[_loc3_.objects[_loc8_].clip + this.objects.length].gotoAndStop(2);
  206.             }
  207.             else
  208.             {
  209.                _root[_loc3_.objects[_loc8_].clip + this.objects.length].gotoAndStop(1);
  210.             }
  211.          }
  212.          this.objects[this.objects.length] = _root[_loc3_.objects[_loc8_].clip + this.objects.length];
  213.       }
  214.       for(_loc8_ in _loc3_.buildings)
  215.       {
  216.          _loc5_;
  217.          _root.attachMovie(_loc3_.buildings[_loc8_].clip,_loc3_.buildings[_loc8_].clip + this.objects.length,_loc5_++);
  218.          _root[_loc3_.buildings[_loc8_].clip + this.objects.length].photo_name = _loc3_.buildings[_loc8_].photo;
  219.          _root[_loc3_.buildings[_loc8_].clip + this.objects.length].pos_x = _loc3_.buildings[_loc8_].x;
  220.          _root[_loc3_.buildings[_loc8_].clip + this.objects.length].pos_y = _loc3_.buildings[_loc8_].y;
  221.          _root[_loc3_.buildings[_loc8_].clip + this.objects.length].room = _loc3_.buildings[_loc8_].room;
  222.          if(_root[_loc3_.buildings[_loc8_].clip + this.objects.length].photo_name == "chief_hut")
  223.          {
  224.             Story.chief_hut = _root[_loc3_.buildings[_loc8_].clip + this.objects.length];
  225.          }
  226.          this.objects[this.objects.length] = _root[_loc3_.buildings[_loc8_].clip + this.objects.length];
  227.       }
  228.       for(_loc8_ in _loc3_.people)
  229.       {
  230.          _loc5_;
  231.          _root.attachMovie(_loc3_.people[_loc8_].clip,_loc3_.people[_loc8_].clip + this.objects.length,_loc5_++);
  232.          _root[_loc3_.people[_loc8_].clip + this.objects.length].photo_name = _loc3_.people[_loc8_].photo;
  233.          _root[_loc3_.people[_loc8_].clip + this.objects.length].pos_x = _loc3_.people[_loc8_].x;
  234.          _root[_loc3_.people[_loc8_].clip + this.objects.length].pos_y = _loc3_.people[_loc8_].y;
  235.          _root[_loc3_.people[_loc8_].clip + this.objects.length].description = _loc3_.people[_loc8_].descript;
  236.          _root[_loc3_.people[_loc8_].clip + this.objects.length].setSpeech(_loc3_.people[_loc8_].speech);
  237.          if(_loc3_.people[_loc8_].use_item != undefined)
  238.          {
  239.             _root[_loc3_.people[_loc8_].clip + this.objects.length].useItemFunc = _loc3_.people[_loc8_].use_item;
  240.             _root[_loc3_.people[_loc8_].clip + this.objects.length].useItem = function(args)
  241.             {
  242.                this.useItemFunc(this,args);
  243.             };
  244.             _root.hud.addListener(_root[_loc3_.people[_loc8_].clip + this.objects.length]);
  245.          }
  246.          if(_loc3_.people[_loc8_].show_photo != undefined)
  247.          {
  248.             _root[_loc3_.people[_loc8_].clip + this.objects.length].showPhotoFunc = _loc3_.people[_loc8_].show_photo;
  249.             _root[_loc3_.people[_loc8_].clip + this.objects.length].showPhoto = function(args)
  250.             {
  251.                this.showPhotoFunc(this,args);
  252.             };
  253.             _root.hud.addListener(_root[_loc3_.people[_loc8_].clip + this.objects.length]);
  254.          }
  255.          this.clickable[this.clickable.length] = _root[_loc3_.people[_loc8_].clip + this.objects.length];
  256.          this.objects[this.objects.length] = _root[_loc3_.people[_loc8_].clip + this.objects.length];
  257.       }
  258.       this.level_list = {};
  259.       for(_loc8_ in this.objects)
  260.       {
  261.          var _loc4_ = this.objects[_loc8_].pos_y;
  262.          while(!this.checkDepthList(_loc4_))
  263.          {
  264.             _loc4_ = _loc4_ + 1;
  265.          }
  266.          this.level_list[this.objects[_loc8_]._name] = _loc4_;
  267.       }
  268.    }
  269.    function checkDepthList(p_d)
  270.    {
  271.       var _loc2_ = true;
  272.       for(var _loc4_ in this.level_list)
  273.       {
  274.          if(this.level_list[_loc4_] == p_d)
  275.          {
  276.             _loc2_ = false;
  277.          }
  278.       }
  279.       return _loc2_;
  280.    }
  281.    function setLimits(p_lx, p_hx, p_ly, p_hy)
  282.    {
  283.       this.low_x = p_lx;
  284.       this.high_x = p_hx;
  285.       this.low_y = p_ly;
  286.       this.high_y = p_hy;
  287.    }
  288.    function setControl(p_control)
  289.    {
  290.       this.control = p_control;
  291.    }
  292.    function stopToTalk()
  293.    {
  294.       this.control.stopToTalk();
  295.       for(var _loc2_ in this.clickable)
  296.       {
  297.          this.clickable[_loc2_].enabled = false;
  298.       }
  299.    }
  300.    function stopTalking()
  301.    {
  302.       this.control.stopTalking();
  303.       if(!this.control.photoing)
  304.       {
  305.          for(var _loc2_ in this.clickable)
  306.          {
  307.             this.clickable[_loc2_].enabled = true;
  308.          }
  309.       }
  310.    }
  311.    function stopToPhoto()
  312.    {
  313.       this.control.stopToPhoto();
  314.       for(var _loc2_ in this.clickable)
  315.       {
  316.          this.clickable[_loc2_].enabled = false;
  317.       }
  318.    }
  319.    function stopPhotoing()
  320.    {
  321.       this.control.stopPhotoing();
  322.       if(!this.control.talking)
  323.       {
  324.          for(var _loc2_ in this.clickable)
  325.          {
  326.             this.clickable[_loc2_].enabled = true;
  327.          }
  328.       }
  329.    }
  330.    function goInside(p_building, p_room)
  331.    {
  332.       this.inside = true;
  333.       for(var _loc3_ in this.clickable)
  334.       {
  335.          this.clickable[_loc3_].enabled = false;
  336.       }
  337.       this.control.stopToTalk();
  338.       if(!Story.umbrella)
  339.       {
  340.          _root.attachMovie("cutscene","cutscene",1000006);
  341.          _root.cutscene.frame = 1;
  342.          _root.cutscene.env = this;
  343.          _root.cutscene.building = p_building;
  344.       }
  345.       else
  346.       {
  347.          _root.attachMovie("building_inside","building_inside",999998);
  348.          _root.building_inside.frame = p_room;
  349.          _root.building_inside.env = this;
  350.       }
  351.       this.render();
  352.       this.hit_center = _root.building_inside;
  353.    }
  354.    function goOutside()
  355.    {
  356.       this.inside = false;
  357.       this.control.stopTalking();
  358.       this.control.stopPhotoing();
  359.       for(var _loc2_ in this.clickable)
  360.       {
  361.          this.clickable[_loc2_].enabled = true;
  362.       }
  363.       this.control.angle = 1;
  364.       this.control.old_angle = 1;
  365.       this.control.character.gotoAndStop(1);
  366.       this.control.character.body.gotoAndStop(1);
  367.       this.pos_y += 20;
  368.    }
  369.    function moveBy(p_x, p_y)
  370.    {
  371.       var _loc4_ = this.pos_x - p_x;
  372.       var _loc3_ = this.pos_y - p_y;
  373.       if(_loc4_ > this.high_x)
  374.       {
  375.          _loc4_ = this.high_x;
  376.       }
  377.       else if(_loc4_ < this.low_x)
  378.       {
  379.          _loc4_ = this.low_x;
  380.       }
  381.       if(_loc3_ > this.high_y)
  382.       {
  383.          _loc3_ = this.high_y;
  384.       }
  385.       else if(_loc3_ < this.low_y)
  386.       {
  387.          _loc3_ = this.low_y;
  388.       }
  389.       for(var _loc5_ in this.objects)
  390.       {
  391.          if(this.objects[_loc5_].distanceTo(this.pos_x,this.pos_y) < this.objects[_loc5_].radius + 150)
  392.          {
  393.             var _loc2_ = this.objects[_loc5_].collide(_loc4_,_loc3_,this.pos_x,this.pos_y);
  394.             _loc4_ = _loc2_[0];
  395.             _loc3_ = _loc2_[1];
  396.          }
  397.       }
  398.       this.pos_x = _loc4_;
  399.       this.pos_y = _loc3_;
  400.       this.render();
  401.    }
  402.    function render()
  403.    {
  404.       var _loc3_ = 0;
  405.       while(_loc3_ < 70)
  406.       {
  407.          this.strips[_loc3_].texture_hold.texture_hold2.texture._x = - this.pos_x;
  408.          this.strips[_loc3_].texture_hold.texture_hold2.texture._y = - this.pos_y;
  409.          _loc3_ = _loc3_ + 1;
  410.       }
  411.       this.hit_center = _root;
  412.       for(_loc3_ in this.objects)
  413.       {
  414.          this.objects[_loc3_].render(this);
  415.          if(this.objects[_loc3_]._visible && this.objects[_loc3_].hitTest(275,176,false) && this.objects[_loc3_].getDepth() > this.hit_center.getDepth())
  416.          {
  417.             this.hit_center = this.objects[_loc3_];
  418.          }
  419.       }
  420.       if(this.last_env == "spring" && !Story.drained && this.pos_y < 850)
  421.       {
  422.          Story.drain();
  423.       }
  424.       if(this.last_env == "tunnel" && this.pos_y < 290)
  425.       {
  426.          Story.leaveTunnel();
  427.       }
  428.       if(this.last_env == "shrine" || this.last_env == "shrine_snow")
  429.       {
  430.          if(this.pos_x > 1400 && this.pos_x < 1430 && this.pos_y > 715 && this.pos_y < 745 && !Story.trapped)
  431.          {
  432.             Story.getTrapped();
  433.          }
  434.          if(this.pos_x > 1440 && this.pos_x < 1480 && this.pos_y > 1220 && this.pos_y < 1250)
  435.          {
  436.             Story.useTunnel(1);
  437.          }
  438.       }
  439.       var _loc4_ = this.environment_map.height_map.getPixel(this.pos_x / 2,(300 + this.pos_y) / 2);
  440.       if(_loc4_ > 500000)
  441.       {
  442.          _root.blue._y = 280 + 30 * (_loc4_ - 500000) / 15205381;
  443.          _root.blue.view._y = -212 - (_root.blue._y - 280) * 100 / 51.2;
  444.          if(Story.drained && this.pos_x > 1300 && this.pos_x < 1600 && this.pos_y > 500 && this.pos_y < 710)
  445.          {
  446.             if(this.pos_x > 1420 && this.pos_x < 1455 && this.pos_y > 615 && this.pos_y < 640)
  447.             {
  448.                Story.useTunnel(0);
  449.             }
  450.          }
  451.          else
  452.          {
  453.             _root.splash._visible = true;
  454.             _root.splash.play();
  455.             _root.blue.setMask(_root.mask);
  456.             _root.blue.shadow._visible = false;
  457.          }
  458.       }
  459.       else
  460.       {
  461.          _root.blue.view._y = -212 - (_root.blue._y - 280) * 100 / 51.2;
  462.          _root.blue.shadow._visible = true;
  463.          _root.blue.setMask(null);
  464.          _root.blue._y = 280;
  465.          _root.splash._visible = false;
  466.          _root.splash.stop();
  467.       }
  468.    }
  469. }
  470.