Attribute VB_Name = "GameScreen"
'// Programmed by Ervin Louie B. Pe Benito
'// GameScreen.bas
'// GameScreen module
Option Explicit
Public DrawScreen As Long
Private onInventory As Boolean
Private onStats As Boolean
Public Autoframecount As Integer 'used in autoanimating the graphics in credits sceen
Public framecount As Integer
Public framewait As Integer
Public bEnablecontrol As Boolean
Public bFightWin As Boolean
Public iFightWinElement As Integer
Public bItemWin As Boolean
Public iItemWinElement As Integer
Public sFile As String
Public iEnemy As Integer
Public iMsgHelp As Integer
Public bPrayle As Boolean

Private bUserTurn As Boolean
Private bHelpOn As Boolean
Private lUTemp, lETemp As Long
Private BGameSolved As Boolean
'Draws the mainmenu
Public Sub DrawMainMenu()

    'Blit the screen
    ClearScreen
    RenderBegin

    'Draw Background
    
    Dev.SetTexture 0, Misc(2)
    Set_Vertex 0, 0, GameWidth, GameHeight, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    
    'Draw Logo
    Dev.SetTexture 0, Misc(3)
    Set_Vertex 146, 50, 357, 111, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    'Draw coded in vb Logo
    Dev.SetTexture 0, Misc(39)
    Set_Vertex GameWidth - 74, GameHeight - 74, 64, 64, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    'Draw coded in directX Logo
    Dev.SetTexture 0, Misc(40)
    Set_Vertex GameWidth - 74 - 74, GameHeight - 74, 64, 64, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    '***** Draw Menu Text *****
    
    'Set The Font Size
    setfont "Times New Roman", 20
    
    'On mouseover animation
    If MouseOver(262, 194, 117, 22) = True Then
        Draw_Text 213, 192, 223, 51, "NEW GAME", &HFFE5F904, DT_TOP Or DT_CENTER
    Else
        Draw_Text 213, 192, 223, 51, "NEW GAME", &HFFF00000, DT_TOP Or DT_CENTER
    End If
    If MouseOver(262, 220, 117, 22) = True Then
        Draw_Text 213, 220, 223, 51, "LOAD GAME", &HFFE5F904, DT_TOP Or DT_CENTER
    Else
        Draw_Text 213, 220, 223, 51, "LOAD GAME", &HFFF00000, DT_TOP Or DT_CENTER
    End If
    If MouseOver(262, 256, 117, 22) = True Then
        Draw_Text 213, 248, 223, 51, "HELP", &HFFE5F904, DT_TOP Or DT_CENTER
    Else
        Draw_Text 213, 248, 223, 51, "HELP", &HFFF00000, DT_TOP Or DT_CENTER
    End If
    If MouseOver(262, 282, 117, 22) = True Then
        Draw_Text 213, 276, 223, 51, "CREDITS", &HFFE5F904, DT_TOP Or DT_CENTER
    Else
        Draw_Text 213, 276, 223, 51, "CREDITS", &HFFF00000, DT_TOP Or DT_CENTER
    End If
    If MouseOver(262, 308, 117, 22) = True Then
        Draw_Text 213, 304, 223, 51, "QUIT", &HFFE5F904, DT_TOP Or DT_CENTER
    Else
        Draw_Text 213, 304, 223, 51, "QUIT", &HFFF00000, DT_TOP Or DT_CENTER
    End If

    'set back to the default font
    setfont "arial", 7
    'Copyright MSg
    Draw_Text 32, GameHeight - 40, 600, 200, "This Game is Freeware created by Ervin Games. Developed on August 2003, Modified on July 2004", &HFF000000, DT_TOP Or DT_LEFT
    Draw_Text 32, GameHeight - 30, 400, 200, "VB and DirectX are registered under Microsoft Corporation", &HFF000000, DT_TOP Or DT_LEFT
    If bDevMode = True Then
        'debug mouse position
        Draw_Text 500, 280, 100, 200, "FPS: " & FrameRate & " x:" & MousePos.x & " y:" & MousePos.y, &HFFFFFFFF, DT_BOTTOM Or DT_RIGHT
    End If
    'Blit The Custom Mouse Pointer

    Dev.SetTexture 0, Misc(1)
    Set_Vertex MousePos.x, MousePos.y, 16, 16, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    RenderEnd
    FlipScreen
End Sub

'Draws the character Screen
Public Sub DrawCharacterWin()

    'Blit the screen
    ClearScreen
    RenderBegin
    
    'Draw Background
    
    Dev.SetTexture 0, Misc(4)
    Set_Vertex 0, 0, GameWidth, GameHeight, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    Draw_Text 213, 50, 223, 51, "STORY", &HFF000000, DT_TOP Or DT_CENTER
        
    'On mouseover animation
    'left arrow
    If MouseOver(44, 395, 52, 32) = True Then
        'Draw the back arrow
        Dev.SetTexture 0, Misc(6)
        Set_Vertex 40, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Else
        'Draw the back arrow
        Dev.SetTexture 0, Misc(5)
        Set_Vertex 40, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    'right arrow
    If MouseOver(543, 395, 58, 32) = True Then
        'Draw the back arrow
        Dev.SetTexture 0, Misc(16)
        Set_Vertex GameWidth - 108, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Else
        'Draw the back arrow
        Dev.SetTexture 0, Misc(15)
        Set_Vertex GameWidth - 108, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    
    DrawInputBox 256, GameHeight - 64, 96, 24
    Draw_Text 192 + 24, GameHeight - 59, 223, 51, "NAME:", &HFF000000, DT_TOP Or DT_LEFT
    
    Draw_Text GameMapScreenX + 128, 96, 350, 280, " " & IntroMsg(1), &HFFAA5577, DT_TOP Or DT_LEFT Or DT_WORDBREAK
    Draw_Text GameMapScreenX + 128, 96 + 200, 350, 280, " " & IntroMsg(2), &HFFAA5577, DT_TOP Or DT_LEFT Or DT_WORDBREAK
    Draw_Text GameMapScreenX + 128, 96 + 276, 350, 280, " " & IntroMsg(3), &HFFFF0000, DT_TOP Or DT_LEFT Or DT_WORDBREAK
    
    'Blit The Custom Mouse Pointer

    Dev.SetTexture 0, Misc(1)
    Set_Vertex MousePos.x, MousePos.y, 16, 16, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    
    'set back to the default font
    setfont "arial", 7
    If bDevMode = True Then
        'debug purposes
        Draw_Text 500, 280, 100, 200, "FPS: " & FrameRate & " x:" & MousePos.x & " y:" & MousePos.y, &HFFFFFFFF, DT_BOTTOM Or DT_RIGHT
    End If
    RenderEnd
    FlipScreen
    
    If CheckAllKeys Then
        If GetKeyState(DIK_RETURN) Then
            Userchar.MapX = 64
                Userchar.MapY = 208
                Sound_Play 1
                MouseEnabled = False
                GameMap(1).enabled = True
                GameMap(2).enabled = False
                GameMap(3).enabled = False
                DrawScreen = 5
                Music_Stop 1
                Music_Start 3
                NewPlayer
        End If
    End If
End Sub

'Draws the HELP Screen
Public Sub DrawLoadWin()

    'Blit the screen
    ClearScreen
    RenderBegin
    
    'Draw Background
    
    Dev.SetTexture 0, Misc(4)
    Set_Vertex 0, 0, GameWidth, GameHeight, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    Dev.SetTexture 0, Misc(29)
    Set_Vertex 128 + 75, 128, 256, 256, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Draw_Text 213, 50, 223, 51, "LOAD MENU", &HFF000000, DT_TOP Or DT_CENTER
    
    DrawInputBoxLoadWin 256 + 32, 96, 96, 24
    
    Draw_Text 128 + 75, 96, 200, 200, "Load Save #", &HFF000000, DT_TOP Or DT_LEFT
    
    ListSaves 144, 128 + 16
    
    'On mouseover animation
    If MouseOver(44, 395, 52, 32) = True Then
        'Draw the back arrow
        Dev.SetTexture 0, Misc(6)
        Set_Vertex 40, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Else
        'Draw the back arrow
        Dev.SetTexture 0, Misc(5)
        Set_Vertex 40, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    'button for load game
    If MouseOver(256 + 128 + 16, 96 - 8, 50, 10) Then
        Draw_Text 256 + 128 + 16, 96 - 8, 100, 100, "Load Game", &HFFFF0000, DT_TOP Or DT_LEFT
    Else
        Draw_Text 256 + 128 + 16, 96 - 8, 100, 100, "Load Game", &HFF000000, DT_TOP Or DT_LEFT
    End If
    'button for delete game
    If MouseOver(256 + 128 + 16, 96 + 12, 50, 10) Then
        Draw_Text 256 + 128 + 16, 96 + 12, 100, 100, "Delete Game", &HFFFF0000, DT_TOP Or DT_LEFT
    Else
        Draw_Text 256 + 128 + 16, 96 + 12, 100, 100, "Delete Game", &HFF000000, DT_TOP Or DT_LEFT
    End If
    '*** miscellaneous blitting
    'Blit The Custom Mouse Pointer

    Dev.SetTexture 0, Misc(1)
    Set_Vertex MousePos.x, MousePos.y, 16, 16, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))

    'set back to the default font
    setfont "arial", 8
    
    If bDevMode = True Then
        Draw_Text 500, 280, 100, 200, "FPS: " & FrameRate & " x:" & MousePos.x & " y:" & MousePos.y, &HFFFFFFFF, DT_BOTTOM Or DT_RIGHT
    End If
    RenderEnd
    FlipScreen
    If CheckAllKeys Then
        If GetKeyState(DIK_RETURN) Then
            If Val(sFile) > 0 And Val(sFile) < Filenum + 1 Then
                LoadPlayer files(Val(sFile))
                DrawScreen = 16
            End If
        End If
    End If
End Sub

'Draws the Credits Screen
Public Sub DrawCreditsWin()
    'Blit the screen
    ClearScreen
    RenderBegin
    
    'Draw Background
    
    Dev.SetTexture 0, Misc(4)
    Set_Vertex 0, 0, GameWidth, GameHeight, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    Draw_Text 213, 50, 223, 51, "CREDITS", &HFF000000, DT_TOP Or DT_CENTER
    Draw_Text 213, 120, 230, 51, "DESIGNED AND PROGRAMMED BY:", &HFF000000, DT_TOP Or DT_CENTER
    Draw_Text 213, 160, 230, 51, "ERVIN LOUIE B. PE BENITO", &HFF000000, DT_TOP Or DT_CENTER
    
    'On mouseover animation
    If MouseOver(44, 395, 52, 32) = True Then
        'Draw the back arrow
        Dev.SetTexture 0, Misc(6)
        Set_Vertex 40, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Else
        'Draw the back arrow
        Dev.SetTexture 0, Misc(5)
        Set_Vertex 40, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    
    'Draw the first animated sprite
    autoAnimate0
    Set_Vertex 227, 140, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'Draw the 2nd animated sprite
    autoAnimate1
    Set_Vertex 393, 141, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    'Draw the mouse
    Dev.SetTexture 0, Misc(1)
    Set_Vertex MousePos.x, MousePos.y, 16, 16, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))

    'set back to the default font
    setfont "arial", 8
    If bDevMode = True Then
        Draw_Text 500, 280, 100, 200, "FPS: " & FrameRate & " x:" & MousePos.x & " y:" & MousePos.y, &HFFFFFFFF, DT_BOTTOM Or DT_RIGHT
    End If
    RenderEnd
    FlipScreen
