Guest User

Untitled

a guest
Apr 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // function to load the enemies to the stage
  2.  
  3.         public function loadEnemies ():void
  4.  
  5.         {
  6.  
  7.             //load in the enemies
  8.  
  9.             var positions:Array = new Array ();
  10.  
  11.             data = layout.layer [2].data;
  12.  
  13.             positions = data.split (",");
  14.  
  15.            
  16.  
  17.             var counter:int = 0;
  18.  
  19.             var endLoop:int = positions.length;
  20.  
  21.             var enemy:Enemy;
  22.  
  23.             var tileValue:int = 0;
  24.  
  25.             var xpos:int = 0;
  26.  
  27.             var ypos:int = 0;
  28.  
  29.            
  30.  
  31.             while (counter < endLoop)
  32.  
  33.             {
  34.  
  35.                 tileValue = positions [counter];
  36.  
  37.                
  38.  
  39.                 if (tileValue > 0)
  40.  
  41.                 {
  42.  
  43.                     // modulus operator
  44.  
  45.                     //x position is determined by using the modulus to get the remainer of the layout width.
  46.  
  47.                     //this determines if the xpos needs to move down on the ypos.
  48.  
  49.                     //counter divided by the map width (example 0 / 1 = 0 ) multiplied by tile width ( 0 * 32 == 0)
  50.  
  51.                     // xpos would be 0 then
  52.  
  53.                     //
  54.  
  55.                     xpos = (counter % layout.@width) * layout.@tilewidth;
  56.  
  57.                    
  58.  
  59.                     //math.floor drops the number down to the lower value (3.6 becomes 3)
  60.  
  61.                    
  62.  
  63.                     ypos = Math.floor (counter / layout.@width) * layout.@tileheight;
  64.  
  65.                    
  66.  
  67.                     enemy = new Enemy (tileValue);
  68.  
  69.                     enemy.x = xpos;
  70.  
  71.                     enemy.y = ypos;
  72.  
  73.                     world.add (enemy);
  74.  
  75.                    
  76.  
  77.                     trace (xpos);
  78.  
  79.                     trace (ypos);
  80.  
  81.                     trace ("stuff");
  82.  
  83.                    
  84.  
  85.                 }
  86.  
  87.                
  88.  
  89.                 counter = counter + 1;
  90.  
  91.             }
  92.  
  93.         }
Add Comment
Please, Sign In to add comment