Commits

Greg Taylor committed ea0b95f

More hex to pixel stuff.

  • Participants
  • Parent commits 6116df5

Comments (0)

Files changed (2)

File lib/src/map_widget/terrain_layer.dart

     regionPixelHeight = regionSize * hexPixelHeight;
   }
 
+  Map getPixelsFromHexCoords(int x, int y) {
+    double hexUpperLeftXPixel = x * hexHorizOffset;
+    double hexUpperLeftYPixel = y * hexPixelHeight;
+    bool hexIsEven = (x & 1) == 0;
+    if (hexIsEven) {
+      hexUpperLeftYPixel += hexPixelHeight / 2;
+    }
+    return {
+      'hexUpperLeftXPixel': hexUpperLeftXPixel,
+      'hexUpperLeftYPixel': hexUpperLeftYPixel,
+    };
+  }
+
   double calcAndSetPixelDimensions() {
     // For some reason, we're off by a bit with this.
     pixelsWide = (mapContainer.hexesWide * hexHorizOffset) + 18.0;
         int hexY = regionUpperLeftHexY() + y;
 
         double hexUpperLeftXPixel = regionStartXPixel + (x * terrainLayer.hexHorizOffset);
-        double hexUupperLeftYPixel = regionStartYPixel + (y * terrainLayer.hexPixelHeight);
+        double hexUpperLeftYPixel = regionStartYPixel + (y * terrainLayer.hexPixelHeight);
         bool hexIsEven = (hexX & 1) == 0;
         if (hexIsEven) {
-          hexUupperLeftYPixel += terrainLayer.hexPixelHeight / 2;
+          hexUpperLeftYPixel += terrainLayer.hexPixelHeight / 2;
         }
 
-        drawHex(hexUpperLeftXPixel, hexUupperLeftYPixel, hexX, hexY);
+        drawHex(hexUpperLeftXPixel, hexUpperLeftYPixel, hexX, hexY);
       }
     }
   }

File lib/src/map_widget/unit_layer.dart

   TextureAtlas _textureAtlas;
   UnitStore unitStore;
 
+  Map<String,UnitSprite> _unitSprites;
+
   UnitLayerSprite(MapContainer this.mapContainer, UnitStore this.unitStore) {
+    _unitSprites = new Map<String,UnitSprite>();
     x = 0.0;
     y = 0.0;
     this.addTo(mapContainer);
   void renderTestUnit() {
     _textureAtlas = mapContainer.resourceManager.getTextureAtlas('unitTextures');
     var bitmapData = _textureAtlas.getBitmapData('Anubis');
+    var coords = mapContainer.terrainLayer.getPixelsFromHexCoords(10, 1);
     var bitmap = new Bitmap(bitmapData)
-    ..x = 0.0
-    ..y = 0.0
+    ..x = coords['hexUpperLeftXPixel']
+    ..y = coords['hexUpperLeftYPixel']
     // Adds the hex to the region Sprite.
     ..addTo(this);
   }
+}
+
+
+class UnitSprite extends Sprite {
+
 }