Advertisement
nutter666

Untitled

Jul 1st, 2013
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.     import flash.display.MovieClip;
  3.     import flash.display.Sprite;
  4.    
  5.     public class TestUnit extends MovieClip{
  6.        
  7.         var collideMarker:Sprite = new Sprite();
  8.        
  9.         var walkSpeed:Number = 1;
  10.        
  11.         var unitWidth:int = 10;
  12.        
  13.         var laneNumber:int;
  14.        
  15.         var unitsInLane:Array = [];
  16.        
  17.         var colliding:Boolean
  18.        
  19.         var playerControlled:Boolean;
  20.        
  21.         var parentClass:BattleScreen
  22.  
  23.         public function TestUnit() {
  24.             // constructor code
  25.         this.addChild(collideMarker)
  26.         }
  27.        
  28.         public function setupUnit(laneNum:int,pClass,pCon:Boolean){
  29.         laneNumber = laneNum
  30.         this.y = 250+(laneNumber*50) - this.height
  31.         parentClass = pClass
  32.         playerControlled = pCon
  33.         }
  34.        
  35.         public function updateUnit(){
  36.         moveForward();
  37.         }
  38.        
  39.         public function moveForward(){
  40.         //collideMarker.graphics.clear();
  41.         collideMarker.graphics.lineStyle(1,0xFF0000)
  42.         if(playerControlled){
  43.         collideMarker.graphics.drawCircle(unitWidth,0,3)
  44.         }
  45.         else{
  46.         collideMarker.graphics.drawCircle(-unitWidth,0,3)
  47.         }
  48.         colliding = false;
  49.         getUnitsInLane();
  50.         for(var i:int = 0;i<=unitsInLane.length-1;i++){
  51.         if(collideMarker.hitTestObject(unitsInLane[i].unitBody)){
  52.         colliding = true;
  53.         }
  54.         }
  55.         if(!colliding){
  56.         if(playerControlled){
  57.         this.x += walkSpeed
  58.         }
  59.         else{
  60.         this.x -= walkSpeed
  61.         }
  62.         }
  63.        
  64.         }
  65.        
  66.         function getUnitsInLane(){
  67.         unitsInLane = [];
  68.         for(var i:int = 0;i<= parentClass.playerUnits.length-1;i++){
  69.         if(parentClass.playerUnits[i].laneNumber == this.laneNumber && parentClass.playerUnits[i] != this){
  70.         unitsInLane.push(parentClass.playerUnits[i])
  71.         }
  72.         }
  73.         for(var j:int = 0;j<= parentClass.enemyUnits.length-1;j++){
  74.         if(parentClass.enemyUnits[j].laneNumber == this.laneNumber && parentClass.enemyUnits[j] != this){
  75.         unitsInLane.push(parentClass.enemyUnits[j])
  76.         }
  77.         }
  78.        
  79.         }
  80.  
  81.     }
  82.    
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement