1 module isodi.raylib.resources.tile; 2 3 import raylib; 4 5 import std.string; 6 import std.exception; 7 8 import isodi.bind; 9 import isodi.pack; 10 import isodi.raylib.cell; 11 import isodi.raylib.internal; 12 13 14 @safe: 15 16 17 /// A tile resource. 18 struct Tile { 19 20 /// Owner object. 21 RaylibCell cell; 22 23 /// Loaded texture. 24 Texture2D texture; 25 26 /// Display scale of the tile. 27 float scale; 28 29 /// Tile options loaded 30 const(ResourceOptions)* options; 31 32 /// Create the tile and load textures. 33 this(RaylibCell cell, Pack.Resource!string resource) { 34 35 this.cell = cell; 36 this.texture = cell.display.loadTexture(resource.match); 37 this.options = resource.options; 38 this.scale = cast(float) cell.display.cellSize / texture.width; 39 40 } 41 42 /// Draw the tile 43 void draw() @trusted { 44 45 const cellSize = cell.display.cellSize; 46 47 rlPushMatrix(); 48 scope (exit) rlPopMatrix(); 49 50 // Move to the appropriate position 51 rlTranslatef(cell.visualPosition.toTuple3(cellSize).expand); 52 53 // Rotate to make it lay 54 rlRotatef(90, 1, 0, 0); 55 56 // Scale the tile to fit cell size 57 rlScalef(scale, scale, scale); 58 59 // Correct position 60 rlTranslatef(0, 0, 1); 61 62 // Draw 63 texture.DrawTexture(0, 0, cell.color); 64 65 } 66 67 }