2011-08-20 17:49:22 +02:00
|
|
|
; This file holds all the functions If it gets too big,
|
|
|
|
; we can split it in categories
|
|
|
|
|
|
|
|
; *****************************************************************************
|
|
|
|
; * Tileset
|
2011-08-20 20:14:22 +02:00
|
|
|
Procedure InitGraphics()
|
|
|
|
GFXLogo = LoadSprite(#PB_Any, "../data/gfx/logo.bmp")
|
2011-08-20 21:43:17 +02:00
|
|
|
GFXTileset = LoadSprite(#PB_Any, "../data/gfx/tileset01.bmp")
|
2011-08-20 20:14:22 +02:00
|
|
|
EndProcedure
|
|
|
|
|
2011-08-20 22:37:31 +02:00
|
|
|
; TODO: Make this dynamic
|
2011-08-20 17:49:22 +02:00
|
|
|
Procedure InitTileset()
|
2011-08-21 02:16:30 +02:00
|
|
|
Define i.i, j.i, count.i
|
|
|
|
count = 0
|
|
|
|
For i=0 To 5
|
|
|
|
For j=0 To 5
|
|
|
|
|
2011-08-21 14:31:28 +02:00
|
|
|
Tileset(count)\ID = CopySprite(GFXTileset, #PB_Any)
|
|
|
|
ClipSprite(Tileset(count)\ID, #TILE_SIZE*j, #TILE_SIZE*i, #TILE_SIZE, #TILE_SIZE)
|
|
|
|
|
|
|
|
Tileset(count)\Type = #TILESET_TYPE_FLOOR
|
|
|
|
Select count
|
|
|
|
Case 0
|
|
|
|
Tileset(count)\Type = #TILESET_TYPE_PLAYER
|
|
|
|
Case 2
|
|
|
|
Tileset(count)\Type = #TILESET_TYPE_WALL
|
|
|
|
Case 3
|
|
|
|
Tileset(count)\Type = #TILESET_TYPE_SOLID
|
|
|
|
Case 4
|
|
|
|
Tileset(count)\Type = #TILESET_TYPE_GRASS
|
|
|
|
EndSelect
|
|
|
|
|
2011-08-21 02:16:30 +02:00
|
|
|
count+1
|
|
|
|
Next
|
|
|
|
Next
|
|
|
|
EndProcedure
|
|
|
|
|
|
|
|
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)
|
2011-08-21 11:48:49 +02:00
|
|
|
If CreateRegularExpression(0, "\d{1,2},?")
|
2011-08-21 02:16:30 +02:00
|
|
|
Dim Tiles.s(0)
|
|
|
|
Define NumFound.i = ExtractRegularExpression(0, MapData, Tiles())
|
|
|
|
Define i.i, X.i, Y.i
|
|
|
|
X = 0
|
|
|
|
Y = 0
|
|
|
|
|
2011-08-21 11:48:49 +02:00
|
|
|
;CreateFile(0, "mapcheck.txt") ; File stuff for checking the map loader
|
2011-08-21 02:16:30 +02:00
|
|
|
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
|
2011-08-21 11:48:49 +02:00
|
|
|
|
|
|
|
;WriteString(0, StrU(TileMap(X, Y)\TileNumber+1)+",")
|
2011-08-21 02:16:30 +02:00
|
|
|
|
|
|
|
If X = #MAP_WIDTH-1
|
|
|
|
X = 0
|
|
|
|
Y+1
|
2011-08-21 11:48:49 +02:00
|
|
|
;WriteStringN(0, "") ; do new line
|
2011-08-21 02:16:30 +02:00
|
|
|
Else
|
|
|
|
X+1
|
|
|
|
EndIf
|
|
|
|
Next
|
2011-08-21 11:48:49 +02:00
|
|
|
;CloseFile(0)
|
2011-08-21 02:16:30 +02:00
|
|
|
EndIf
|
|
|
|
EndIf
|
2011-08-20 17:49:22 +02:00
|
|
|
EndProcedure
|
|
|
|
|
2011-08-21 12:42:55 +02:00
|
|
|
; Shadowmap
|
|
|
|
Procedure CalculateShadow()
|
|
|
|
Define X.i, Y.i
|
2011-08-21 13:54:12 +02:00
|
|
|
Define MapX.i, MapY.i, Strength.i, Centercheck.i, CentercheckX.i, CentercheckY.i
|
2011-08-21 12:42:55 +02:00
|
|
|
|
2011-08-21 13:54:12 +02:00
|
|
|
For X.i=-#SHADOW_RADIUS To #SHADOW_RADIUS*2
|
|
|
|
For Y.i=-#SHADOW_RADIUS To #SHADOW_RADIUS*2
|
|
|
|
MapX = Player\X + X
|
|
|
|
MapY = Player\Y + Y
|
2011-08-21 12:42:55 +02:00
|
|
|
|
2011-08-21 13:54:12 +02:00
|
|
|
CentercheckX = X
|
2011-08-21 12:42:55 +02:00
|
|
|
If CentercheckX < 0
|
|
|
|
CentercheckX * -1
|
|
|
|
EndIf
|
|
|
|
|
2011-08-21 13:54:12 +02:00
|
|
|
CentercheckY = Y
|
2011-08-21 12:42:55 +02:00
|
|
|
If CentercheckY < 0
|
|
|
|
CentercheckY * -1
|
|
|
|
EndIf
|
|
|
|
|
|
|
|
If CentercheckX > CentercheckY
|
2011-08-21 13:54:12 +02:00
|
|
|
Centercheck = CentercheckX
|
|
|
|
Else
|
|
|
|
Centercheck = CentercheckY
|
2011-08-21 12:42:55 +02:00
|
|
|
EndIf
|
2011-08-21 13:54:12 +02:00
|
|
|
Centercheck = #SHADOW_RADIUS - Centercheck;
|
2011-08-21 12:42:55 +02:00
|
|
|
|
2011-08-21 13:54:12 +02:00
|
|
|
Strength = (255 / #SHADOW_RADIUS) * (Centercheck)
|
2011-08-21 12:42:55 +02:00
|
|
|
|
|
|
|
If MapX >= 0 And MapY >= 0
|
|
|
|
If ShadowMap(MapX, MapY)\Strength < Strength
|
|
|
|
ShadowMap(MapX, MapY)\Strength = Strength
|
|
|
|
EndIf
|
|
|
|
EndIf
|
|
|
|
Next
|
|
|
|
Next
|
|
|
|
EndProcedure
|
|
|
|
|
|
|
|
Procedure DrawShadowtile(strength.i, x.i, y.i)
|
|
|
|
Box(#TILE_SIZE*x, #TILE_SIZE*y, #TILE_SIZE, #TILE_SIZE, RGBA(Random(0), Random(0), Random(0), 255-strength))
|
|
|
|
EndProcedure
|
|
|
|
|
|
|
|
Procedure DrawShadow()
|
|
|
|
Define X.i ,Y.i
|
|
|
|
|
|
|
|
StartDrawing(ScreenOutput()) ;ImageOutput(0)
|
|
|
|
DrawingMode(#PB_2DDrawing_AlphaBlend)
|
|
|
|
For X.i=0 To Cam\Width
|
|
|
|
For Y.i=0 To Cam\Height
|
|
|
|
DrawShadowtile(ShadowMap(X+Cam\X, Y+Cam\Y)\Strength, X, Y)
|
|
|
|
Next
|
|
|
|
Next
|
|
|
|
StopDrawing()
|
|
|
|
EndProcedure
|
|
|
|
|
|
|
|
; Map itself
|
2011-08-20 20:15:44 +02:00
|
|
|
Procedure DrawTile(number.i, x.i, y.i)
|
2011-08-21 14:31:28 +02:00
|
|
|
DisplaySprite(Tileset(number)\ID, #TILE_SIZE*x, #TILE_SIZE*y)
|
2011-08-20 20:15:44 +02:00
|
|
|
EndProcedure
|
|
|
|
|
|
|
|
Procedure DrawMap()
|
2011-08-20 22:37:31 +02:00
|
|
|
Define X.i ,Y.i
|
2011-08-20 20:15:44 +02:00
|
|
|
|
2011-08-20 23:51:33 +02:00
|
|
|
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)
|
2011-08-20 22:37:31 +02:00
|
|
|
Next
|
|
|
|
Next
|
2011-08-20 20:15:44 +02:00
|
|
|
EndProcedure
|
|
|
|
|
2011-08-21 14:31:28 +02:00
|
|
|
Procedure TileIsType(type.i, X.i, Y.i)
|
|
|
|
Define istype.b
|
|
|
|
|
|
|
|
istype = #False
|
|
|
|
|
|
|
|
If Tileset(TileMap(X, Y)\TileNumber)\Type = type
|
|
|
|
istype = #True
|
|
|
|
EndIf
|
|
|
|
|
|
|
|
ProcedureReturn istype
|
|
|
|
EndProcedure
|
|
|
|
|
2011-08-21 12:42:55 +02:00
|
|
|
; The player
|
2011-08-20 22:52:29 +02:00
|
|
|
Procedure DrawPlayer()
|
2011-08-20 23:51:33 +02:00
|
|
|
DrawTile(Player\TileNumber, Player\X-Cam\X, Player\Y-Cam\Y)
|
2011-08-20 22:52:29 +02:00
|
|
|
EndProcedure
|
|
|
|
|
2011-08-21 12:42:55 +02:00
|
|
|
; We need a HUD, hell yeah!
|
2011-08-20 22:37:31 +02:00
|
|
|
Procedure DrawHUD()
|
2011-08-20 21:43:17 +02:00
|
|
|
EndProcedure
|
2011-08-20 17:49:22 +02:00
|
|
|
|
2011-08-20 22:52:29 +02:00
|
|
|
|
2011-08-20 17:49:22 +02:00
|
|
|
; *****************************************************************************
|
|
|
|
; * Menu
|
|
|
|
|
|
|
|
Procedure Menu_GotoCurrent()
|
|
|
|
If *ActiveMenu\Entries()\Selected <> #True
|
2011-08-20 22:37:31 +02:00
|
|
|
FirstElement(*ActiveMenu\Entries())
|
2011-08-20 17:49:22 +02:00
|
|
|
|
|
|
|
ForEach *ActiveMenu\Entries()
|
|
|
|
If *ActiveMenu\Entries()\Selected = #True
|
|
|
|
Break
|
|
|
|
EndIf
|
|
|
|
Next
|
|
|
|
EndIf
|
|
|
|
EndProcedure
|
2011-08-20 20:15:44 +02:00
|
|
|
|
|
|
|
|