Guest User

Untitled

a guest
May 22nd, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.         import flash.display.Bitmap;
  4.         import flash.display.BitmapData;
  5.         import flash.geom.Rectangle;
  6.         import net.flashpunk.Entity;
  7.         import net.flashpunk.FP;
  8.         import flash.geom.Point;
  9.         import flash.filters.DisplacementMapFilter;
  10.         import flash.filters.DropShadowFilter;
  11.         import net.flashpunk.graphics.Canvas;
  12.         import net.flashpunk.utils.Draw;
  13.         import flash.display.BlendMode;
  14.         /**
  15.          * ...
  16.          * @author Todd Luke
  17.          */
  18.         public class Water extends Entity
  19.         {
  20.                
  21.                 // Perlin noise variables, I encourage you to play around with these...
  22.                 public var baseX              :Number = 32;
  23.                 public var baseY              :Number = 32;    
  24.                 public var nOctaves           :Number = 1;
  25.                 public var randomSeed         :Number = Math.random()*10;
  26.                 public var bStitch         :Boolean = true;
  27.                 public var bFractalNoise      :Boolean = true;
  28.                 public var nChannels          :Number = 1;
  29.                 public var bGreyScale      :Boolean= false;
  30.                 // Offset array for perlin function
  31.                 public var p1:Point = new Point(450, 340);
  32.                 public var p2:Point = new Point(500, 600);
  33.                 public var perlinOffset:Array = new Array(p1, p2);
  34.                 // Create the bitmapdata we are going to change with the perinNoise function        
  35.                 public var bmp:BitmapData = new BitmapData(320,240,true,0x00000000);
  36.                 private var caRoom:Canvas = new Canvas( FP.width, FP.height);
  37.                 public var _rect:Rectangle = new Rectangle(0, 0, FP.width, FP.height);
  38.                 public function Water()
  39.                 {
  40.                     trace("water created");
  41.                     layer = -2;
  42.                 }
  43.                
  44.                 override public function render():void
  45.                 {
  46.                    
  47.                     super.render();
  48.                    
  49.                    
  50.                      //    change the values in the perlinOffset to animate each perlin layer
  51.                      bmp.copyPixels(FP.buffer, _rect, _rect.topLeft);
  52.                     perlinOffset[0].y-=1;
  53.                     perlinOffset[0].x-=1;
  54.                     perlinOffset[1].x+=1;
  55.                     perlinOffset[1].y+=1;
  56.                     //    apply perlin noise to our bitmapdata
  57.                     bmp.perlinNoise(baseX, baseY, nOctaves, randomSeed, bStitch, bFractalNoise, nChannels, bGreyScale, perlinOffset);
  58.                     //
  59.                     //    Uncomment the following line to see the generated perlin noise
  60.                     //_root.attachBitmap(bmp, 1, "auto", true);
  61.                     //
  62.                     //    Now use the bitmapdata in bmp as a base for the distortion
  63.                     var dmf:DisplacementMapFilter = new DisplacementMapFilter(bmp, new Point(0, 0), 1, 1, 20, 20, "color");
  64.                     //    and apply it to our pic (instance name sourcePic)
  65.                     bmp.applyFilter(FP.buffer, _rect, _rect.topLeft, dmf);
  66.                    
  67.                     caRoom.fillTexture(_rect, bmp);     //render the blurred background to the canvas.
  68.                     caRoom.blend = BlendMode.HARDLIGHT;
  69.                     caRoom.alpha=.3
  70.                     Draw.graphic(caRoom, FP.camera.x, FP.camera.y);
  71.                 }
  72.                
  73.         }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment