Advertisement
Guest User

Particle2D

a guest
Dec 3rd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.79 KB | None | 0 0
  1. package scripts;
  2.  
  3. /**
  4.  * ...
  5.  * @author SadiQ
  6.  */
  7.  
  8. import com.stencyl.Engine;
  9. import com.stencyl.graphics.BitmapWrapper;
  10. import com.stencyl.utils.Utils;
  11. import openfl.display.Bitmap;
  12. import openfl.display.BitmapData;
  13. import openfl.display.Shape;
  14. import openfl.filters.BitmapFilter;
  15. import openfl.filters.BlurFilter;
  16. import openfl.geom.Matrix;
  17. import openfl.geom.Point;
  18. import scripts.Particle2D;
  19. import com.stencyl.graphics.G;
  20. import com.stencyl.behavior.Script;
  21. import com.stencyl.behavior.Script.*;
  22.  
  23. class Particle2D
  24. {
  25.     public var x:Float;
  26.     public var y:Float;
  27.     public var vx:Float;
  28.     public var vy:Float;
  29.     public var color:Int;
  30.     public var radius:Int;
  31.     public var alpha:Float;
  32.    
  33.     var bd:BitmapData;
  34.     var shape:Shape;
  35.     var bw:BitmapWrapper;
  36.     var splashGravity:Float;
  37.    
  38.     public function new(x:Float = 0, y:Float = 0, vx:Float = 0, vy:Float = 0, color:Int = 0, radius:Int = 5, alpha:Float = 0.5, splashGravity:Float = 0.6)
  39.     {
  40.         this.splashGravity = splashGravity;
  41.         this.x = x;
  42.         this.y = y;
  43.         this.vx = vx;
  44.         this.vy = vy;
  45.         this.color = color;
  46.         this.radius = radius;
  47.         this.alpha = alpha;
  48.        
  49.         var width = this.radius*2;
  50.         bd = new BitmapData(width, width,true, 0);
  51.         var matrix:Matrix = new Matrix();
  52.        
  53.         shape = new Shape();
  54.         shape.graphics.beginFill(this.color, this.alpha);
  55.             shape.graphics.drawCircle(this.radius, this.radius, this.radius / 2);
  56.             shape.graphics.endFill();
  57.         bd.draw(shape);
  58.         bw = new BitmapWrapper(new Bitmap(this.bd));
  59.         attachImageToHUD(bw, Std.int(this.x), Std.int(this.y));
  60.         trace (alpha);
  61.     }
  62.    
  63.     public function update()
  64.     {
  65.         vy += splashGravity;
  66.         vx *= 0.99;
  67.         vy *= 0.99;
  68.         x += vx;
  69.         y += vy;
  70.         bw.x = x;
  71.         bw.y = y;
  72.     }
  73.    
  74.     public function dispose()
  75.     {
  76.         removeImage(bw);
  77.         bd = null;
  78.         shape = null;
  79.         bw = null;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement