``` Private Sub InitSurfaces() Dim rec As DxVBLib.RECT ' If debug mode, handle error then exit out If Options.Debug = 1 Then On Error GoTo errorhandler ' DirectDraw Surface memory management setting DDSD_Temp.lFlags = DDSD_CAPS DDSD_Temp.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY ' clear out everything for re-init Set DDS_BackBuffer = Nothing ' Initialize back buffer With DDSD_BackBuffer .lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT .ddsCaps.lCaps = DDSD_Temp.ddsCaps.lCaps .lWidth = (MAX_MAPX + 3) * PIC_X .lHeight = (MAX_MAPY + 3) * PIC_Y End With Set DDS_BackBuffer = DD.CreateSurface(DDSD_BackBuffer) ' load persistent surfaces If FileExist(App.Path & "\data files\graphics\door.bmp", True) Then Call InitDDSurf("door", DDSD_Door, DDS_Door) If FileExist(App.Path & "\data files\graphics\direction.bmp", True) Then Call InitDDSurf("direction", DDSD_Direction, DDS_Direction) If FileExist(App.Path & "\data files\graphics\target.bmp", True) Then Call InitDDSurf("target", DDSD_Target, DDS_Target) If FileExist(App.Path & "\data files\graphics\misc.bmp", True) Then Call InitDDSurf("misc", DDSD_Misc, DDS_Misc) If FileExist(App.Path & "\data files\graphics\blood.bmp", True) Then Call InitDDSurf("blood", DDSD_Blood, DDS_Blood) If FileExist(App.Path & "\data files\graphics\bars.bmp", True) Then Call InitDDSurf("bars", DDSD_Bars, DDS_Bars) If FileExist(App.Path & "\data files\graphics\gui\main\hud.bmp", True) Then Call InitDDSurf("gui\main\hud", DDSD_HUD, DDS_HUD) ' count the blood sprites BloodCount = DDSD_Blood.lWidth / 32 ' Error handler Exit Sub errorhandler: HandleError "InitSurfaces", "modDirectDraw7", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.Clear Exit Sub End Sub ``` ``` Public Sub BltHUD() Dim x As Long, y As Long, rec As DxVBLib.RECT 'Rect/Rec is a simple way to say Rectangle. The RECT is the area to grab from your bmp 'In this case it is the whole thing while in sprites/tiles it is only portions. With rec .top = 0 .Left = 0 .Right = 0 .Bottom = 0 End With 'V This here basically tells it to cut out ur color in pixel 1x1. Call Engine_BltFast(Camera.Right - rec.Right, Camera.top, DDS_HUD, rec, DDBLTFAST_SRCCOLORKEY) End Sub ``` ``` Public Sub Render_Graphics() Dim x As Long Dim y As Long Dim i As Long Dim rec As DxVBLib.RECT Dim rec_pos As DxVBLib.RECT ' If debug mode, handle error then exit out If Options.Debug = 1 Then On Error GoTo errorhandler ' check if automation is screwed If Not CheckSurfaces Then ' exit out and let them know we need to re-init ReInitSurfaces = True Exit Sub Else ' if we need to fix the surfaces then do so If ReInitSurfaces Then ReInitSurfaces = False ReInitDD End If End If ' don't render If frmMain.WindowState = vbMinimized Then Exit Sub If GettingMap Then Exit Sub ' update the viewpoint UpdateCamera ' update animation editor If Editor = EDITOR_ANIMATION Then EditorAnim_BltAnim End If ' fill it with black DDS_BackBuffer.BltColorFill rec_pos, 0 BltHUD ' blit lower tiles If NumTileSets > 0 Then For x = TileView.Left To TileView.Right For y = TileView.top To TileView.Bottom If IsValidMapPoint(x, y) Then Call BltMapTile(x, y) End If Next Next End If ' render the decals For i = 1 To MAX_BYTE Call BltBlood(i) Next ' Blit out the items If NumItems > 0 Then For i = 1 To MAX_MAP_ITEMS If MapItem(i).num > 0 Then Call BltItem(i) End If Next End If ' draw animations If NumAnimations > 0 Then For i = 1 To MAX_BYTE If AnimInstance(i).Used(0) Then BltAnimation i, 0 End If Next End If ' Y-based render. Renders Players, Npcs and Resources based on Y-axis. For y = 0 To Map.MaxY If NumCharacters > 0 Then ' Players For i = 1 To Player_HighIndex If IsPlaying(i) And GetPlayerMap(i) = GetPlayerMap(MyIndex) Then If Player(i).y = y Then Call BltPlayer(i) End If End If Next ' Npcs For i = 1 To Npc_HighIndex If MapNpc(i).y = y Then Call BltNpc(i) End If Next End If ' Resources If NumResources > 0 Then If Resources_Init Then If Resource_Index > 0 Then For i = 1 To Resource_Index If MapResource(i).y = y Then Call BltMapResource(i) End If Next End If End If End If Next ' animations If NumAnimations > 0 Then For i = 1 To MAX_BYTE If AnimInstance(i).Used(1) Then BltAnimation i, 1 End If Next End If ' blit out upper tiles If NumTileSets > 0 Then For x = TileView.Left To TileView.Right For y = TileView.top To TileView.Bottom If IsValidMapPoint(x, y) Then Call BltMapFringeTile(x, y) End If Next Next End If ' blit out a square at mouse cursor If InMapEditor Then If frmEditor_Map.optBlock.Value = True Then For x = TileView.Left To TileView.Right For y = TileView.top To TileView.Bottom If IsValidMapPoint(x, y) Then Call BltDirection(x, y) End If Next Next End If Call BltTileOutline End If ' Render the bars BltBars ' Blt the target icon If myTarget > 0 Then If myTargetType = TARGET_TYPE_PLAYER Then BltTarget (Player(myTarget).x * 32) + Player(myTarget).XOffset, (Player(myTarget).y * 32) + Player(myTarget).YOffset ElseIf myTargetType = TARGET_TYPE_NPC Then BltTarget (MapNpc(myTarget).x * 32) + MapNpc(myTarget).XOffset, (MapNpc(myTarget).y * 32) + MapNpc(myTarget).YOffset End If End If ' blt the hover icon For i = 1 To Player_HighIndex If IsPlaying(i) Then If Player(i).Map = Player(MyIndex).Map Then If CurX = Player(i).x And CurY = Player(i).y Then If myTargetType = TARGET_TYPE_PLAYER And myTarget = i Then ' dont render lol Else BltHover TARGET_TYPE_PLAYER, i, (Player(i).x * 32) + Player(i).XOffset, (Player(i).y * 32) + Player(i).YOffset End If End If End If End If Next For i = 1 To Npc_HighIndex If MapNpc(i).num > 0 Then If CurX = MapNpc(i).x And CurY = MapNpc(i).y Then If myTargetType = TARGET_TYPE_NPC And myTarget = i Then ' dont render lol Else BltHover TARGET_TYPE_NPC, i, (MapNpc(i).x * 32) + MapNpc(i).XOffset, (MapNpc(i).y * 32) + MapNpc(i).YOffset End If End If End If Next ' Lock the backbuffer so we can draw text and names TexthDC = DDS_BackBuffer.GetDC ' draw FPS If BFPS Then Call DrawText(TexthDC, Camera.Right - (Len("FPS: " & GameFPS) * 8), Camera.top + 1, Trim$("FPS: " & GameFPS), QBColor(Yellow)) End If ' draw cursor, player X and Y locations If BLoc Then Call DrawText(TexthDC, Camera.Left, Camera.top + 1, Trim$("cur x: " & CurX & " y: " & CurY), QBColor(Yellow)) Call DrawText(TexthDC, Camera.Left, Camera.top + 15, Trim$("loc x: " & GetPlayerX(MyIndex) & " y: " & GetPlayerY(MyIndex)), QBColor(Yellow)) Call DrawText(TexthDC, Camera.Left, Camera.top + 27, Trim$(" (map #" & GetPlayerMap(MyIndex) & ")"), QBColor(Yellow)) End If ' draw player names For i = 1 To Player_HighIndex If IsPlaying(i) And GetPlayerMap(i) = GetPlayerMap(MyIndex) Then Call DrawPlayerName(i) End If Next ' draw npc names For i = 1 To Npc_HighIndex If MapNpc(i).num > 0 Then Call DrawNpcName(i) End If Next For i = 1 To Action_HighIndex Call BltActionMsg(i) Next i ' Blit out map attributes If InMapEditor Then Call BltMapAttributes End If ' Draw map name Call DrawText(TexthDC, DrawMapNameX, DrawMapNameY, Map.Name, DrawMapNameColor) ' Release DC DDS_BackBuffer.ReleaseDC TexthDC ' Get rec With rec .top = Camera.top .Bottom = .top + ScreenY .Left = Camera.Left .Right = .Left + ScreenX End With ' rec_pos With rec_pos .Bottom = ((MAX_MAPY + 1) * PIC_Y) .Right = ((MAX_MAPX + 1) * PIC_X) End With ' Flip and render DX7.GetWindowRect frmMain.picScreen.hWnd, rec_pos DDS_Primary.Blt rec_pos, DDS_BackBuffer, rec, DDBLT_WAIT ' Error handler Exit Sub errorhandler: HandleError "Render_Graphics", "modDirectDraw7", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.Clear Exit Sub End Sub ```