Option Explicit
'размер карты в тайлах
Private mvarWidth As Integer, mvarHeight As Integer
'структура тайла. поверхность, ректангл
Private Type Tile
Surface As DirectDrawSurface7
TRect As RECT
End Type
'габариты тайла
Private mvarTileWidth As Integer, mvarTileHeight As Integer
'массив используемых на карте тайлов
Private Tiles() As Tile
'двухмерный массив карты тайлов
Private TileMap() As Integer
'количество используемых типов тайлов
Private mvarTilesQuantity As Integer
Public Property Let Height(ByVal vData As Integer)
mvarHeight = vData
End Property
Public Property Get Height() As Integer
Height = mvarHeight
End Property
Public Property Let Width(ByVal vData As Integer)
mvarWidth = vData
End Property
Public Property Get Width() As Integer
Width = mvarWidth
End Property
Private Sub LoadTiles(MapFile As String)
SetConfigurationFile MapFile
SetSection "Tiles"
mvarTilesQuantity = Int(LoadValue("Quantity"))
mvarTileWidth = Int(LoadValue("Width"))
mvarTileHeight = Int(LoadValue("Heigh"))
Dim i As Integer, j As Integer
ReDim Tiles(mvarTilesQuantity)
For i = 0 To mvarTilesQuantity - 1
Set Tiles(i).Surface = CreateDDSFromFile(App.Path + LoadValue("Tile" + CStr(i + 1)))
SetRect Tiles(i).TRect, 0, 0, mvarTileWidth, mvarTileHeight
Next i
ReDim TileMap(mvarWidth, mvarHeight)
Dim S As String
SetSection "TileMap"
'i - y; j - x
For i = 0 To mvarHeight - 1
S = LoadValue("Y" + CStr(i + 1))
For j = 0 To mvarWidth - 1
TileMap(j, i) = Int(Left(S, 1))
S = Right(S, mvarWidth - j - 1)
Next j
Next i
End Sub
Public Sub LoadMap(MapFile As String)
SetConfigurationFile MapFile
SetSection "Size"
mvarWidth = Int(LoadValue("Width"))
mvarHeight = Int(LoadValue("Height"))
LoadTiles (MapFile)
End Sub
Public Sub DrawMap()
DrawTiles
End Sub
Private Sub DrawTiles()
Dim i As Integer, j As Integer
For i = 0 To mvarWidth - 1
For j = 0 To mvarWidth - 1
'DrawTile i, j, Tiles(TileNo).Surface, Tiles(TileNo).TRect, mvarTileWidth, mvarTileHeight
DrawTile i, j
Next j
Next i
End Sub
Private Sub DrawTile(X As Integer, Y As Integer)
Dim TileNo As Integer
TileNo = TileMap(X, Y)
Dim dx As Long, dy As Long, W As Long, H As Long
dx = CLng(X)
dy = CLng(Y)
W = CLng(mvarTileWidth)
H = CLng(mvarTileHeight)
ddsBack.BltFast CartToIsoX(dx, dy, W), CartToIsoY(dx, dy, H), Tiles(TileNo).Surface, Tiles(TileNo).TRect, DDBLTFAST_SRCCOLORKEY
End Sub