ld21-ESCape/src/Functions.pbi
2011-08-21 02:16:30 +02:00

95 lines
2.3 KiB
Plaintext

; This file holds all the functions If it gets too big,
; we can split it in categories
; *****************************************************************************
; * Tileset
Procedure InitGraphics()
GFXLogo = LoadSprite(#PB_Any, "../data/gfx/logo.bmp")
GFXTileset = LoadSprite(#PB_Any, "../data/gfx/tileset01.bmp")
EndProcedure
; TODO: Make this dynamic
Procedure InitTileset()
Define i.i, j.i, count.i
count = 0
For i=0 To 5
For j=0 To 5
Tileset(count) = CopySprite(GFXTileset, #PB_Any)
ClipSprite(Tileset(count), #TILE_SIZE*j, #TILE_SIZE*i, #TILE_SIZE, #TILE_SIZE)
count+1
Next
Next
Debug count
EndProcedure
; TODO: Hier gehts weiter
Procedure LoadMap(Filename.s)
; Extract the map data from the XML file
If LoadXML(0, Filename) And XMLStatus(0) = #PB_XML_Success
Define *Node.i = XMLNodeFromPath(MainXMLNode(0), "/map/layer/data")
Define MapData.s = GetXMLNodeText(*Node)
If CreateRegularExpression(0, "\d,?")
Dim Tiles.s(0)
Define NumFound.i = ExtractRegularExpression(0, MapData, Tiles())
Define i.i, X.i, Y.i
X = 0
Y = 0
Debug ArraySize(Tiles())
For i=0 To NumFound-1
TileMap(X, Y)\TileNumber = Val(RTrim(Tiles(i), ","))-1
TileMap(X, Y)\X = X
TileMap(X, Y)\Y = Y
If X = #MAP_WIDTH-1
X = 0
Y+1
Else
X+1
EndIf
Next
EndIf
EndIf
EndProcedure
Procedure DrawTile(number.i, x.i, y.i)
DisplaySprite(Tileset(number), #TILE_SIZE*x, #TILE_SIZE*y)
EndProcedure
Procedure DrawMap()
Define X.i ,Y.i
For X.i=0 To Cam\Width
For Y.i=0 To Cam\Height
DrawTile(TileMap(X+Cam\X, Y+Cam\Y)\TileNumber, X, Y)
Next
Next
EndProcedure
Procedure DrawPlayer()
DrawTile(Player\TileNumber, Player\X-Cam\X, Player\Y-Cam\Y)
EndProcedure
Procedure DrawHUD()
EndProcedure
; *****************************************************************************
; * Menu
Procedure Menu_GotoCurrent()
If *ActiveMenu\Entries()\Selected <> #True
FirstElement(*ActiveMenu\Entries())
ForEach *ActiveMenu\Entries()
If *ActiveMenu\Entries()\Selected = #True
Break
EndIf
Next
EndIf
EndProcedure