End Sub
'Draw Stage Screen
Public Sub DrawStageWin(iMapWin As Integer)
    'Blit the screen
    ClearScreen
    RenderBegin
    
    'Draws the map
    Drawmap iMapWin
    
    iLastStage = DrawScreen
    'used in moving down
    If Userchar.Direction = 0 Then
        If bMoving = True Then
            If framecount > framewait Then
                CharMoveDown iMapWin
                Userchar.AnimCount = Userchar.AnimCount + 1
                If Userchar.AnimCount > Userchar.AnimMax Then Userchar.AnimCount = 1
                framecount = 1
            Else
                framecount = framecount + 1
            End If
        End If
        Animate0
        Set_Vertex Userchar.MapX, Userchar.MapY, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    'used in moving up
    If Userchar.Direction = 3 Then
        If bMoving = True Then
            If framecount > framewait Then
                CharMoveUp iMapWin
                Userchar.AnimCount = Userchar.AnimCount + 1
                If Userchar.AnimCount > Userchar.AnimMax Then Userchar.AnimCount = 1
                framecount = 1
            Else
                framecount = framecount + 1
            End If
        End If
        Animate3
        Set_Vertex Userchar.MapX, Userchar.MapY, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    'used in moving right
    If Userchar.Direction = 1 Then
        'movement
        If bMoving = True Then
            If framecount > framewait Then
                CharMoveRight iMapWin
                Userchar.AnimCount = Userchar.AnimCount + 1
                If Userchar.AnimCount > Userchar.AnimMax Then Userchar.AnimCount = 1
                framecount = 1
            Else
                framecount = framecount + 1
            End If
        End If
        Animate1
        Set_Vertex Userchar.MapX, Userchar.MapY, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    'used in moving left
    If Userchar.Direction = 2 Then
        If bMoving = True Then
            If framecount > framewait Then
                CharMoveLeft iMapWin
                Userchar.AnimCount = Userchar.AnimCount + 1
                If Userchar.AnimCount > Userchar.AnimMax Then Userchar.AnimCount = 1
                framecount = 1
            Else
                framecount = framecount + 1
            End If
        End If
        Animate2
        Set_Vertex Userchar.MapX, Userchar.MapY, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    
    If bMoving = True Then
        If BattleDeterminer = True Then
                iEnemy = CInt(Rnd() * 12) + 1
                If iMapWin = 1 Then
                    iEnemy = 0
                ElseIf iMapWin = 2 Then
                    If iEnemy < 9 Then
                        iEnemy = 0
                    Else
                        iEnemy = 1
                    End If
                ElseIf iMapWin = 3 Then
                    If iEnemy < 5 Then
                        iEnemy = 0
                    ElseIf iEnemy < 9 Then
                        iEnemy = 1
                    Else
                        iEnemy = 2
                    End If
                ElseIf iMapWin = 4 Then
                    If iEnemy < 4 Then
                        iEnemy = 0
                    ElseIf iEnemy < 8 Then
                        iEnemy = 1
                    ElseIf iEnemy < 10 Then
                        iEnemy = 2
                    Else
                        iEnemy = 3
                    End If
                ElseIf iMapWin = 5 Then
                    If iEnemy < 4 Then
                        iEnemy = 0
                    ElseIf iEnemy < 7 Then
                        iEnemy = 1
                    ElseIf iEnemy < 9 Then
                        iEnemy = 2
                    Else
                        iEnemy = 3
                    End If
                ElseIf iMapWin = 5 Then
                    If iEnemy < 5 Then
                        iEnemy = 1
                    ElseIf iEnemy < 9 Then
                        iEnemy = 2
                    Else
                        iEnemy = 3
                    End If
                ElseIf iMapWin = 6 Then
                    If iEnemy < 3 Then
                        iEnemy = 1
                    ElseIf iEnemy < 6 Then
                        iEnemy = 2
                    Else
                        iEnemy = 3
                    End If
                End If
                
                tempstats.Agility = EnemyStats(iEnemy).Agility
                tempstats.Armor = EnemyStats(iEnemy).Armor
                tempstats.Damage = EnemyStats(iEnemy).Damage
                tempstats.Dexterity = EnemyStats(iEnemy).Dexterity
                tempstats.MaxLife = EnemyStats(iEnemy).MaxLife
                tempstats.Life = EnemyStats(iEnemy).MaxLife
                tempstats.Belt = EnemyStats(iEnemy).Belt
                tempstats.ItemCount = EnemyStats(iEnemy).ItemCount
                tempstats.ExperienceEarn = EnemyStats(iEnemy).ExperienceEarn
                tempstats.MoneyEarn = EnemyStats(iEnemy).MoneyEarn
                tempstats.Name = EnemyStats(iEnemy).Name
                bUserTurn = FirstMoveDeterminer
                DrawScreen = 6
                Music_Stop 3
                Music_Start 4
        End If
    End If
    'This will Draw the stage Frame
    DrawFrame
    'draws the belt
    Dev.SetTexture 0, Misc(26)
    Set_Vertex 33, 33, 128, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    Draw_Text 286, 16, 120, 200, "F5 - QUIT w/o Saving", &HFFFFFFFF, DT_TOP Or DT_LEFT

    'checks if stats is on or if user is quiting
    
    If onStats = True Then
        Draw_Text 160, 16, 120, 200, "F4 - CLOSE STATS", &HFFFFFFFF, DT_TOP Or DT_LEFT
        'update stats
        onFightWin GameMapScreenX, GameMapScreenY, 160, 128 + 32
        Draw_Text GameMapScreenX + 16, GameMapScreenY + 16, 120, 200, PlayerStats.Name & "STATS", &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 24, GameMapScreenY + 32, 120, 200, "STR: " & PlayerStats.Strength, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 96, GameMapScreenY + 32, 120, 200, "EXPERIENCE:", &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 24, GameMapScreenY + 32 + 16, 120, 200, "VIT: " & PlayerStats.Vitality, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 96, GameMapScreenY + 32 + 16, 120, 200, "  " & PlayerStats.Experience, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 24, GameMapScreenY + 32 + 32, 120, 200, "DEX: " & PlayerStats.Dexterity, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 96, GameMapScreenY + 32 + 32, 120, 200, "NEXT LEVEL:", &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 24, GameMapScreenY + 64 + 16, 120, 200, "AGI: " & PlayerStats.Agility, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 96, GameMapScreenY + 64 + 16, 120, 200, "  " & PlayerStats.nextExperience, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 24, GameMapScreenY + 96, 120, 200, "DMG: " & PlayerStats.Damage, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 96, GameMapScreenY + 96, 120, 200, "LVL: " & PlayerStats.Level, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 24, GameMapScreenY + 96 + 16, 120, 200, "HP: " & PlayerStats.Life, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 96, GameMapScreenY + 96 + 16, 120, 200, "KILLS: " & PlayerStats.Kills, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 24, GameMapScreenY + 128, 120, 200, "AP: " & PlayerStats.Armor, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 96, GameMapScreenY + 128, 120, 200, "CASH: " & PlayerStats.Money, &HFF900000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 24, GameMapScreenY + 128 + 16, 150, 200, "Press 1 - 4 to use an item", &HFFFF0000, DT_TOP Or DT_LEFT
    Else
        Draw_Text 160, 16, 120, 200, "F3 - STATS", &HFFFFFFFF, DT_TOP Or DT_LEFT
    End If

    'set back to the default font
    setfont "arial", 8
    If bDevMode = True Then
        Draw_Text GameWidth - 100, 12, 100, 200, "FPS: " & FrameRate & " x:" & MousePos.x & " y:" & MousePos.y, &HFFFFFFFF, DT_TOP Or DT_RIGHT
    End If
    Refreshbelt
    If bHelpOn = True Then
        Draw_Text 33, 16, 120, 200, "F2 - CLOSE HELP", &HFFFFFFFF, DT_TOP Or DT_LEFT
        HelpInGameMsg
    Else
        Draw_Text 33, 16, 120, 200, "F1 - HELP", &HFFFFFFFF, DT_TOP Or DT_LEFT
    End If
    'check if tile is hotspot
    CheckBehavior Userchar.Direction, iMapWin
    RenderEnd
    FlipScreen
    'checking menu keys
    If CheckAllKeys = True Then
        If GetKeyState(DIK_F1) And onStats = False Then
                bHelpOn = True
                bMoving = False
                bEnablecontrol = False
        ElseIf GetKeyState(DIK_F2) And onStats = False Then
                bHelpOn = False
                bEnablecontrol = True
        ElseIf GetKeyState(DIK_F3) And bHelpOn = False Then
                onStats = True
                bEnablecontrol = False
                bMoving = False
        ElseIf GetKeyState(DIK_F4) And bHelpOn = False Then
                onStats = False
                bEnablecontrol = True
        ElseIf GetKeyState(DIK_F5) And bHelpOn = False And onStats = False Then
                Returntomain
        ElseIf onStats = True Then
            If GetKeyState(DIK_1) Then
                If PlayerBelt.Slot(0) <> 0 Then
                    PlayerUseItem 0
                    PlayerBelt.Slot(0) = 0
                    Sound_Play 7
                End If
            ElseIf GetKeyState(DIK_2) Then
                If PlayerBelt.Slot(1) <> 0 Then
                    PlayerUseItem 1
                    PlayerBelt.Slot(1) = 0
                    Sound_Play 7
                End If
            ElseIf GetKeyState(DIK_3) Then
                If PlayerBelt.Slot(2) <> 0 Then
                    PlayerUseItem 2
                    PlayerBelt.Slot(2) = 0
                    Sound_Play 7
                End If
            ElseIf GetKeyState(DIK_4) Then
                If PlayerBelt.Slot(3) <> 0 Then
                    PlayerUseItem 3
                    PlayerBelt.Slot(3) = 0
                    Sound_Play 7
                End If
            End If
       ElseIf bEnablecontrol = True Then
            If GetKeyState(DIK_DOWN) Then
                Userchar.Direction = 0
                bMoving = True
            ElseIf GetKeyState(DIK_RIGHT) Then
                Userchar.Direction = 1
                bMoving = True
            ElseIf GetKeyState(DIK_LEFT) Then
                Userchar.Direction = 2
                bMoving = True
            ElseIf GetKeyState(DIK_UP) Then
                Userchar.Direction = 3
                bMoving = True
            Else
            bMoving = False
            End If
        End If
    End If
    
End Sub

Public Sub DrawFrame()
Dim lNum As Long
    'Draw the corners
    'upperleft
    Dev.SetTexture 0, Misc(7)
    Set_Vertex 0, 33, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'upperright
    Dev.SetTexture 0, Misc(9)
    Set_Vertex GameWidth - 32, 33, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'lowerleft
    Dev.SetTexture 0, Misc(12)
    Set_Vertex 0, GameHeight - 32, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'lowerright
    Dev.SetTexture 0, Misc(14)
    Set_Vertex GameWidth - 32, GameHeight - 32, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    'Draw the horizontal line
    'Draw the upperhorizontal line
    For lNum = 32 To GameWidth - 64 Step 32
        Dev.SetTexture 0, Misc(8)
        Set_Vertex lNum, 33, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Next
    'Draw the lowerhorizontal line
    For lNum = 32 To GameWidth - 64 Step 32
        Dev.SetTexture 0, Misc(13)
        Set_Vertex lNum, GameHeight - 32, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Next
    'draw the vertical lines
    'draws the leftvertical line
    For lNum = 64 To GameHeight - 64 Step 32
        Dev.SetTexture 0, Misc(10)
        Set_Vertex 0, lNum, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Next
    'draw the rightvertical line
    For lNum = 64 To GameHeight - 64 Step 32
        Dev.SetTexture 0, Misc(11)
        Set_Vertex GameWidth - 32, lNum, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Next
    
    Dev.SetTexture 0, Misc(31)
    Set_Vertex 160, 40, 64, 16, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    Draw_Text 176, 41, 100, 200, " " & PlayerStats.Money, &HFF000000, DT_TOP Or DT_LEFT
End Sub

Private Sub Returntomain()
    ReDim files(1)
    Filenum = 0
    Music_Stop 3
    Music_Start 1
    MouseEnabled = True
    DrawScreen = 1
End Sub

