Advertisement
Guest User

Untitled

a guest
May 24th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.84 KB | None | 0 0
  1. package com.isartdigital.plateformer.game.sprites.levelObjects.props.traps;
  2. import com.isartdigital.plateformer.game.sprites.levelObjects.props.Trap;
  3. import pixi.core.display.Container;
  4. import pixi.core.math.Point;
  5.  
  6. /**
  7.  * ...
  8.  * @author Rafael Garcin
  9.  */
  10.  
  11.  enum Orientation {
  12.      HORIZONTAL;
  13.      VERTICAL;
  14.  }
  15.  
  16. class KillZoneDynamic extends Trap
  17. {
  18.     public static function doActions():Void {
  19.         for (killZoneDynamic in list) {
  20.             killZoneDynamic.doAction();
  21.         }
  22.     }
  23.    
  24.     public static var list:Array<KillZoneDynamic> = new Array<KillZoneDynamic>();
  25.    
  26.     private static inline var AMPLITUDE:Int = 200;
  27.  
  28.     public var horizontal(get, null):Bool;
  29.    
  30.     private var speedValue:Float = 0;
  31.     private var baseAcceleration:Float = 1.8;
  32.     private var origin:Float;
  33.     private var pos:Float;
  34.    
  35.     private var orientation: Orientation;
  36.    
  37.     private var way:Int = 1;
  38.    
  39.     public function new()
  40.     {
  41.         super();
  42.         speedValue = 0.07;
  43.         baseAcceleration = 1;
  44.     }
  45.    
  46.     override public function init(pName:String,?pStage:Container=null, ?pX:Float=0, ?pY:Float=0, ?pRotation:Float=0, ?pScaleX:Float= 1, ?pScaleY:Float = 1, ?pAssetName:String=null, ?pStart:Bool=true):Void
  47.     {
  48.         super.init(pName,pStage, pX, pY, pRotation, pScaleX, pScaleY, pAssetName, pStart);
  49.         orientation = Math.abs(rotation % Math.PI) <= 0.01 ? Orientation.HORIZONTAL : Orientation.VERTICAL;
  50.         origin = horizontal ? x : y;
  51.     }
  52.    
  53.     override public function start():Void
  54.     {
  55.         list.push(this);
  56.         super.start();
  57.     }
  58.    
  59.     override public function destroy():Void
  60.     {
  61.         list.splice(list.indexOf(this), 1);
  62.         super.destroy();
  63.     }
  64.    
  65.     override function doActionNormal():Void
  66.     {
  67.         pos = origin + Math.cos(Main.getInstance().frames * speedValue) * AMPLITUDE;
  68.        
  69.         if (horizontal) x = pos;
  70.         else y = pos;
  71.     }
  72.    
  73.     private function get_horizontal():Bool {
  74.         return orientation == Orientation.HORIZONTAL;
  75.     }
  76.    
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement