fb:porticula NoPaste
TileEngine
Uploader: | Westbeam |
Datum/Zeit: | 12.11.2011 17:18:55 |
'Die Tiles sind jeweils 16x16 Pixel groß
'Im Beispiel wird ein Tileset mit 5 Tiles aus dem Ordner '"gfx/tileset1" geladen
Type TTile
As Integer x,y
As Integer block
As Any Ptr img
End Type
Type TTileset
As TTile Tile(128)
As Integer anz
As String path
End Type
Dim Shared As Integer AnzTilesets,ScrollX,ScrollY
Dim Shared As TTileset Tileset(128)
Declare Function LoadTileset(path As String,anz As Integer)As Integer
Declare Sub DrawMap(tileset2 As Integer,mx As Integer,my As Integer)
Declare Sub ChangeCollision(tileset2 As Integer,tile2 As Integer,col As Integer)
Function LoadTileset(path As String,anz As Integer)As Integer
AnzTilesets+=1
Tileset(AnzTilesets).anz=anz
Tileset(AnzTilesets).path=path
For i As Integer=0 To anz
Tileset(AnzTilesets).Tile(i).img=ImageCreate(16,16)
Bload Tileset(AnzTilesets).path+"/tile"+Str(i+1)+".bmp",Tileset(AnzTilesets).Tile(i).img
Tileset(AnzTilesets).Tile(i).block=0
Next
Return AnzTilesets
End Function
Sub DrawMap(tileset2 As Integer,mx As Integer,my As Integer)
Dim As Integer Map(mx,my)
For i As Integer=1 To my
For i2 As Integer=1 To mx
Read Map(i2,i)
Next
Next
For y As Integer= 1 To my
For x As Integer= 1 To mx
For i As Integer=0 To Tileset(tileset2).anz
If map(x,y)=i Then Put(x*16-ScrollX,y*16-ScrollY),Tileset(tileset2).Tile(i).img,Trans
Next
Next
Next
End Sub
Sub ChangeCollision(tileset2 As Integer,tile2 As Integer,col As Integer)
Tileset(tileset2).Tile(tile2).block=col
End Sub
'Example:
Screenres 320,240,32
Var set1=LoadTileset("gfx/tileset1",5)
Do
Screenlock
Cls
Restore level1
DrawMap(set1,10,10)
Screenunlock
Sleep 1
Loop Until Inkey=Chr(27)
End
level1:
Data 4,4,4,4,4,4,4,4,4,4
Data 4,0,0,0,0,0,0,0,0,4
Data 4,0,0,0,3,0,0,0,0,4
Data 4,0,0,0,2,0,0,0,0,4
Data 4,0,0,0,0,0,0,0,0,4
Data 4,0,0,0,0,0,0,0,0,4
Data 4,0,0,0,0,0,0,0,0,4
Data 4,0,0,0,0,0,0,0,0,4
Data 4,0,0,0,0,0,0,0,0,4
Data 4,4,4,4,4,4,4,4,4,4