Public Sub FightScreen(Optional iScreenNum As Integer = 1, Optional bBattle As Boolean = True)
Dim sName, sDesc As String
Dim itemp As Integer
Dim bTemp As Boolean
Static inputdelay As Integer
Static ActionControl, lCount, MsgDelay, UserAttackDelay, AttackDelay, EnemyDelay As Long
Static bHelpFightWin, bEnemyKilled, bUserKilled, bHitd, bEscapeMsg, bAnimDlay, BAIControl As Boolean
    ClearScreen
    RenderBegin
    'draw the stage frame
    DrawFrame
    'draws the belt
    Dev.SetTexture 0, Misc(26)
    Set_Vertex 33, 33, 128, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    If bUserTurn = True Then
        If bUserKilled Then
            Music_Stop 4
            If iLastStage = 5 Then
                Music_Start 3
            ElseIf iLastStage = 8 Then
                Music_Start 5
            ElseIf iLastStage = 9 Then
                Music_Start 6
            ElseIf iLastStage = 10 Then
                Music_Start 7
            ElseIf iLastStage = 11 Then
                Music_Start 8
            ElseIf iLastStage = 12 Then
                Music_Start 3
            End If
            bUserKilled = False
            DrawScreen = 14
        End If
        bFightWin = True
        BAIControl = False
        bHitd = HitDeterminer(PlayerStats.Agility)
        
    Else
        If UserFightChar.Status <> 0 And UserAttackDelay < 20 Then
            UserAttackDelay = UserAttackDelay + 1
        Else
            UserAttackDelay = 0
            UserFightChar.Status = 0
            EnemyChar(iEnemy).Status = 0
        'DRaw the post fight screen
            If bEnemyKilled Then
                Music_Stop 4
                If iLastStage = 5 Then
                    Music_Start 3
                ElseIf iLastStage = 8 Then
                    Music_Start 5
                ElseIf iLastStage = 9 Then
                    Music_Start 6
                ElseIf iLastStage = 10 Then
                    Music_Start 7
                ElseIf iLastStage = 11 Then
                    Music_Start 8
                ElseIf iLastStage = 12 Then
                    Music_Start 3
                End If
                bEnemyKilled = False
                DrawScreen = 14
                lSkillPoints = LevelUpPoints
            End If
        End If
        bFightWin = False
        If BAIControl = False Then
            ImplementAI
            BAIControl = True
        End If
        If (EnemyDelay > 60 Or bAnimDlay = True) And tempstats.Life > 0 Then
            If EnemyMove = Attack Then
                If bHitd = True Then
                    EnemyChar(iEnemy).Status = 1
                    UserFightChar.Status = 2
                    bAnimDlay = True
                        If AttackDelay > 15 Then
                            bAnimDlay = False
                            bUserTurn = True
                            UserFightChar.Status = 0
                            EnemyChar(iEnemy).Status = 0
                            AttackDelay = 0
                            lETemp = DamageTakenDeterminer(tempstats.Damage, PlayerStats.Armor)
                            If lETemp < 1 Then
                                lETemp = 1
                            End If
                            PlayerStats.Life = PlayerStats.Life - lETemp
                            If PlayerStats.Life < 1 Then bUserKilled = True
                        Else
                            AttackDelay = AttackDelay + 1
                        End If
                Else
                    EnemyChar(iEnemy).Status = 1
                    UserFightChar.Status = 4
                    bAnimDlay = True
                        If AttackDelay > 15 Then
                            bAnimDlay = False
                            bUserTurn = True
                            UserFightChar.Status = 0
                            EnemyChar(iEnemy).Status = 0
                            AttackDelay = 0
                        Else
                            AttackDelay = AttackDelay + 1
                        End If
                End If
            End If
            If EnemyMove = Useitem Then
                EnemyChar(iEnemy).Status = 3
                bAnimDlay = True
                    If AttackDelay > 15 Then
                        bAnimDlay = False
                        bUserTurn = True
                        EnemyChar(iEnemy).Status = 0
                        AttackDelay = 0
                        HealEffect
                    Else
                        AttackDelay = AttackDelay + 1
                    End If
            End If
            EnemyDelay = 0
        Else
            EnemyDelay = EnemyDelay + 1
        End If
    End If
    'draw the fightscreenbackground
    If iScreenNum = 1 Then
        Dev.SetTexture 0, SceneBackground(1)
        Set_Vertex GameMapScreenX + 128, GameMapScreenY + 96, 320, 160, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    ElseIf iScreenNum = 2 Then
        Dev.SetTexture 0, SceneBackground(2)
        Set_Vertex GameMapScreenX + 160, GameMapScreenY + 96, 320, 168, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    'display enemy stats
        onFightWin GameMapScreenX + 450, GameMapScreenY + 128, 96, 32
        Draw_Text GameMapScreenX + 450 + 16, GameMapScreenY + 128 + 8, 100, 200, tempstats.Name, &HFFA55555, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 450 + 16, GameMapScreenY + 128 + 24, 100, 200, "HP: " & tempstats.Life & "/" & tempstats.MaxLife, &HFFA55555, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 450 + 16, GameMapScreenY + 128 + 24 + 16, 100, 200, "DMG: " & tempstats.Damage, &HFFA55555, DT_TOP Or DT_LEFT
    'display User stats
        onFightWin GameMapScreenX, GameMapScreenY + 128, 96, 32
        Draw_Text GameMapScreenX + 16, GameMapScreenY + 128 + 8, 100, 200, PlayerStats.Name, &HFF5555A5, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 16, GameMapScreenY + 128 + 24, 100, 200, "HP: " & PlayerStats.Life & "/" & PlayerStats.LifeMax, &HFF5555A5, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 16, GameMapScreenY + 128 + 24 + 16, 100, 200, "DMG: " & PlayerStats.Damage, &HFF5555A5, DT_TOP Or DT_LEFT
        
    'If user status is idle
    If UserFightChar.Status = 0 Then
        UserFightAnimate
    'if user is attacking
    ElseIf UserFightChar.Status = 1 Then
        UserFightAnimate 1
    'if user has been attacked
    ElseIf UserFightChar.Status = 2 Then
        UserFightAnimate 2
        Draw_Text (GameMapScreenWidth / 2) - 64, GameMapScreenY + 64, 300, 200, "You have been hit with " & lETemp & " Damage", &HFFFF5555, DT_TOP Or DT_LEFT
    'if user heals himself
    ElseIf UserFightChar.Status = 3 Then
        UserFightAnimate 3
    'if user has managed to avoid an attack
    ElseIf UserFightChar.Status = 4 Then
        UserFightAnimate 4
    End If
    
    'if enemy status is idle
    If EnemyChar(iEnemy).Status = 0 Then
        EnemyFightAnimate iEnemy, 0
   'if enemy is attacking
    ElseIf EnemyChar(iEnemy).Status = 1 Then
        EnemyFightAnimate iEnemy, 1
    'if enemy is attacked
    ElseIf EnemyChar(iEnemy).Status = 2 Then
        EnemyFightAnimate iEnemy, 2
        Draw_Text (GameMapScreenWidth / 2) - 64, GameMapScreenY + 64, 300, 200, "You hit the enemy with " & lUTemp & " Damage", &HFF5555FF, DT_TOP Or DT_LEFT
    'if enemy is healing
    ElseIf EnemyChar(iEnemy).Status = 3 Then
        EnemyFightAnimate iEnemy, 3
    'if enemy has managed to avoid the attack
    ElseIf EnemyChar(iEnemy).Status = 4 Then
        EnemyFightAnimate iEnemy, 4
    End If
    
    If bFightWin = True Then
        onFightWin GameMapScreenX + 160, GameMapScreenY + 256, 64, 64
        
        Draw_Text GameMapScreenX + 184, GameMapScreenY + 272, 100, 200, "ATTACK", &HFF000000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 184, GameMapScreenY + 288, 100, 200, "ITEM", &HFF000000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 184, GameMapScreenY + 304, 100, 200, "RETREAT", &HFF000000, DT_TOP Or DT_LEFT

        If iFightWinElement = 0 Then
            Draw_Text GameMapScreenX + 178, GameMapScreenY + 272, 100, 200, ">", &HFFFF0000, DT_TOP Or DT_LEFT
        Else
            Draw_Text GameMapScreenX + 178, GameMapScreenY + 272, 100, 200, " ", &HFF000000, DT_TOP Or DT_LEFT
        End If
        If iFightWinElement = 1 Then
            Draw_Text GameMapScreenX + 178, GameMapScreenY + 288, 100, 200, ">", &HFFFF0000, DT_TOP Or DT_LEFT
        Else
            Draw_Text GameMapScreenX + 178, GameMapScreenY + 288, 100, 200, " ", &HFF000000, DT_TOP Or DT_LEFT
        End If
        If iFightWinElement = 2 Then
            Draw_Text GameMapScreenX + 178, GameMapScreenY + 304, 100, 200, ">", &HFFFF0000, DT_TOP Or DT_LEFT
        Else
            Draw_Text GameMapScreenX + 178, GameMapScreenY + 304, 100, 200, " ", &HFF000000, DT_TOP Or DT_LEFT
        End If
        'If iFightWinElement = 3 Then
            'Draw_Text GameMapScreenX + 178, GameMapScreenY + 320, 100, 200, ">", &HFFFF0000, DT_TOP Or DT_LEFT
        'Else
            'Draw_Text GameMapScreenX + 178, GameMapScreenY + 320, 100, 200, " ", &HFF000000, DT_TOP Or DT_LEFT
        'End If
    End If
        
    If bItemWin = True Then
        onFightWin GameMapScreenX + 224 + 32, GameMapScreenY + 256 + 16, 96, 64
        'displays item names during a fight
        'belt 1 "slot is a zero based array
        If PlayerBelt.Slot(0) <> 0 Then
            For itemp = 1 To 9
                If PlayerBelt.Slot(0) = itemp Then sName = GameItem(itemp).ItemName
            Next
            Draw_Text GameMapScreenX + 184 + 96, GameMapScreenY + 272 + 16, 100, 200, " " & sName, &HFF000000, DT_TOP Or DT_LEFT
        Else
            Draw_Text GameMapScreenX + 184 + 96, GameMapScreenY + 272 + 16, 100, 200, "<empty>", &HFFAAAAAA, DT_TOP Or DT_LEFT
        End If
        'belt 2
        If PlayerBelt.Slot(1) <> 0 Then
            For itemp = 1 To 9
                If PlayerBelt.Slot(1) = itemp Then sName = GameItem(itemp).ItemName
            Next
            Draw_Text GameMapScreenX + 184 + 96, GameMapScreenY + 288 + 16, 100, 200, " " & sName, &HFF000000, DT_TOP Or DT_LEFT
        Else
            Draw_Text GameMapScreenX + 184 + 96, GameMapScreenY + 288 + 16, 100, 200, "<empty>", &HFFAAAAAA, DT_TOP Or DT_LEFT
        End If
        'belt 3
        If PlayerBelt.Slot(2) <> 0 Then
            For itemp = 1 To 9
                If PlayerBelt.Slot(2) = itemp Then sName = GameItem(itemp).ItemName
            Next
            Draw_Text GameMapScreenX + 184 + 96, GameMapScreenY + 304 + 16, 100, 200, " " & sName, &HFF000000, DT_TOP Or DT_LEFT
        Else
        Draw_Text GameMapScreenX + 184 + 96, GameMapScreenY + 304 + 16, 100, 200, "<empty>", &HFFAAAAAA, DT_TOP Or DT_LEFT
        End If
        'belt 4
        If PlayerBelt.Slot(3) <> 0 Then
            For itemp = 1 To 9
                If PlayerBelt.Slot(3) = itemp Then sName = GameItem(itemp).ItemName
            Next
                Draw_Text GameMapScreenX + 184 + 96, GameMapScreenY + 320 + 16, 100, 200, " " & sName, &HFF000000, DT_TOP Or DT_LEFT
        Else
        Draw_Text GameMapScreenX + 184 + 96, GameMapScreenY + 320 + 16, 100, 200, "<empty>", &HFFAAAAAA, DT_TOP Or DT_LEFT
        End If
        If iItemWinElement = 0 Then
            Draw_Text GameMapScreenX + 178 + 96, GameMapScreenY + 272 + 16, 100, 200, ">", &HFFFF0000, DT_TOP Or DT_LEFT
            If PlayerBelt.Slot(0) <> 0 Then
                For itemp = 1 To 9
                    If PlayerBelt.Slot(0) = itemp Then sDesc = GameItem(itemp).ItemDesc
                Next
                Draw_Text 213, GameMapScreenY + 80, 223, 51, " " & sDesc, &HFF00FF00, DT_TOP Or DT_CENTER
            End If
        Else
            Draw_Text GameMapScreenX + 178 + 96, GameMapScreenY + 272 + 16, 100, 200, " ", &HFF000000, DT_TOP Or DT_LEFT
        End If
        If iItemWinElement = 1 Then
            Draw_Text GameMapScreenX + 178 + 96, GameMapScreenY + 288 + 16, 100, 200, ">", &HFFFF0000, DT_TOP Or DT_LEFT
            If PlayerBelt.Slot(1) <> 0 Then
                For itemp = 1 To 9
                    If PlayerBelt.Slot(1) = itemp Then sDesc = GameItem(itemp).ItemDesc
                Next
                Draw_Text 213, GameMapScreenY + 80, 223, 51, " " & sDesc, &HFF00FF00, DT_TOP Or DT_CENTER
            End If
        Else
            Draw_Text GameMapScreenX + 178 + 96, GameMapScreenY + 288 + 16, 100, 200, " ", &HFF000000, DT_TOP Or DT_LEFT
        End If
        If iItemWinElement = 2 Then
            Draw_Text GameMapScreenX + 178 + 96, GameMapScreenY + 304 + 16, 100, 200, ">", &HFFFF0000, DT_TOP Or DT_LEFT
            If PlayerBelt.Slot(2) <> 0 Then
                For itemp = 1 To 9
                    If PlayerBelt.Slot(2) = itemp Then sDesc = GameItem(itemp).ItemDesc
                Next
                Draw_Text 213, GameMapScreenY + 80, 223, 51, " " & sDesc, &HFF00FF00, DT_TOP Or DT_CENTER
            End If
        Else
            Draw_Text GameMapScreenX + 178 + 96, GameMapScreenY + 304 + 16, 100, 200, " ", &HFF000000, DT_TOP Or DT_LEFT
        End If
        If iItemWinElement = 3 Then
            Draw_Text GameMapScreenX + 178 + 96, GameMapScreenY + 320 + 16, 100, 200, ">", &HFFFF0000, DT_TOP Or DT_LEFT
            If PlayerBelt.Slot(3) <> 0 Then
                For itemp = 1 To 9
                    If PlayerBelt.Slot(3) = itemp Then sDesc = GameItem(itemp).ItemDesc
                Next
                Draw_Text 213, GameMapScreenY + 80, 223, 51, " " & sDesc, &HFF00FF00, DT_TOP Or DT_CENTER
            End If
        Else
            Draw_Text GameMapScreenX + 178 + 96, GameMapScreenY + 320 + 16, 100, 200, " ", &HFF000000, DT_TOP Or DT_LEFT
        End If
        
    Else
        offFightWin GameMapScreenX + 224 + 32, GameMapScreenY + 256 + 16, 64, 64
    End If
    
    Refreshbelt
    If bDevMode = True Then
        'show hit chance varaiable
        Draw_Text 5, 5, 100, 100, " " & CStr(bHitd), &HFF00AA00, DT_TOP Or DT_LEFT
        'show fps info
        Draw_Text GameWidth - 100, 12, 100, 200, "FPS: " & FrameRate & " x:" & MousePos.x & " y:" & MousePos.y, &HFFFFFFFF, DT_TOP Or DT_RIGHT
        Draw_Text GameWidth - 100, 12 + 16, 100, 200, " " & iItemWinElement, &HFFFFFFFF, DT_TOP Or DT_RIGHT
        Draw_Text GameWidth - 100, 12 + 32, 100, 200, " " & PlayerBelt.Slot(iItemWinElement), &HFFFFFFFF, DT_TOP Or DT_RIGHT
        Draw_Text GameWidth - 100, 12 + 32 + 16, 100, 200, " " & PlayerStats.Life & "/" & PlayerStats.LifeMax, &HFFFFFFFF, DT_TOP Or DT_RIGHT
    End If
    'In game messages
    If bEscapeMsg = True Then
        Draw_Text (GameMapScreenWidth / 2), GameMapScreenY + 64, 100, 200, "Unable to Retreat", &HFF00F000, DT_TOP Or DT_LEFT
        If MsgDelay = 0 Then
            Sound_Play 12
        End If
        If MsgDelay < 20 Then
            MsgDelay = MsgDelay + 1
        Else
            MsgDelay = 0
            bEscapeMsg = False
        End If
    End If
    If bHelpFightWin Then
        HelpFightGameMsg
        Draw_Text 33, 16, 120, 200, "F2 - CLOSE HELP", &HFFFFFFFF, DT_TOP Or DT_LEFT
    Else
        Draw_Text 33, 16, 120, 200, "F1 - HELP", &HFFFFFFFF, DT_TOP Or DT_LEFT
    End If
    RenderEnd
    FlipScreen
If bUserTurn = True Then
    If inputdelay < 1 Then
        If CheckAllKeys Then
            If GetKeyState(DIK_F1) Then
                bHelpFightWin = True
            ElseIf GetKeyState(DIK_F2) And bHelpFightWin = True Then
                bHelpFightWin = False
            End If
            If bFightWin = True And GetKeyState(DIK_UP) And bItemWin = False And bHelpFightWin = False Then
                iFightWinElement = iFightWinElement - 1
                If iFightWinElement < 0 Then iFightWinElement = 2
                inputdelay = 7
            ElseIf bFightWin = True And GetKeyState(DIK_DOWN) And bItemWin = False And bHelpFightWin = False Then
                iFightWinElement = iFightWinElement + 1
                If iFightWinElement > 2 Then iFightWinElement = 0
                inputdelay = 7
            ElseIf GetKeyState(DIK_RETURN) And bHelpFightWin = False Then
                If bFightWin = True And iFightWinElement = 0 Then
                    bTemp = HitDeterminer(tempstats.Agility)
                    If bTemp = True Then
                        UserFightChar.Status = 1
                        EnemyChar(iEnemy).Status = 2
                        inputdelay = 7
                        UserAttackDelay = 0
                        bUserTurn = False
                        bFightWin = False
                        lUTemp = DamageTakenDeterminer(PlayerStats.Damage, tempstats.Armor)
                        If lUTemp < 1 Then
                            lUTemp = 1
                        End If
                        tempstats.Life = tempstats.Life - lUTemp
                        If tempstats.Life <= 0 Then
                            bEnemyKilled = True
                        End If
                    Else
                        UserFightChar.Status = 1
                        EnemyChar(iEnemy).Status = 4
                        inputdelay = 7
                        UserAttackDelay = 0
                        bUserTurn = False
                        bFightWin = False
                    End If
                ElseIf bFightWin = True And iFightWinElement = 1 Then
                    bItemWin = True
                    inputdelay = 7
                ElseIf bFightWin = True And iFightWinElement = 2 Then
                    bTemp = RetreatDeterminer()
                    If bTemp = True Then
                        bBattle = False
                    Else
                        bUserTurn = False
                        bEscapeMsg = True
                    End If
                End If
            ElseIf bItemWin = True And GetKeyState(DIK_RSHIFT) And bHelpFightWin = False Then
                If PlayerStats.Life < PlayerStats.LifeMax And PlayerBelt.Slot(iItemWinElement) <> 0 Then
                    PlayerUseItem iItemWinElement
                    UserAttackDelay = 0
                    UserFightChar.Status = 3
                    PlayerBelt.Slot(iItemWinElement) = 0
                    bUserTurn = False
                    inputdelay = 7
                End If
            ElseIf bItemWin = True And GetKeyState(DIK_LEFT) And bHelpFightWin = False Then
                bItemWin = False
                inputdelay = 7
            ElseIf bItemWin = True And GetKeyState(DIK_UP) And bHelpFightWin = False Then
                iItemWinElement = iItemWinElement - 1
                If iItemWinElement < 0 Then iItemWinElement = 3
                inputdelay = 7
            ElseIf bItemWin = True And GetKeyState(DIK_DOWN) And bHelpFightWin = False Then
                iItemWinElement = iItemWinElement + 1
                If iItemWinElement > 3 Then iItemWinElement = 0
                inputdelay = 7
            End If
        End If
    Else
        inputdelay = inputdelay - 1
    End If
    If bBattle = False Then
        Music_Stop 4
        If iLastStage = 5 Then
            Music_Start 3
        ElseIf iLastStage = 8 Then
            Music_Start 5
        ElseIf iLastStage = 9 Then
            Music_Start 6
        End If
        DrawScreen = iLastStage
    End If
    'used to elimate a minor bug
    lETemp = DamageTakenDeterminer(tempstats.Damage, PlayerStats.Armor)
End If
End Sub

Public Sub onFightWin(lx As Long, ly As Long, lwidth As Long, lheight As Long)
Dim lNum, lnumo As Integer
    lwidth = lx + lwidth
    lheight = ly + lheight
   For lNum = lx To lwidth Step 32
        For lnumo = ly To lheight Step 32
            Dev.SetTexture 0, Misc(21)
            Set_Vertex lNum, lnumo, 32, 32, 16777215, 16777215, 16777215, 16777215
            Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        Next
   Next
   'upperleft
    Dev.SetTexture 0, Misc(17)
    Set_Vertex lx, ly, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'upperright
    Dev.SetTexture 0, Misc(19)
    Set_Vertex lwidth, ly, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'lowerleft
    Dev.SetTexture 0, Misc(23)
    Set_Vertex lx, lheight, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'lowerright
    Dev.SetTexture 0, Misc(25)
    Set_Vertex lwidth, lheight, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'Draw the horizontal line
    'Draw the upperhorizontal line
    For lNum = lx + 32 To lwidth - 32 Step 32
        Dev.SetTexture 0, Misc(18)
        Set_Vertex lNum, ly, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Next
    'Draw the lowerhorizontal line
    For lNum = lx + 32 To lwidth - 32 Step 32
        Dev.SetTexture 0, Misc(24)
        Set_Vertex lNum, lheight, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Next
    
    'draw the vertical lines
    'draws the leftvertical line
    For lNum = ly + 32 To lheight - 32 Step 32
        Dev.SetTexture 0, Misc(20)
        Set_Vertex lx, lNum, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Next
    'draw the rightvertical line
    For lNum = ly + 32 To lheight - 32 Step 32
        Dev.SetTexture 0, Misc(22)
        Set_Vertex lwidth, lNum, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Next
End Sub

Public Sub offFightWin(lx As Long, ly As Long, lwidth As Long, lheight As Long)

Dim lNum, lnumo As Integer
    lwidth = lx + lwidth
    lheight = ly + lheight
   For lNum = lx To lwidth Step 32
        For lnumo = ly To lheight Step 32
            Dev.SetTexture 0, Misc(0)
            Set_Vertex lNum, lnumo, 32, 32, 16777215, 16777215, 16777215, 16777215
            Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        Next
   Next
End Sub

