Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  
  2. {
  3.     import net.flashpunk.World;
  4.     import net.flashpunk.utils.Input;
  5.     import net.flashpunk.FP;
  6.    
  7.     public class GameWorld extends World
  8.     {
  9.         //Current X on the grid
  10.         public var xInt:uint = 0;
  11.         //current Y on the grid
  12.         public var yInt:uint = 0;
  13.         //pixel coordinates on screen
  14.         public var pixelX:uint = 1;
  15.         public var pixelY:uint = 1;
  16.         //current layer of map build
  17.         public var layerInt:uint = 20;
  18.         //tile that's being built
  19.         public var currentTile:uint = 0;
  20.         //current Z value in the heightmap
  21.         public var currentHeight:uint = 1;
  22.         //the lowest known height of each tile in the immediate vicinity of the current tile
  23.         public var lowestHeightNear:uint = 0;
  24.         //used to assign layers to tiles spawned under others to fill gaps
  25.         public var layerPlaceholder:Number;
  26.        
  27.         //Build the tilemap
  28.         public var a01Row:Array = [07, 08, 09, 10, 11, 12, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  29.         public var a02Row:Array = [07, 08, 09, 10, 11, 11, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  30.         public var a03Row:Array = [07, 08, 09, 10, 11, 11, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  31.         public var a04Row:Array = [09, 08, 09, 10, 11, 11, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  32.         public var a05Row:Array = [09, 08, 09, 10, 11, 12, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  33.         public var a06Row:Array = [09, 08, 09, 10, 11, 12, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  34.         public var a07Row:Array = [08, 08, 09, 10, 11, 11, 11, 08, 07, 08, 08, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  35.         public var a08Row:Array = [08, 08, 09, 10, 11, 12, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  36.         public var a09Row:Array = [07, 08, 09, 07, 11, 12, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  37.         public var a10Row:Array = [07, 08, 09, 10, 11, 12, 11, 07, 07, 09, 07, 08, 09, 12, 11, 08, 08, 09, 10, 08];
  38.         public var a11Row:Array = [07, 08, 09, 10, 11, 12, 11, 07, 07, 07, 09, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  39.         public var a12Row:Array = [08, 09, 09, 10, 11, 12, 11, 08, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  40.         public var a13Row:Array = [08, 08, 09, 07, 11, 12, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  41.         public var a14Row:Array = [08, 08, 09, 10, 11, 12, 11, 07, 07, 10, 09, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  42.         public var a15Row:Array = [08, 08, 09, 10, 11, 12, 11, 07, 07, 07, 07, 08, 12, 10, 11, 08, 08, 09, 10, 08];
  43.         public var a16Row:Array = [07, 08, 09, 10, 11, 12, 10, 08, 10, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  44.         public var a17Row:Array = [07, 08, 09, 10, 11, 12, 11, 07, 09, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  45.         public var a18Row:Array = [07, 08, 09, 10, 11, 12, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  46.         public var a19Row:Array = [08, 08, 09, 07, 10, 12, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  47.         public var a20Row:Array = [08, 08, 09, 10, 11, 12, 11, 07, 07, 07, 07, 08, 09, 10, 11, 08, 08, 09, 10, 08];
  48.         public var map1Array:Array = [a01Row, a02Row, a03Row, a04Row, a05Row, a06Row, a07Row, a08Row, a09Row, a10Row, a11Row, a12Row, a13Row, a14Row, a15Row, a16Row, a17Row, a18Row, a19Row, a20Row];
  49.        
  50.        
  51.         //Build the height map
  52.         public var h01Row:Array = [01, 01, 02, 09, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  53.         public var h02Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  54.         public var h03Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  55.         public var h04Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  56.         public var h05Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  57.         public var h06Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  58.         public var h07Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  59.         public var h08Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  60.         public var h09Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  61.         public var h10Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  62.         public var h11Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  63.         public var h12Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  64.         public var h13Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  65.         public var h14Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  66.         public var h15Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  67.         public var h16Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  68.         public var h17Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  69.         public var h18Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  70.         public var h19Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  71.         public var h20Row:Array = [01, 01, 02, 02, 03, 03, 04, 04, 05, 05, 06, 06, 07, 07, 08, 08, 09, 09, 10, 10];
  72.         public var height1Array:Array = [h01Row, h02Row, h03Row, h04Row, h05Row, h06Row, h07Row, h08Row, h09Row, h10Row, h11Row, h12Row, h13Row, h14Row, h15Row, h16Row, h17Row, h18Row, h19Row, h20Row];
  73.        
  74.         public function GameWorld()
  75.         {
  76.             add(new TileSetTest);
  77.             for (var i:int = 0; i < 400; i++)
  78.             {
  79.                 layerInt++;
  80.                 if (xInt > 19)
  81.                 {
  82.                     xInt -= 20;
  83.                     yInt++;
  84.                     layerInt -= 21;
  85.                    
  86.                 }
  87.                 currentTile = map1Array[yInt][xInt];
  88.                 currentHeight = height1Array[yInt][xInt];
  89.                 // 0 = the X offset in this equasion, necessary for different sized objects
  90.                 pixelX = 0 + ((xInt * 22) + (yInt * 22));
  91.                 // 343 = the Y offset in this equasion, necessary for different sized objects
  92.                 pixelY = 343 - ((xInt * 11) - (yInt * 11));
  93.                 pixelY = (pixelY -= (currentHeight * 11));
  94.                 add(new TileEntity(pixelX, pixelY, layerInt, currentTile));
  95.                 layerPlaceholder = layerInt;
  96.                 if (!xInt == 0)
  97.                 {
  98.                     if (height1Array[yInt][(xInt - 1)] < height1Array[yInt][xInt])
  99.                     {
  100.                         lowestHeightNear = height1Array[yInt][xInt - 1];
  101.                         for (var j:int = 0; j < 9; j++)
  102.                         {
  103.                             if (lowestHeightNear < currentHeight)
  104.                             {
  105.                                 currentHeight --;
  106.                                 layerPlaceholder ++;
  107.                                 pixelY = (343 - ((xInt * 11) - (yInt * 11)));
  108.                                 pixelY = (pixelY -= (currentHeight * 11));
  109.                                 add(new TileEntity(pixelX, pixelY, layerPlaceholder, currentTile));
  110.                             }
  111.                         }
  112.                     }
  113.                 }
  114.                 if (!xInt == 16)
  115.                 {
  116.                     trace("butts");
  117.                 }
  118.                 xInt++;
  119.             }
  120.         }
  121.        
  122.     }
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement