Worklog for FBEpyon

RPG Game

Return to Worklogs

Test2016-06-29
format_code('
Global _Zone:TMap = CreateMap()
Global _ZoneManager:TZoneManager = TZoneManager.Create()
Global _Player:TPlayer = TPlayer.Create(0,0)
Global _Camera:TCamera = TCamera.Create(0,0)

Type TZone

Field _data:Int[,]
Field _offsetx:Int
Field _offsety:Int

Function Create:TZone(width:Int = 32, height:Int = 32)
Local zone:TZone = New TZone
zone._width = width
zone._height = height
zone._data = New Int[width * height]
Return zone
End Function

Method Init()
For Local i:Int = 0 Until _width
For Local j:Int = 0 Until _height
_data[i,j] = 0
Next
Next
End

Method Draw:Int(camera:TCamera)
Local IsAlive:Int = False
For Local i:Int = 0 To _width - 1
For Local j:Int = 0 To _height - 1
If _data[i,j] > 0
Local x:Int = (i+_offsetx) * 16 - _Camera.GetX()
Local y:Int = (j+_offsety) * 16 - _Camera.GetY()
If _Camera.CheckBounds(x, y)
IsAlive = True
DrawRect x, y, 16, 16
EndIf
EndIf
Next
Next
Return IsAlive
End Method

Method SetOffset(x:Int, y:Int)
_offsetx = x
_offsety = y
end Method

Method GetOffsetX:Int()
Return _offsetx
End Method

Method GetOffsetY:Int()
Return _offsety
End Method

End Type

Type TZoneManager

Field _curzone:TZone

Function Create:TZoneManager()
Return New TZoneManager
End Function

Method Init()
For Local i:Int = 0 To 7
For Local j:Int = 0 To 7
MapInsert(_Zone, hex(i+j*8), TZone.Create())
Next
Next
// Store first zone into _curzone variable
If MapContains(_Zone, hex(0))
_curzone = TZone(MapValueForKey(_Zone, hex(0))
EndIf
End Method

Method Update()

End Method

Method Draw(camera:TCamera)
If _curzone.Draw(camera) = False
SetCurrent(((_Player.GetX()/16)/32), ((_Player.GetY()/16)/32))
EndIf
End Method

Method SetCurrent(x:Int, y:Int)
If MapContains(_Zone, hex(x + y * 8))
_curzone = TZone(MapValueForKey(_Zone, hex(x + y * 8))
EndIf
End Method

Method GetCurrent:TZone()
Return _curzone
End Method

End Type
')