Public Sub BuyScreen(Optional iScreenNum As Integer = 1)
Static marketelementX, marketelementY, inputdelay As Integer
Static bHelpBuyWin As Boolean
Dim sName, sDesc As String
Dim lPrice As Long
    ClearScreen
    RenderBegin
    'draw the stage frame
    DrawFrame
    'draws the belt
    Dev.SetTexture 0, Misc(26)
    Set_Vertex 33, 33, 128, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    'draw the buyscreen background
    If iScreenNum = 1 Then
        Dev.SetTexture 0, SceneBackground(1)
        Set_Vertex GameMapScreenX + 128, GameMapScreenY + 96, 320, 160, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    ElseIf iScreenNum = 2 Then
        Dev.SetTexture 0, SceneBackground(2)
        Set_Vertex GameMapScreenX + 128, GameMapScreenY + 96, 320, 168, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    
    Draw_Text 160, 16, 120, 200, "<Enter> Buy Item", &HFFFFFFFF, DT_TOP Or DT_LEFT
    Draw_Text 260, 16, 200, 200, "<Right Shift> End Buy Mode", &HFFFFFFFF, DT_TOP Or DT_LEFT
    
    'draw market menu
    Dev.SetTexture 0, SceneBackground(3)
    Set_Vertex GameMapScreenWidth - 224, GameMapScreenY + 96, 128, 160, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'draw the seller graphic
    Dev.SetTexture 0, SceneBackground(4)
    Set_Vertex GameMapScreenX + 192, GameMapScreenY + 128, 64, 64, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'y = 0
    If marketelementX = 0 And marketelementY = 0 Then
        Dev.SetTexture 0, Misc(28)
        Set_Vertex GameMapScreenX + 320 + 7, GameMapScreenY + 128 + 8, 29, 30, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        sName = GameItem(1).ItemName
        sDesc = GameItem(1).ItemDesc
        lPrice = GameItem(1).itemPrice
    ElseIf marketelementX = 1 And marketelementY = 0 Then
        Dev.SetTexture 0, Misc(28)
        Set_Vertex GameMapScreenX + 320 + 7 + 41, GameMapScreenY + 128 + 8, 29, 30, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        sName = GameItem(2).ItemName
        sDesc = GameItem(2).ItemDesc
        lPrice = GameItem(2).itemPrice
    ElseIf marketelementX = 2 And marketelementY = 0 Then
        Dev.SetTexture 0, Misc(28)
        Set_Vertex GameMapScreenX + 320 + 7 + 82, GameMapScreenY + 128 + 8, 29, 30, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        sName = GameItem(3).ItemName
        sDesc = GameItem(3).ItemDesc
        lPrice = GameItem(3).itemPrice
    'y = 1
    ElseIf marketelementX = 0 And marketelementY = 1 Then
        Dev.SetTexture 0, Misc(28)
        Set_Vertex GameMapScreenX + 320 + 7, GameMapScreenY + 128 + 48, 29, 30, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        sName = GameItem(4).ItemName
        sDesc = GameItem(4).ItemDesc
        lPrice = GameItem(4).itemPrice
    ElseIf marketelementX = 1 And marketelementY = 1 Then
        Dev.SetTexture 0, Misc(28)
        Set_Vertex GameMapScreenX + 320 + 7 + 41, GameMapScreenY + 128 + 48, 29, 30, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        sName = GameItem(5).ItemName
        sDesc = GameItem(5).ItemDesc
        lPrice = GameItem(5).itemPrice
    ElseIf marketelementX = 2 And marketelementY = 1 Then
        Dev.SetTexture 0, Misc(28)
        Set_Vertex GameMapScreenX + 320 + 7 + 82, GameMapScreenY + 128 + 48, 29, 30, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        sName = GameItem(6).ItemName
        sDesc = GameItem(6).ItemDesc
        lPrice = GameItem(6).itemPrice
    'y = 2
    ElseIf marketelementX = 0 And marketelementY = 2 Then
        Dev.SetTexture 0, Misc(28)
        Set_Vertex GameMapScreenX + 320 + 7, GameMapScreenY + 128 + 88, 29, 30, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        sName = GameItem(7).ItemName
        sDesc = GameItem(7).ItemDesc
        lPrice = GameItem(7).itemPrice
    ElseIf marketelementX = 1 And marketelementY = 2 Then
        Dev.SetTexture 0, Misc(28)
        Set_Vertex GameMapScreenX + 320 + 7 + 41, GameMapScreenY + 128 + 88, 29, 30, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        sName = GameItem(8).ItemName
        sDesc = GameItem(8).ItemDesc
        lPrice = GameItem(8).itemPrice
    ElseIf marketelementX = 2 And marketelementY = 2 Then
        Dev.SetTexture 0, Misc(28)
        Set_Vertex GameMapScreenX + 320 + 7 + 82, GameMapScreenY + 128 + 88, 29, 30, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        sName = GameItem(9).ItemName
        sDesc = GameItem(9).ItemDesc
        lPrice = GameItem(9).itemPrice
    End If
    'draw market items
    BuyWinItems
    
    onFightWin GameMapScreenWidth - 224, GameMapScreenY, 160, 64
    Draw_Text GameMapScreenWidth - 208, GameMapScreenY + 16, 200, 200, "Item Name: " & sName, &HFF000000, DT_TOP Or DT_LEFT
    Draw_Text GameMapScreenWidth - 208, GameMapScreenY + 32, 200, 200, "Description: ", &HFF000000, DT_TOP Or DT_LEFT
    Draw_Text GameMapScreenWidth - 208, GameMapScreenY + 48, 200, 200, "     " & sDesc, &HFF000000, DT_TOP Or DT_LEFT
    If lPrice < 2 Then
        Draw_Text GameMapScreenWidth - 208, GameMapScreenY + 64, 200, 200, "Price: " & lPrice & " Centavo", &HFF000000, DT_TOP Or DT_LEFT
    Else
        Draw_Text GameMapScreenWidth - 208, GameMapScreenY + 64, 200, 200, "Price: " & lPrice & " Centavos ", &HFF000000, DT_TOP Or DT_LEFT
    End If
    
    If bHelpBuyWin Then
        HelpBuyGameMsg
        Draw_Text 33, 16, 120, 200, "F2 - CLOSE HELP", &HFFFFFFFF, DT_TOP Or DT_LEFT
    Else
        Draw_Text 33, 16, 120, 200, "F1 - HELP", &HFFFFFFFF, DT_TOP Or DT_LEFT
    End If
    
    RenderEnd
    FlipScreen
    If inputdelay < 1 Then
        If CheckAllKeys Then
            If GetKeyState(DIK_F1) Then
                bHelpBuyWin = True
            ElseIf GetKeyState(DIK_F2) And bHelpBuyWin = True Then
                bHelpBuyWin = False
            ElseIf GetKeyState(DIK_RETURN) And bHelpBuyWin = False Then
                If marketelementX = 0 And marketelementY = 0 Then
                    If (PlayerStats.Money - GameItem(1).itemPrice) > -1 Then
                        If PlayerBelt.Slot(0) = 0 Then
                            PlayerBelt.Slot(0) = 1
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(1).itemPrice
                        ElseIf PlayerBelt.Slot(1) = 0 Then
                            PlayerBelt.Slot(1) = 1
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(1).itemPrice
                        ElseIf PlayerBelt.Slot(2) = 0 Then
                            PlayerBelt.Slot(2) = 1
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(1).itemPrice
                        ElseIf PlayerBelt.Slot(3) = 0 Then
                            PlayerBelt.Slot(3) = 1
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(1).itemPrice
                        End If
                    End If
                ElseIf marketelementX = 1 And marketelementY = 0 Then
                    If (PlayerStats.Money - GameItem(2).itemPrice) > -1 Then
                        If PlayerBelt.Slot(0) = 0 Then
                            PlayerBelt.Slot(0) = 2
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(2).itemPrice
                        ElseIf PlayerBelt.Slot(1) = 0 Then
                            PlayerBelt.Slot(1) = 2
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(2).itemPrice
                        ElseIf PlayerBelt.Slot(2) = 0 Then
                            PlayerBelt.Slot(2) = 2
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(2).itemPrice
                        ElseIf PlayerBelt.Slot(3) = 0 Then
                            PlayerBelt.Slot(3) = 2
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(2).itemPrice
                        End If
                    End If
                ElseIf marketelementX = 2 And marketelementY = 0 Then
                    If (PlayerStats.Money - GameItem(3).itemPrice) > -1 Then
                        If PlayerBelt.Slot(0) = 0 Then
                            PlayerBelt.Slot(0) = 3
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(3).itemPrice
                        ElseIf PlayerBelt.Slot(1) = 0 Then
                            PlayerBelt.Slot(1) = 3
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(3).itemPrice
                        ElseIf PlayerBelt.Slot(2) = 0 Then
                            PlayerBelt.Slot(2) = 3
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(3).itemPrice
                        ElseIf PlayerBelt.Slot(3) = 0 Then
                            PlayerBelt.Slot(3) = 3
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(3).itemPrice
                        End If
                    End If
                ElseIf marketelementX = 0 And marketelementY = 1 Then
                    If (PlayerStats.Money - GameItem(4).itemPrice) > -1 Then
                        If PlayerBelt.Slot(0) = 0 Then
                            PlayerBelt.Slot(0) = 4
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(4).itemPrice
                        ElseIf PlayerBelt.Slot(1) = 0 Then
                            PlayerBelt.Slot(1) = 4
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(4).itemPrice
                        ElseIf PlayerBelt.Slot(2) = 0 Then
                            PlayerBelt.Slot(2) = 4
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(4).itemPrice
                        ElseIf PlayerBelt.Slot(3) = 0 Then
                            PlayerBelt.Slot(3) = 4
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(4).itemPrice
                        End If
                    End If
                ElseIf marketelementX = 1 And marketelementY = 1 Then
                    If (PlayerStats.Money - GameItem(5).itemPrice) > -1 Then
                        If PlayerBelt.Slot(0) = 0 Then
                            PlayerBelt.Slot(0) = 5
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(5).itemPrice
                        ElseIf PlayerBelt.Slot(1) = 0 Then
                            PlayerBelt.Slot(1) = 5
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(5).itemPrice
                        ElseIf PlayerBelt.Slot(2) = 0 Then
                            PlayerBelt.Slot(2) = 5
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(5).itemPrice
                        ElseIf PlayerBelt.Slot(3) = 0 Then
                            PlayerBelt.Slot(3) = 5
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(5).itemPrice
                        End If
                    End If
                ElseIf marketelementX = 2 And marketelementY = 1 Then
                    If (PlayerStats.Money - GameItem(6).itemPrice) > -1 Then
                        If PlayerBelt.Slot(0) = 0 Then
                            PlayerBelt.Slot(0) = 6
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(6).itemPrice
                        ElseIf PlayerBelt.Slot(1) = 0 Then
                            PlayerBelt.Slot(1) = 6
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(6).itemPrice
                        ElseIf PlayerBelt.Slot(2) = 0 Then
                            PlayerBelt.Slot(2) = 6
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(6).itemPrice
                        ElseIf PlayerBelt.Slot(3) = 0 Then
                            PlayerBelt.Slot(3) = 6
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(6).itemPrice
                        End If
                    End If
                ElseIf marketelementX = 0 And marketelementY = 2 Then
                    If (PlayerStats.Money - GameItem(7).itemPrice) > -1 Then
                        If PlayerBelt.Slot(0) = 0 Then
                            PlayerBelt.Slot(0) = 7
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(7).itemPrice
                        ElseIf PlayerBelt.Slot(1) = 0 Then
                            PlayerBelt.Slot(1) = 7
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(7).itemPrice
                        ElseIf PlayerBelt.Slot(2) = 0 Then
                            PlayerBelt.Slot(2) = 7
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(7).itemPrice
                        ElseIf PlayerBelt.Slot(3) = 0 Then
                            PlayerBelt.Slot(3) = 7
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(7).itemPrice
                        End If
                    End If
                ElseIf marketelementX = 1 And marketelementY = 2 Then
                    If (PlayerStats.Money - GameItem(8).itemPrice) > -1 Then
                        If PlayerBelt.Slot(0) = 0 Then
                            PlayerBelt.Slot(0) = 8
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(8).itemPrice
                        ElseIf PlayerBelt.Slot(1) = 0 Then
                            PlayerBelt.Slot(1) = 8
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(8).itemPrice
                        ElseIf PlayerBelt.Slot(2) = 0 Then
                            PlayerBelt.Slot(2) = 8
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(8).itemPrice
                        ElseIf PlayerBelt.Slot(3) = 0 Then
                            PlayerBelt.Slot(3) = 8
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(8).itemPrice
                        End If
                    End If
                ElseIf marketelementX = 2 And marketelementY = 2 Then
                    If (PlayerStats.Money - GameItem(9).itemPrice) > -1 Then
                        If PlayerBelt.Slot(0) = 0 Then
                            PlayerBelt.Slot(0) = 9
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(9).itemPrice
                        ElseIf PlayerBelt.Slot(1) = 0 Then
                            PlayerBelt.Slot(1) = 9
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(9).itemPrice
                        ElseIf PlayerBelt.Slot(2) = 0 Then
                            PlayerBelt.Slot(2) = 9
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(9).itemPrice
                        ElseIf PlayerBelt.Slot(3) = 0 Then
                            PlayerBelt.Slot(3) = 9
                            Sound_Play 12
                            PlayerStats.Money = PlayerStats.Money - GameItem(9).itemPrice
                        End If
                    End If
                End If
                inputdelay = 10
            ElseIf GetKeyState(DIK_RSHIFT) And bHelpBuyWin = False Then
                DrawScreen = iLastStage
                Userchar.Direction = 0
            ElseIf GetKeyState(DIK_LEFT) And bHelpBuyWin = False Then
                marketelementX = marketelementX - 1
                If marketelementX < 0 Then marketelementX = 0
                inputdelay = 5
            ElseIf GetKeyState(DIK_RIGHT) And bHelpBuyWin = False Then
                marketelementX = marketelementX + 1
                If marketelementX > 2 Then marketelementX = 2
                inputdelay = 5
            ElseIf GetKeyState(DIK_UP) And bHelpBuyWin = False Then
                marketelementY = marketelementY - 1
                If marketelementY < 0 Then marketelementY = 0
                inputdelay = 5
            ElseIf GetKeyState(DIK_DOWN) And bHelpBuyWin = False Then
                marketelementY = marketelementY + 1
                If marketelementY > 2 Then marketelementY = 2
                inputdelay = 5
            End If
        End If
    End If
    inputdelay = inputdelay - 1
End Sub

Public Sub SaveWin()
Static iChoice As Integer
    ClearScreen
    RenderBegin
    Dev.SetTexture 0, SceneBackground(5)
    Set_Vertex GameMapScreenX + 128, GameMapScreenY + 96, 320, 160, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))

    If iChoice = 0 Then
        Draw_Text (GameMapScreenWidth / 2) - 4, GameMapScreenY + 192, 200, 200, "<< Yes >>", &HFF0000FF, DT_TOP Or DT_LEFT
    Else
        Draw_Text (GameMapScreenWidth / 2) - 4, GameMapScreenY + 192, 200, 200, "   Yes   ", &HFFFF0000, DT_TOP Or DT_LEFT
    End If
    If iChoice = 1 Then
        Draw_Text (GameMapScreenWidth / 2) - 4, GameMapScreenY + 192 + 16, 200, 200, "<< No >>", &HFF0000FF, DT_TOP Or DT_LEFT
    Else
        Draw_Text (GameMapScreenWidth / 2) - 4, GameMapScreenY + 192 + 16, 200, 200, "   NO   ", &HFFFF0000, DT_TOP Or DT_LEFT
    End If
    
    Draw_Text GameMapScreenX + 128 + 16, GameMapScreenY + 32, 300, 20, "Saving the game will automatically quit the current game...", &HFF00FF00, DT_TOP Or DT_LEFT

    RenderEnd
    FlipScreen
    
    'input
    If CheckAllKeys Then
        If GetKeyState(DIK_UP) Then
            iChoice = 0
        ElseIf GetKeyState(DIK_DOWN) Then
            iChoice = 1
        ElseIf iChoice = 1 And GetKeyState(DIK_RETURN) Then
            DrawScreen = iLastStage
            Userchar.Direction = 0
        ElseIf iChoice = 0 And GetKeyState(DIK_RETURN) Then
            SavePlayer
            Returntomain
        End If
    End If
End Sub
'inputbox for loadwin
Public Sub DrawInputBoxLoadWin(x As Long, y As Long, xwidth As Long, yheight As Long)
Static sCount, ncount As Long
Static inputdelay As Integer
Static sTemp As String
    Dev.SetTexture 0, Misc(30)
    Set_Vertex x, y, xwidth, yheight, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    If ncount > 30 Then
        Draw_Text x + 5, y + 2, (xwidth - x) - 16, (yheight - y) - 16, "|", &HFFFFFFFF, DT_TOP Or DT_LEFT
        ncount = 0
        If ncount > 1000 Then ncount = 0
    Else
        Draw_Text x + 5, y + 2, (xwidth - x) - 16, (yheight - y) - 16, " ", &HFFFFFFFF, DT_TOP Or DT_LEFT
        ncount = ncount + 1
    End If
    
    Draw_Text x + 5, y + 2, (xwidth - x) - 16, (yheight - y) - 16, sTemp, &HFFFFFFFF, DT_TOP Or DT_LEFT
    
    
    If CheckAllKeys Then
       If Len(Trim(sTemp)) < 10 And inputdelay < 0 Then
        If GetKeyState(DIK_1) Then
            sTemp = sTemp + "1"
            sCount = sCount + 1
            inputdelay = 7
        ElseIf GetKeyState(DIK_2) Then
            sTemp = sTemp + "2"
            sCount = sCount + 1
            inputdelay = 7
        ElseIf GetKeyState(DIK_3) Then
            sTemp = sTemp + "3"
            sCount = sCount + 1
            inputdelay = 7
        ElseIf GetKeyState(DIK_4) Then
            sTemp = sTemp + "4"
            sCount = sCount + 1
            inputdelay = 7
        ElseIf GetKeyState(DIK_5) Then
            sTemp = sTemp + "5"
            sCount = sCount + 1
            inputdelay = 7
        ElseIf GetKeyState(DIK_6) Then
            sTemp = sTemp + "6"
            sCount = sCount + 1
            inputdelay = 7
        ElseIf GetKeyState(DIK_7) Then
            sTemp = sTemp + "7"
            sCount = sCount + 1
            inputdelay = 7
        ElseIf GetKeyState(DIK_8) Then
            sTemp = sTemp + "8"
            sCount = sCount + 1
            inputdelay = 7
        ElseIf GetKeyState(DIK_9) Then
            sTemp = sTemp + "9"
            sCount = sCount + 1
            inputdelay = 7
        ElseIf GetKeyState(DIK_0) Then
            If Val(sTemp) > 0 Then
                sTemp = sTemp + "0"
                sCount = sCount + 1
                inputdelay = 7
            End If
        End If
     End If
     If GetKeyState(DIK_BACKSPACE) Then
        If sCount > 0 Then
            sCount = sCount - 1
            sTemp = Left(Trim(sTemp), sCount)
            inputdelay = 7
            
        End If
     End If
      inputdelay = inputdelay - 1
    End If
    sFile = sTemp
End Sub
'inputbox for characterwin
Public Sub DrawInputBox(x As Long, y As Long, xwidth As Long, yheight As Long)
Static sCount, ncount As Long
Static inputdelay As Integer
Static sTemp As String
    Dev.SetTexture 0, Misc(30)
    Set_Vertex x, y, xwidth, yheight, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    If ncount > 30 Then
        Draw_Text x + 5, y + 2, (xwidth - x) - 16, (yheight - y) - 16, "|", &HFFFFFFFF, DT_TOP Or DT_LEFT
        ncount = 0
        If ncount > 1000 Then ncount = 0
    Else
        Draw_Text x + 5, y + 2, (xwidth - x) - 16, (yheight - y) - 16, " ", &HFFFFFFFF, DT_TOP Or DT_LEFT
        ncount = ncount + 1
    End If
    
    Draw_Text x + 5, y + 2, (xwidth - x) - 16, (yheight - y) - 16, sTemp, &HFFFFFFFF, DT_TOP Or DT_LEFT
    
    If CheckAllKeys Then
       If Len(Trim(sTemp)) < 10 And inputdelay < 0 Then
        If GetKeyState(DIK_A) Then
            sTemp = sTemp + "A"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_B) Then
            sTemp = sTemp + "B"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_C) Then
            sTemp = sTemp + "C"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_D) Then
            sTemp = sTemp + "D"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_E) Then
            sTemp = sTemp + "E"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_F) Then
            sTemp = sTemp + "F"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_G) Then
            sTemp = sTemp + "G"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_H) Then
            sTemp = sTemp + "H"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_I) Then
            sTemp = sTemp + "I"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_J) Then
            sTemp = sTemp + "J"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_K) Then
            sTemp = sTemp + "K"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_L) Then
            sTemp = sTemp + "L"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_M) Then
            sTemp = sTemp + "M"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_N) Then
            sTemp = sTemp + "N"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_O) Then
            sTemp = sTemp + "O"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_P) Then
            sTemp = sTemp + "P"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_Q) Then
            sTemp = sTemp + "Q"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_R) Then
            sTemp = sTemp + "R"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_S) Then
            sTemp = sTemp + "S"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_T) Then
            sTemp = sTemp + "T"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_U) Then
            sTemp = sTemp + "U"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_V) Then
            sTemp = sTemp + "V"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_W) Then
            sTemp = sTemp + "W"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_X) Then
            sTemp = sTemp + "X"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_W) Then
            sTemp = sTemp + "W"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_Y) Then
            sTemp = sTemp + "Y"
            sCount = sCount + 1
            inputdelay = 5
        ElseIf GetKeyState(DIK_Z) Then
            sTemp = sTemp + "Z"
            sCount = sCount + 1
            inputdelay = 5
        End If
     End If
     If GetKeyState(DIK_BACKSPACE) Then
        If sCount > 0 Then
            sCount = sCount - 1
            sTemp = Left(Trim(sTemp), sCount)
            inputdelay = 7
            
        End If
     End If
      inputdelay = inputdelay - 1
    End If
    InputName sTemp
End Sub
Public Sub DrawPostFightWin()
Static lExp, lMoney As Long
Static iDelay, iDelay2 As Integer
Static bShowExitMsg, bKills, BLevelUpSound As Boolean
    ClearScreen
    RenderBegin
    DrawFrame
    
    If PlayerStats.Life > 0 And tempstats.Life < 1 Then
        If iEnemy = 4 Then
            BGameSolved = True
            Music_Stop 3
            Music_Start 9
            DrawScreen = 19
        End If
        onFightWin GameMapScreenX + 128, GameMapScreenY + 96, 128, 128
        If bKills = False Then
            PlayerStats.Kills = PlayerStats.Kills + 1
            bKills = True
        End If
        Draw_Text GameMapScreenX + 128 + 16, GameMapScreenY + 96 + 16, 300, 20, " " & RTrim(PlayerStats.Name) & " Stats", &HFFFF0202, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 128 + 32, GameMapScreenY + 96 + 32, 300, 20, "EXP: " & PlayerStats.Experience, &HFF6666FF, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 128 + 32, GameMapScreenY + 96 + 32 + 16, 300, 20, "Money: " & PlayerStats.Money, &HFF6666FF, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 128 + 32, GameMapScreenY + 96 + 64, 300, 20, "STR: " & PlayerStats.Strength, &HFF000000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 128 + 32, GameMapScreenY + 96 + 64 + 16, 300, 20, "VIT: " & PlayerStats.Vitality, &HFF000000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 128 + 32, GameMapScreenY + 192, 300, 20, "DEX: " & PlayerStats.Dexterity, &HFF000000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 128 + 32, GameMapScreenY + 192 + 16, 300, 20, "AGI: " & PlayerStats.Agility, &HFF000000, DT_TOP Or DT_LEFT
        If iDelay > 10 Then
            If lExp < tempstats.ExperienceEarn Then
                PlayerStats.Experience = PlayerStats.Experience + 1
                Sound_Play 9
            lExp = lExp + 1
            End If
            If lMoney < tempstats.MoneyEarn Then
                PlayerStats.Money = PlayerStats.Money + 1
                lMoney = lMoney + 1
            End If
            If lMoney >= tempstats.MoneyEarn And lExp >= tempstats.ExperienceEarn Then
                bShowExitMsg = True
            End If
            iDelay = 0
        Else
            iDelay = iDelay + 1
        End If
        If PlayerStats.Experience >= PlayerStats.nextExperience Then
            If BLevelUpSound = False Then
                Sound_Play 11
                BLevelUpSound = True
            End If
            onFightWin GameMapScreenX + 128 + 128, GameMapScreenY + 96, 128, 128
            Draw_Text GameMapScreenX + 128 + 128 + 16, GameMapScreenY + 96 + 8, 300, 20, "L E V E L  U P", &HFF222222, DT_TOP Or DT_LEFT
            Draw_Text GameMapScreenX + 128 + 128 + 16, GameMapScreenY + 96 + 32, 300, 20, "[1] Raise Strength + 1", &HFF2222AB, DT_TOP Or DT_LEFT
            Draw_Text GameMapScreenX + 128 + 128 + 16, GameMapScreenY + 96 + 32 + 16, 300, 20, "[2] Raise Vitality + 1", &HFF2222AB, DT_TOP Or DT_LEFT
            Draw_Text GameMapScreenX + 128 + 128 + 16, GameMapScreenY + 96 + 64, 300, 20, "[3] Raise Dexterity + 1", &HFF2222AB, DT_TOP Or DT_LEFT
            Draw_Text GameMapScreenX + 128 + 128 + 16, GameMapScreenY + 96 + 64 + 16, 300, 20, "[4] Raise Agility + 1", &HFF2222AB, DT_TOP Or DT_LEFT
            Draw_Text GameMapScreenX + 128 + 128 + 16, GameMapScreenY + 96 + 96 + 16, 300, 20, "SKILL POINTS: " & lSkillPoints, &HFF222222, DT_TOP Or DT_LEFT
        
            If PlayerStats.Level < 11 Then
                Draw_Text GameMapScreenX + 128 + 32, GameMapScreenHeight - 75, 250, 18, " " & TitleMsg(1), &HFF22FF33, DT_TOP Or DT_CENTER
                Draw_Text GameMapScreenX + 32, GameMapScreenHeight - 75 + 18, 450, 18, " " & AuthByMsg(1), &HFF22FF33, DT_TOP Or DT_CENTER
                Draw_Text GameMapScreenX + 32, GameMapScreenHeight - 75 + 32, 450, 60, "   '" & LevelMsg(CInt(PlayerStats.Level)) & "'", &HFFAA2233, DT_TOP Or DT_CENTER Or DT_WORDBREAK
            ElseIf PlayerStats.Level < 24 Then
                Draw_Text GameMapScreenX + 32 + 32, GameMapScreenHeight - 75, 250, 18, " " & TitleMsg(2), &HFF22FF33, DT_TOP Or DT_CENTER
                Draw_Text GameMapScreenX + 32, GameMapScreenHeight - 75 + 18, 450, 18 + 18, " " & AuthByMsg(2), &HFF22FF33, DT_TOP Or DT_CENTER
                Draw_Text GameMapScreenX + 32, GameMapScreenHeight - 75 + 32, 450, 60, "   '" & LevelMsg(CInt(PlayerStats.Level)) & "'", &HFFAA2233, DT_TOP Or DT_CENTER Or DT_WORDBREAK
            End If
            Draw_Text GameMapScreenX + 128 + 64, GameMapScreenY + 64, 300, 20, "You have Won the battle    -    Tagumpay! Level UP!!", &HFFFFAAAA, DT_TOP Or DT_LEFT
        Else
            Draw_Text GameMapScreenX + 128 + 64, GameMapScreenY + 64, 300, 20, "You have Won the battle    -    Tagumpay!", &HFFFFAAAA, DT_TOP Or DT_LEFT
        End If
    Else
        Draw_Text GameMapScreenX + 128 + 64, GameMapScreenY + 64, 300, 20, "You have been defeated!!   -    Ikaw ay natalo!", &HFFFF7777, DT_TOP Or DT_LEFT
        onFightWin GameMapScreenX + 128 + 96, GameMapScreenY + 96, 128, 64
        Music_Stop 3
        Sound_Play 10
        Draw_Text GameMapScreenX + 128 + 96 + 32, GameMapScreenY + 96 + 32, 300, 20, " G A M E  O V E R", &HFFFF0000, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 128 + 88, GameMapScreenY + 96 + 128 + 32, 300, 20, "PRESS <RIGHT SHIFT> TO MAIN MENU", &HFF22FF22, DT_TOP Or DT_LEFT
    End If
    If bShowExitMsg = True Then
        Draw_Text GameMapScreenX + 128 + 96, GameMapScreenY + 96 + 128 + 32, 300, 20, "<Right Shift> To Continue", &HFF2244FF, DT_TOP Or DT_LEFT
    End If
    RenderEnd
    FlipScreen
    
    If CheckAllKeys Then
        If PlayerStats.Experience >= PlayerStats.nextExperience And lSkillPoints > 0 Then
          If iDelay2 < 1 Then
            If GetKeyState(DIK_1) Then
                PlayerStats.Strength = PlayerStats.Strength + 1
                lSkillPoints = lSkillPoints - 1
                Sound_Play 12
                iDelay2 = 10
            ElseIf GetKeyState(DIK_2) Then
                PlayerStats.Vitality = PlayerStats.Vitality + 1
                lSkillPoints = lSkillPoints - 1
                Sound_Play 12
                iDelay2 = 10
            ElseIf GetKeyState(DIK_3) Then
                PlayerStats.Dexterity = PlayerStats.Dexterity + 1
                lSkillPoints = lSkillPoints - 1
                Sound_Play 12
                iDelay2 = 10
            ElseIf GetKeyState(DIK_4) Then
                PlayerStats.Agility = PlayerStats.Agility + 1
                lSkillPoints = lSkillPoints - 1
                Sound_Play 12
                iDelay2 = 10
            End If
          Else
            iDelay2 = iDelay2 - 1
          End If
        End If
        If GetKeyState(DIK_RSHIFT) Then
            If PlayerStats.Life < 1 Then
                DrawScreen = 1
                lExp = 0
                lMoney = 0
                Returntomain
            Else
                DrawScreen = iLastStage
                lExp = 0
                lMoney = 0
                If PlayerStats.Experience >= PlayerStats.nextExperience Then
                    PlayerStats.Level = PlayerStats.Level + 1
                    SetNextExperience
                    PlayerStats.Experience = 0
                    iDelay = 0
                    RefreshStats
                    BLevelUpSound = False
                End If
            End If
            bKills = False
            bShowExitMsg = False
        End If
    End If
End Sub
Public Sub DrawHelpWin()
Static HelpInputDelay As Integer
    'Blit the screen
    ClearScreen
    RenderBegin
    
    'Draw Background
    
    Dev.SetTexture 0, Misc(4)
    Set_Vertex 0, 0, GameWidth, GameHeight, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    'On mouseover animation
    'left arrow
    If MouseOver(44, 395, 52, 32) = True Then
        'Draw the back arrow
        Dev.SetTexture 0, Misc(6)
        Set_Vertex 40, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Else
        'Draw the back arrow
        Dev.SetTexture 0, Misc(5)
        Set_Vertex 40, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    
    If iMsgHelp = 0 Then
        Draw_Text GameMapScreenX + 128, 96, 350, 280, "     " & HelpMsg, &HFFAA5577, DT_TOP Or DT_CENTER Or DT_WORDBREAK
        Draw_Text GameMapScreenX + 128, GameMapScreenHeight - 30 - 18, 300, 51, "Press F1 during the game to see the in-game help", &HFFAA5577, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 128, GameMapScreenHeight - 30, 300, 51, "PRESS RIGHT ARROW KEY FOR MORE HELP", &HFFFF0000, DT_TOP Or DT_LEFT
    ElseIf iMsgHelp = 1 Then
        Draw_Text GameMapScreenX + 128, 96, 220, 51, "WorldMap Game Icons", &HFFAA5577, DT_TOP Or DT_LEFT
        
        'draws the world market graphic
        Dev.SetTexture 0, Tiles(1)
        Set_Vertex GameMapScreenX + 128 + 64, 128, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        
        Dev.SetTexture 0, Tiles(7)
        Set_Vertex GameMapScreenX + 128 + 64, 128, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        
        Draw_Text GameMapScreenX + 128 + 100, 128 + 16, 320, 51, "MARKET - This is where the user can buy some healing items", &HFFAA5577, DT_TOP Or DT_LEFT
    
        'draws the world house graphic
        Dev.SetTexture 0, Tiles(1)
        Set_Vertex GameMapScreenX + 128 + 64, 128 + 32 + 16, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        
        Dev.SetTexture 0, Tiles(3)
        Set_Vertex GameMapScreenX + 128 + 64, 128 + 32 + 16, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        
        Draw_Text GameMapScreenX + 128 + 100, 128 + 16 + 32 + 16, 400, 51, "HOUSE - This is the savegame location in the game", &HFFAA5577, DT_TOP Or DT_LEFT
        
        'draws the a tree
        Dev.SetTexture 0, Tiles(1)
        Set_Vertex GameMapScreenX + 128 + 64, 128 + 64 + 32, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        
        Dev.SetTexture 0, Tiles(4)
        Set_Vertex GameMapScreenX + 128 + 64, 128 + 64 + 32, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        
        Draw_Text GameMapScreenX + 128 + 100, 128 + 16 + 64 + 32, 400, 51, "TREE - Accessory graphic that blocks the map", &HFFAA5577, DT_TOP Or DT_LEFT
    
        'draws the a church
        Dev.SetTexture 0, Tiles(1)
        Set_Vertex GameMapScreenX + 128 + 64, 128 + 96 + 32 + 16, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        
        Dev.SetTexture 0, Tiles(12)
        Set_Vertex GameMapScreenX + 128 + 64, 128 + 96 + 32 + 16, 32, 32, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
        
        Draw_Text GameMapScreenX + 128 + 100, 128 + 16 + 96 + 32 + 16, 400, 51, "Church - Church location in the game", &HFFAA5577, DT_TOP Or DT_LEFT
    
        Draw_Text GameMapScreenX + 128, GameMapScreenHeight - 30, 300, 51, "PRESS LEFT ARROW KEY FOR PREVIOUS HELP", &HFFFF0000, DT_TOP Or DT_LEFT
    End If
    
    Draw_Text 213, 50, 223, 51, "HELP", &HFF000000, DT_TOP Or DT_CENTER
    
    'Draw the mouse
    Dev.SetTexture 0, Misc(1)
    Set_Vertex MousePos.x, MousePos.y, 16, 16, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    If bDevMode = True Then
        'show mouse pointer position
        Draw_Text 500, 280, 100, 200, "FPS: " & FrameRate & " x:" & MousePos.x & " y:" & MousePos.y, &HFFFFFFFF, DT_BOTTOM Or DT_RIGHT
    End If
    
    RenderEnd
    FlipScreen
    
    If HelpInputDelay < 1 Then
        If CheckAllKeys Then
            If GetKeyState(DIK_RIGHT) Then
                iMsgHelp = iMsgHelp + 1
                HelpInputDelay = 10
                If iMsgHelp > 1 Then iMsgHelp = 1
            ElseIf GetKeyState(DIK_LEFT) Then
                iMsgHelp = iMsgHelp - 1
                HelpInputDelay = 10
                If iMsgHelp < 0 Then iMsgHelp = 0
            End If
        End If
    Else
        HelpInputDelay = HelpInputDelay - 1
    End If
End Sub
'Drawstagewin help
Public Sub HelpInGameMsg()
    onFightWin 128, 128, 256, 256
    Draw_Text 128 + 16, 128 + 16, 200, 20, "IN GAME HELP", &HFFFF5555, DT_TOP Or DT_LEFT
    Draw_Text 128 + 32, 128 + 32 + 16, 200, 20, "To move Press the arrowkeys...", &HFFFF5555, DT_TOP Or DT_LEFT
    'DrawArrowKeys
    'up
    Dev.SetTexture 0, Misc(33)
    Set_Vertex 128 + 32 + 32, 128 + 64, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'down
    Dev.SetTexture 0, Misc(35)
    Set_Vertex 128 + 64, 128 + 64 + 33, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'left
    Dev.SetTexture 0, Misc(36)
    Set_Vertex 128 + 31, 128 + 64 + 33, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'right
    Dev.SetTexture 0, Misc(34)
    Set_Vertex 128 + 64 + 33, 128 + 64 + 33, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))

    Draw_Text 128 + 32, 128 + 128, 200, 50, "To use an item in the world map open the STATS(F3) screen and press the belt number that corresponds the slot(1 to 4)", &HFFFF5555, DT_TOP Or DT_LEFT Or DT_WORDBREAK
    Draw_Text 128 + 32 + 16, 128 + 128 + 70, 200, 50, "NOTE: Close the help(F2) screen first before opening the STATS(F3) screen", &HFF5555FF, DT_TOP Or DT_LEFT Or DT_WORDBREAK
End Sub
'buyscreen help
Public Sub HelpBuyGameMsg()
    onFightWin 128, 128, 256, 256
    Draw_Text 128 + 16, 128 + 16, 200, 20, "IN GAME HELP", &HFFFF5555, DT_TOP Or DT_LEFT
    Draw_Text 128 + 32, 128 + 32 + 16, 200, 20, "To choose an item press the arrowkeys...", &HFFFF5555, DT_TOP Or DT_LEFT
    'DrawArrowKeys
    'up
    Dev.SetTexture 0, Misc(33)
    Set_Vertex 128 + 32 + 32, 128 + 64, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'down
    Dev.SetTexture 0, Misc(35)
    Set_Vertex 128 + 64, 128 + 64 + 33, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'left
    Dev.SetTexture 0, Misc(36)
    Set_Vertex 128 + 31, 128 + 64 + 33, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'right
    Dev.SetTexture 0, Misc(34)
    Set_Vertex 128 + 64 + 33, 128 + 64 + 33, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))

    Draw_Text 128 + 32, 128 + 128, 200, 50, "To buy an item press <ENTER> in your keyboard", &HFFFF5555, DT_TOP Or DT_LEFT Or DT_WORDBREAK
    Draw_Text 128 + 32, 128 + 128 + 70, 200, 50, "To exit the market press <RIGHT SHIFT> in your keyboard", &HFF5555FF, DT_TOP Or DT_LEFT Or DT_WORDBREAK
End Sub
'fightscreen help
Public Sub HelpFightGameMsg()
    onFightWin 128, 128, 256, 256
    Draw_Text 128 + 16, 128 + 16, 200, 20, "IN GAME HELP", &HFFFF5555, DT_TOP Or DT_LEFT
    Draw_Text 128 + 32, 128 + 32 + 16, 300, 20, "To choose a command press the arrowkeys...", &HFFFF5555, DT_TOP Or DT_LEFT
    'DrawArrowKeys
    'up
    Dev.SetTexture 0, Misc(33)
    Set_Vertex 128 + 32 + 32, 128 + 64, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'down
    Dev.SetTexture 0, Misc(35)
    Set_Vertex 128 + 64, 128 + 64 + 33, 32, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))

    Draw_Text 128 + 32, 128 + 128, 200, 50, "To use the command in the menu press <ENTER> and to use the command in the item sub menu press the <RIGHT SHIFT>", &HFFFF5555, DT_TOP Or DT_LEFT Or DT_WORDBREAK
    Draw_Text 128 + 32, 128 + 128 + 60, 200, 60, "Note: if you want to go back to the previous menu and you are in the item sub menu press left in the arrowkeys of your keyboard", &HFF5555FF, DT_TOP Or DT_LEFT Or DT_WORDBREAK
End Sub
'Confirm Load
Public Sub GameLoadedWin()
    ClearScreen
    RenderBegin
    
    onFightWin GameMapScreenX + 128, GameMapScreenY + 96, 128, 128
    Draw_Text GameMapScreenX + 128 + 32 + 10, GameMapScreenY + 96 + 32, 300, 20, "GAME LOADED", &HFFFF0000, DT_TOP Or DT_LEFT
    Draw_Text GameMapScreenX + 128 + 10, GameMapScreenY + 96 + 128, 300, 20, "<SPACE BAR> To Continue", &HFF2244FF, DT_TOP Or DT_LEFT
    
    RenderEnd
    FlipScreen
    
    If CheckAllKeys Then
        If GetKeyState(DIK_SPACE) Then
            Userchar.Direction = 0
            If MapNumber = 1 Then
                DrawScreen = 5
                Music_Stop 1
                Music_Start 3
                GameMap(1).enabled = True
            ElseIf MapNumber = 2 Then
                DrawScreen = 8
                Music_Stop 1
                Music_Start 5
                GameMap(2).enabled = True
            ElseIf MapNumber = 3 Then
                DrawScreen = 9
                Music_Stop 1
                Music_Start 6
                GameMap(3).enabled = True
            ElseIf MapNumber = 4 Then
                DrawScreen = 10
                Music_Stop 1
                Music_Start 7
                GameMap(4).enabled = True
            ElseIf MapNumber = 5 Then
                DrawScreen = 11
                Music_Stop 1
                Music_Start 8
                GameMap(5).enabled = True
            ElseIf MapNumber = 6 Then
                DrawScreen = 12
                Music_Stop 1
                Music_Start 3
                GameMap(6).enabled = True
            End If
        End If
    End If
End Sub
'Church screen
Public Sub ChurchScreen()
Dim lLoop As Long

Dim iPriest As Long
Static sPriest As String
Static bDone, bDetPriest, bChkd As Boolean
Static lPrice As Long
    ClearScreen
    RenderBegin
    'draw the stage frame
    DrawFrame
    'draws the belt
    Dev.SetTexture 0, Misc(26)
    Set_Vertex 33, 33, 128, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    'draw the churchscreen background
    Dev.SetTexture 0, SceneBackground(2)
    Set_Vertex GameMapScreenX + 128, GameMapScreenY + 96, 320, 168, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    'draws the church
    Dev.SetTexture 0, Misc(38)
    Set_Vertex GameMapScreenX + 128 + 128 + 64, GameMapScreenY + 96, 128, 64, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    'draws the priest
    Dev.SetTexture 0, Misc(37)
    Set_Vertex GameMapScreenX + 128 + 128, GameMapScreenY + 96 + 96, 64, 64, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    If bPrayle Then
        If bChkd = False Then
            If PlayerStats.Level < 5 Then
                lPrice = 15
            ElseIf PlayerStats.Level < 9 Then
                lPrice = 35
            ElseIf PlayerStats.Level < 13 Then
                lPrice = 65
            ElseIf PlayerStats.Level < 17 Then
                lPrice = 75
            ElseIf PlayerStats.Level < 21 Then
                lPrice = 95
            End If
        End If
        Draw_Text GameMapScreenX + 128, GameMapScreenHeight - 75, 450, 60, "Father Damaso: Indio! You must pay " & lPrice & " tribute", &HFFAA2233, DT_TOP Or DT_LEFT
        If PlayerStats.Money = 0 And bChkd = False Then
            Draw_Text GameMapScreenX + 128, GameMapScreenHeight - 75 + 18, 450, 60, "Poor 'INDIO'... Well dont forget to drop by next time...", &HFF33AA33, DT_TOP Or DT_LEFT
            lPrice = 0
        Else
            If bChkd = False Then
                If PlayerStats.Money - lPrice < 1 Then
                    lPrice = PlayerStats.Money
                End If
            End If
            Draw_Text GameMapScreenX + 128, GameMapScreenHeight - 75 + 18, 450, 60, "You have given " & lPrice & " centavos to the Spanish Friar", &HFF33AA33, DT_TOP Or DT_LEFT
            bChkd = True
        End If
        
        If bDone = False Then
            For lLoop = 1 To lPrice
                PlayerStats.Money = PlayerStats.Money - 1
            Next
            bDone = True
        End If
    Else
        If PlayerStats.Level < 5 Then
            lPrice = 20
        ElseIf PlayerStats.Level < 9 Then
            lPrice = 40
        ElseIf PlayerStats.Level < 13 Then
            lPrice = 60
        ElseIf PlayerStats.Level < 17 Then
            lPrice = 80
        ElseIf PlayerStats.Level < 21 Then
            lPrice = 100
        End If
        If bDetPriest = False Then
            iPriest = CInt(Rnd() * 12) + 1
            bDetPriest = True
            If iPriest < 5 Then
                sPriest = "Father Gomez"
            ElseIf iPriest < 9 Then
                sPriest = "Father Burgoz"
            ElseIf iPriest < 13 Then
                sPriest = "Father Zamora"
            End If
        End If
        
        Draw_Text GameMapScreenX + 128, GameMapScreenHeight - 75, 450, 60, " " & sPriest & ": Ka " & RTrim(PlayerStats.Name) & " Please recieve this as an aide to your quest", &HFF33AA33, DT_TOP Or DT_LEFT
        Draw_Text GameMapScreenX + 128, GameMapScreenHeight - 75 + 18, 450, 60, "You have recieved " & lPrice & " centavos", &HFF33AA33, DT_TOP Or DT_LEFT
        If bDone = False Then
            For lLoop = 1 To lPrice
                PlayerStats.Money = PlayerStats.Money + 1
            Next
            bDone = True
        End If
    End If
    RenderEnd
    FlipScreen
    If CheckAllKeys Then
        If GetKeyState(DIK_RSHIFT) Then
            bDetPriest = False
            bDone = False
            bChkd = False
            DrawScreen = iLastStage
            Userchar.Direction = 1
        End If
    End If
End Sub
Public Sub EnemyHideOut()
Static bFinishWords As Boolean
    ClearScreen
    RenderBegin
    'draw the stage frame
    DrawFrame
    
    'draws the belt
    Dev.SetTexture 0, Misc(26)
    Set_Vertex 33, 33, 128, 32, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'draws the background
    Dev.SetTexture 0, SceneBackground(1)
    Set_Vertex GameMapScreenX + 128, GameMapScreenY + 96, 320, 160, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    UserFightAnimate
    EnemyFightAnimate 4
    
    'General's Last Words
    Draw_Text GameMapScreenX + 128, GameMapScreenHeight - 75, 450, 60, "Gov.General Izquirdo: Ka " & RTrim(PlayerStats.Name) & ", You have come here to end your life Indio!!!", &HFFAA3333, DT_TOP Or DT_LEFT
    Draw_Text GameMapScreenX + 128, GameMapScreenHeight - 75 + 18, 450, 60, "KA " & RTrim(PlayerStats.Name) & ": I am not afraid of you! i've come here to save my nation!", &HFF33AA33, DT_TOP Or DT_LEFT
    
    RenderEnd
    FlipScreen
    'keyboard control
    If CheckAllKeys Then
        If GetKeyState(DIK_RETURN) And bFinishWords = False Then
            iEnemy = 4
            DrawScreen = 6
            tempstats.Agility = EnemyStats(iEnemy).Agility
            tempstats.Armor = EnemyStats(iEnemy).Armor
            tempstats.Damage = EnemyStats(iEnemy).Damage
            tempstats.Dexterity = EnemyStats(iEnemy).Dexterity
            tempstats.MaxLife = EnemyStats(iEnemy).MaxLife
            tempstats.Life = EnemyStats(iEnemy).MaxLife
            tempstats.Belt = EnemyStats(iEnemy).Belt
            tempstats.ItemCount = EnemyStats(iEnemy).ItemCount
            tempstats.ExperienceEarn = EnemyStats(iEnemy).ExperienceEarn
            tempstats.MoneyEarn = EnemyStats(iEnemy).MoneyEarn
            tempstats.Name = EnemyStats(iEnemy).Name
            bUserTurn = FirstMoveDeterminer
            DrawScreen = 6
            Music_Stop 3
            Music_Start 4
            bFinishWords = True
        End If
    End If
End Sub
Public Sub GameEnd()
    'Blit the screen
    ClearScreen
    RenderBegin
    
    'Draw Background
    
    Dev.SetTexture 0, Misc(4)
    Set_Vertex 0, 0, GameWidth, GameHeight, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    Draw_Text 213, 50, 223, 51, "CONCLUSION", &HFF000000, DT_TOP Or DT_CENTER
    
    'On mouseover animation
    'left arrow
    If MouseOver(44, 395, 52, 32) = True Then
        'Draw the back arrow
        Dev.SetTexture 0, Misc(6)
        Set_Vertex 40, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    Else
        'Draw the back arrow
        Dev.SetTexture 0, Misc(5)
        Set_Vertex 40, GameHeight - 100, 64, 64, 16777215, 16777215, 16777215, 16777215
        Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    End If
    
    Draw_Text GameMapScreenX + 128, 96, 350, 280, " CONGRATULATIONS! You have DEFEATED the Governor General!", &HFFAA5577, DT_TOP Or DT_LEFT Or DT_WORDBREAK
    
    Draw_Text GameMapScreenX + 128, 96 + 16, 350, 280, "In those years, thousands of Filipinos have bravely died for their country and fellowmen.", &HFFAA5577, DT_TOP Or DT_LEFT Or DT_WORDBREAK
    
    'Blit The Custom Mouse Pointer

    Dev.SetTexture 0, Misc(1)
    Set_Vertex MousePos.x, MousePos.y, 16, 16, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    
    RenderEnd
    FlipScreen
End Sub
