Attribute VB_Name = "modDraw"
'-------------------------------------------------------------------------------------
'
'  Project: Shooter
'  Date:    24/04/03
'  File:    modDraw
'
'  Description
'   The Drawing Routines for the game go into here.
'-------------------------------------------------------------------------------------
Option Explicit
Sub DD_DrawAll()
    Select Case nScreen
        Case SCREEN_GAME
            DD_DrawGame
        Case SCREEN_MENU
            DD_DrawMenu
        Case SCREEN_HIGH
            DD_DrawHigh
    End Select
    
    FPS

End Sub
Sub DD_DrawMenu()
    Dim sTemp   As String
    Dim nLoop   As Long
    
    Call DD_BltFast(0, 0, 800, 600, TitleSurf, rTitleSurf, 0, 0, DX_BLIT)

    Call SetText(TXTWHITE)
    Call BackBuf.DrawText(370, nMenuPos, "Press FIRE to Start", False)
    
    For nLoop = 1 To 10
        Call BackBuf.DrawText(370, nMenuPos + 400, "High Scores", False)
        sTemp = Str(nHighScore(nLoop))
        Call BackBuf.DrawText(370 - (Len(sTemp) * 8), nMenuPos + (14 * nLoop) + 400, sTemp, False)
        sTemp = sHighScore(nLoop)
        Call BackBuf.DrawText(450, nMenuPos + (14 * nLoop) + 400, sTemp, False)
    Next nLoop
    Call SetText(TXTRED)
End Sub
Sub DD_DrawHigh()
    Dim sTemp   As String
    Dim nLoop   As Long
    
    Call DD_BltFast(0, 0, 800, 600, TitleSurf, rTitleSurf, 0, 0, DX_BLIT)

    Call SetText(TXTWHITE)
    Call BackBuf.DrawText(370, 100, "New High Score", False)
    Call BackBuf.DrawText(330, 270, "Enter Name and press fire.", False)
    
    For nLoop = 1 To 10
        Call BackBuf.DrawText(370, 300, "High Scores", False)
        sTemp = Str(nHighScore(nLoop))
        Call BackBuf.DrawText(370 - (Len(sTemp) * 8), (14 * nLoop) + 300, sTemp, False)
        sTemp = sHighScore(nLoop)
        Call BackBuf.DrawText(450, (14 * nLoop) + 300, sTemp, False)
    Next nLoop
    Call SetText(TXTRED)
End Sub
Sub DD_DrawGame()
    'Draw can only happen whilst we have the screen...
    bRestore = False
    Do Until ExModeActive
        DoEvents
        bRestore = True
    Loop
    If bRestore Then
        ddMain.RestoreAllSurfaces
        Running = False
        Exit Sub
    End If
    
    'Check to see if everything is drawn in a different colour
    If nGammaCurrent <> nGammaMode Then
        SetGamma nGammaRed, nGammaGreen, nGammaBlue
        nGammaCurrent = nGammaMode
    End If
    
    'This blits a black color fill to the back buffer
    'This should become a proper background...
'    Call BackBuf.BltColorFill(rBGSurf, RGB(0, 0, 0))
    Call DD_DrawTiles

    'This calls a sub from modDD that blits the Background to the back buffer
    'Call DD_BltFast(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, BGSurf, rBGSurf, 0, 0, DX_BLIT)
    Call DD_DrawGems
    Call DD_DrawEnemies
    
    Call DD_DrawPlayer
    Call DD_DrawMissiles
    Call DD_DrawEnemyMissiles
    Call DD_DrawStars
    Call DD_DrawExplosions

    Call DD_DrawBorders
    
    Call DD_DrawScore
    Call DD_DrawPowerUps
    Call DD_DrawHealth
    
    'This draws the text at the top of the form
    Call BackBuf.DrawText(200, yTextPos, "This is a Vertical Scroll Shoot-em-up!", False)
    If Pdebug(0) > 0 Then
        Dim nLoop As Long
        Dim sTemp As String
        For nLoop = 0 To 12
            sTemp = sTemp + " " + Str(Pdebug(nLoop))
        Next nLoop
        Call BackBuf.DrawText(20, 100, sTemp, False)
    End If
    
    
    'Debug boxes....
    Call DD_DrawBoxes

End Sub
Sub DD_DrawTiles()
'Draw the background map.  The tiles can be moved slightly out of position by using
' the ShakeX and ShakeY variables.
'This is a two layer parallelex scroller

    Dim nLoopX  As Long
    Dim nLoopY  As Long
    Dim nPosX   As Long
    Dim nPosY   As Long
    Dim nDrawX  As Long
    Dim nTile   As Long
    Dim nMap2   As Long
    Dim nHeight As Long
    
    nPosY = MapScroll - ShakeY
    nPosX = 48 + ShakeX
    
    If bDontDrawBottom Then GoTo dd_drawtile2
    'Layer 1
    'Top Line needs to be clipped
    For nLoopX = 0 To 10
        nTile = Int(Map(nLoopX, MapPointer)) * 64
        If nTile > 0 Then
            Call DD_BltFast(nPosY, nTile, nTile + 64, 64, TileSurf, rTileSurf, nLoopX * 64 + nPosX, 0, DX_BLIT)
        End If
    Next nLoopX
    'Main Body has no clipping
    For nLoopX = 0 To 10
        nDrawX = nLoopX * 64 + nPosX    'Performance tweak to calculate once
        For nLoopY = 1 To 8
            nTile = Int(Map(nLoopX, MapPointer + nLoopY)) * 64
            If nTile > 0 Then
                Call DD_BltFast(0, nTile, nTile + 64, 64, TileSurf, rTileSurf, nDrawX, nLoopY * 64 - nPosY, DX_BLIT)
            End If
        Next nLoopY
    Next nLoopX
    'Bottom Line needs to be clipped
    If nPosY > 40 Then
        For nLoopX = 0 To 10
            nDrawX = nLoopX * 64 + nPosX    'Performance tweak to calculate once
            nTile = Int(Map(nLoopX, MapPointer + 9)) * 64
            If nTile > 0 Then
                Call DD_BltFast(0, nTile, nTile + 64, 64, TileSurf, rTileSurf, nDrawX, (9 * 64) - nPosY, DX_BLIT)
            End If
            
            nTile = Int(Map(nLoopX, MapPointer + 10)) * 64
            If nTile > 0 Then
                Call DD_BltFast(0, nTile, nTile + 64, nPosY - 40, TileSurf, rTileSurf, nDrawX, (10 * 64) - nPosY, DX_BLIT)
            End If
        Next nLoopX
    Else
        For nLoopX = 0 To 10
            nTile = Int(Map(nLoopX, MapPointer + 9)) * 64
            If nTile > 0 Then
                Call DD_BltFast(0, nTile, nTile + 64, nPosY + 24, TileSurf, rTileSurf, nLoopX * 64 + nPosX, (9 * 64) - nPosY, DX_BLIT)
            End If
        Next nLoopX
    End If

dd_drawtile2:
    If bDontDrawTop Then GoTo dd_drawtileend
    'Layer2
    'The shake is double the size of the bottom layer,
    nMap2 = MapPointer * 2

    nPosY = (MapScroll - ShakeY) * 2
    nPosX = 48 + (ShakeX * 2)
    'Top Line needs to be clipped
        For nLoopX = 0 To 10
            If nPosY < 64 Then
                nTile = Map2(nLoopX, nMap2) * 64
                If nTile > 0 Then
                    nHeight = 0
                    While nTile > 639
                        nHeight = nHeight + 64
                        nTile = nTile - 640
                    Wend
                    Call DD_BltFast(nHeight + nPosY, nTile, nTile + 64, nHeight + 64, TileSurf, rTileSurf, nLoopX * 64 + nPosX, 0, DX_BLITTRANS)
                End If
            Else
                nTile = Map2(nLoopX, nMap2 + 1) * 64
                If nTile > 0 Then
                    nHeight = 0
                    While nTile > 639
                        nHeight = nHeight + 64
                        nTile = nTile - 640
                    Wend
                    Call DD_BltFast(nHeight + nPosY - 64, nTile, nTile + 64, nHeight + 64, TileSurf, rTileSurf, nLoopX * 64 + nPosX, 0, DX_BLITTRANS)
                End If
            End If
        Next nLoopX
    'Main Body has no clipping (there are cases when we try and draw a tile but fail)
    For nLoopX = 0 To 10
        nDrawX = nLoopX * 64 + nPosX    'Performance tweak to calculate once
        For nLoopY = 1 To 8
            nTile = Map2(nLoopX, nMap2 + nLoopY) * 64
            If nTile > 0 Then
                nHeight = 0
                While nTile > 639
                    nHeight = nHeight + 64
                    nTile = nTile - 640
                Wend
                Call DD_BltFast(nHeight, nTile, nTile + 64, nHeight + 64, TileSurf, rTileSurf, nDrawX, nLoopY * 64 - nPosY, DX_BLITTRANS)
            End If
        Next nLoopY
    Next nLoopX
    'Bottom Line needs to be clipped and padded quite a lot
    If nPosY > 104 Then
        For nLoopX = 0 To 10
            nDrawX = nLoopX * 64 + nPosX    'Performance tweak to calculate once
            nTile = Map2(nLoopX, nMap2 + 9) * 64
            If nTile > 0 Then
                nHeight = 0
                While nTile > 639
                    nHeight = nHeight + 64
                    nTile = nTile - 640
                Wend
                Call DD_BltFast(nHeight, nTile, nTile + 64, nHeight + 64, TileSurf, rTileSurf, nDrawX, (9 * 64) - nPosY, DX_BLITTRANS)
            End If
            nTile = Map2(nLoopX, nMap2 + 10) * 64
            If nTile > 0 Then
                nHeight = 0
                While nTile > 639
                    nHeight = nHeight + 64
                    nTile = nTile - 640
                Wend
                Call DD_BltFast(nHeight, nTile, nTile + 64, nHeight + 64, TileSurf, rTileSurf, nDrawX, (10 * 64) - nPosY, DX_BLITTRANS)
            End If
            nTile = Map2(nLoopX, nMap2 + 11) * 64
            If nTile > 0 Then
                nHeight = 0
                While nTile > 639
                    nHeight = nHeight + 64
                    nTile = nTile - 640
                Wend
                Call DD_BltFast(nHeight, nTile, nTile + 64, nHeight + nPosY - 104, TileSurf, rTileSurf, nDrawX, (11 * 64) - nPosY, DX_BLITTRANS)
            End If
        Next nLoopX
    ElseIf nPosY > 40 Then
        For nLoopX = 0 To 10
            nDrawX = nLoopX * 64 + nPosX    'Performance tweak to calculate once
            nTile = Map2(nLoopX, nMap2 + 9) * 64
            If nTile > 0 Then
                nHeight = 0
                While nTile > 639
                    nHeight = nHeight + 64
                    nTile = nTile - 640
                Wend
                Call DD_BltFast(nHeight, nTile, nTile + 64, nHeight + 64, TileSurf, rTileSurf, nDrawX, (9 * 64) - nPosY, DX_BLITTRANS)
            End If
            nTile = Map2(nLoopX, nMap2 + 10) * 64
            If nTile > 0 Then
                nHeight = 0
                While nTile > 639
                    nHeight = nHeight + 64
                    nTile = nTile - 640
                Wend
                Call DD_BltFast(nHeight, nTile, nTile + 64, nHeight + nPosY - 40, TileSurf, rTileSurf, nDrawX, (10 * 64) - nPosY, DX_BLITTRANS)
            End If
        Next nLoopX
    Else
        For nLoopX = 0 To 10
            nTile = Map2(nLoopX, nMap2 + 9) * 64
            If nTile > 0 Then
                nHeight = 0
                While nTile > 639
                    nHeight = nHeight + 64
                    nTile = nTile - 640
                Wend
                Call DD_BltFast(nHeight, nTile, nTile + 64, nHeight + nPosY + 24, TileSurf, rTileSurf, nLoopX * 64 + nPosX, (9 * 64) - nPosY, DX_BLITTRANS)
            End If
        Next nLoopX
    End If
    
dd_drawtileend:
End Sub


Sub DD_DrawPlayer()
'Draw the player with all his bits...
    Dim xPos    As Long
    Dim yPos    As Long
    Dim Graphic As Long
    Dim pOff    As Long
    
    If PHealth < 1 Then GoTo EndDrawPlayer
    If PLives = 0 Then
        Call SetText(TXTWHITE)
        Call BackBuf.DrawText(350, 300, "GAME OVER", False)
        GoTo EndDrawPlayer
    End If
    'Player ship sits on 32x32 but is only 20 high so...
    pOff = GetPlayerFrame
    xPos = PX + POffset(pOff, 1)
    yPos = PY + POffset(pOff, 2)
    With PRect
        .Left = xPos
        .Top = yPos
        .Right = xPos + 32
        .Bottom = yPos + 20
    End With
    
    Graphic = P_SHIP_GRAPHIC + PMove
    Call DD_BltFast(0, Graphic, Graphic + 32, 20, Sprite32Surf, rSprite32Surf, xPos, yPos, DX_BLITCLIPTRANS)

    'Draw the front weapon on the ship
    If PDual = False Then
        Graphic = 0
        xPos = PX + POffset(P_OFF_WEAP1, 1)
        yPos = PY + POffset(P_OFF_WEAP1, 2)
        If kbFirePressed > AutoFireSpeed - 5 Then
            Graphic = 16
            yPos = yPos - 1
        End If
    Else
        Graphic = 176
        xPos = PX + POffset(P_OFF_WEAP2, 1)
        yPos = PY + POffset(P_OFF_WEAP2, 2)
        If kbFirePressed > AutoFireSpeed - 5 Then
            Graphic = Graphic + 32
        End If
    End If
    Call DD_BltFast(0, Graphic, Graphic + 16, 16, Sprite16Surf, rSprite16Surf, xPos, yPos, DX_BLITCLIPTRANS)
        
    'Is the player moving backwards...
    If PThruster Then
        Graphic = 16
        xPos = PX + POffset(P_OFF_THRUST_LEFT, 1)
        yPos = PY + POffset(P_OFF_THRUST_LEFT, 2)
        Call DD_BltFast(0, Graphic, Graphic + 8, 8, Sprite8Surf, rSprite8Surf, xPos, yPos, DX_BLITCLIPTRANS)
        
        Graphic = 24
        xPos = PX + POffset(P_OFF_THRUST_RIGHT, 1)
        yPos = PY + POffset(P_OFF_THRUST_RIGHT, 2)
        Call DD_BltFast(0, Graphic, Graphic + 8, 8, Sprite8Surf, rSprite8Surf, xPos, yPos, DX_BLITCLIPTRANS)
    End If
    
EndDrawPlayer:
End Sub
Function GetPlayerFrame() As Long
    
    GetPlayerFrame = P_OFF_SHIP
    If PMove < 0 Then GetPlayerFrame = GetPlayerFrame - 1
    If PMove > 0 Then GetPlayerFrame = GetPlayerFrame + 1

End Function
Sub DD_DrawMissiles()
    Dim nLoop       As Long
    Dim nGraphic    As Long
    Dim ScreenX     As Long
    Dim ScreenY     As Long
        
    For nLoop = 1 To MAXMISSILES
        With Missiles(nLoop)
            ScreenX = .xPos
            ScreenY = .yPos
            Select Case .Type
                Case 0  'Not Active

                Case 1  'Yellow Bullet
                    Call DD_BltFast(0, 0, 8, 8, Sprite8Surf, rSprite8Surf, ScreenX, ScreenY, DX_BLITTRANS)
                
                Case 2  'Green Bullet
                    Call DD_BltFast(0, 8, 16, 8, Sprite8Surf, rSprite8Surf, ScreenX, ScreenY, DX_BLITTRANS)
            End Select
        End With
    Next nLoop
End Sub
Sub DD_DrawEnemyMissiles()
'Draw the enemy missiles
    Dim nLoop   As Long
    Dim nGraphic
        
    For nLoop = 1 To MAXMISSILES
        With EnemyFire(nLoop)
            Select Case .Type
                Case 0  'Not Active
                
                Case 1  'Big Yellow Dot...
                    Call DD_BltFast(0, 32, 40, 8, Sprite16Surf, rSprite16Surf, (.xPos / 4) - 4, (.yPos / 4) - 4, DX_BLITCLIPTRANS)
            End Select
        End With
    Next nLoop
End Sub
Sub DD_DrawExplosions()
    Dim nLoop   As Long
    Dim nTemp   As Long
    
    For nLoop = 1 To MAXEXPLOSIONS
        nTemp = Explosions(nLoop).Frame
        If nTemp > 0 Then
            With ExpDetail(nTemp)
                Call DD_BltFast(.StartY, .StartX, .Width, .Height, ExpSurf, rExpSurf, Explosions(nLoop).xPos - .OffsetX, Explosions(nLoop).yPos - .OffsetY, DX_BLITCLIPTRANS)
            End With
        End If
    Next nLoop
End Sub
Sub DD_DrawEnemies()
    Dim nLoop       As Long
    Dim nEnemy      As Long
    Dim nStartY     As Long
    Dim nStartX     As Long
    Dim nEndY       As Long
    Dim nEndX       As Long
    Dim nPosX       As Long
    Dim nPosY       As Long
    
    For nLoop = 1 To MAXENEMIES
        nEnemy = Enemies(nLoop).Type
        If nEnemy > 0 Then
        
            With EnemyDetail(Enemies(nLoop).Frame)
                nStartX = .StartX
                nEndX = .Width
                nStartY = .StartY
                nEndY = .Height
                nPosX = Enemies(nLoop).xPos - .OffsetX
                nPosY = Enemies(nLoop).yPos - .OffsetY

                Select Case .Surface
                    Case 4
                        Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite4Surf, rSprite4Surf, nPosX, nPosY, DX_BLITCLIPTRANS)
                    Case 8
                        Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite8Surf, rSprite8Surf, nPosX, nPosY, DX_BLITCLIPTRANS)
                    Case 16
                        Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite16Surf, rSprite16Surf, nPosX, nPosY, DX_BLITCLIPTRANS)
                    Case 32
                        If Enemies(nLoop).Flash Then
                            Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite32SurfFlash, rSprite32Surf, nPosX, nPosY, DX_BLITCLIPTRANS)
                        Else
                            Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite32Surf, rSprite32Surf, nPosX, nPosY, DX_BLITCLIPTRANS)
                        End If
                    Case 64
                        If Enemies(nLoop).Flash Then
                            Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite64SurfFlash, rSprite64Surf, nPosX, nPosY, DX_BLITCLIPTRANS)
                        Else
                            Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite64Surf, rSprite64Surf, nPosX, nPosY, DX_BLITCLIPTRANS)
                        End If
                    Case 128
                        If Enemies(nLoop).Flash Then
                            Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite128SurfFlash, rSprite128Surf, nPosX, nPosY, DX_BLITCLIPTRANS)
                        Else
                            Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite128Surf, rSprite128Surf, nPosX, nPosY, DX_BLITCLIPTRANS)
                        End If
                End Select
            
            End With
        End If
    Next nLoop
End Sub
Sub DD_DrawGems()
    Dim nLoop       As Long
    Dim nGem        As Long
    Dim nStartY     As Long
    Dim nStartX     As Long
    Dim nEndY       As Long
    Dim nEndX       As Long
    Dim nPosX       As Long
    Dim nPosY       As Long
    
    For nLoop = 1 To MAXGEMS
        nGem = Gems(nLoop).Type
        If nGem > 0 Then
            With GemDetail(Gems(nLoop).Frame)
                nStartX = .StartX
                nEndX = .Width
                nStartY = .StartY
                nEndY = .Height
                nPosX = Gems(nLoop).xPos - .OffsetX
                nPosY = Gems(nLoop).yPos - .OffsetY
            End With
            Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite16Surf, rSprite16Surf, nPosX, nPosY, DX_BLITCLIPTRANS)
        End If
    Next nLoop

End Sub
Sub DD_DrawStars()
    Dim nLoop       As Long
    Dim nStar       As Long
    
    For nLoop = 1 To MAXSTARS
        If Stars(nLoop).Active Then
            Call DD_BltFast(0, 40, 44, 2, Sprite8Surf, rSprite8Surf, Stars(nLoop).xPos, Stars(nLoop).yPos, DX_BLITTRANS)
        End If
    Next nLoop

End Sub
Sub DD_DrawBoxes()
    Dim nLoop   As Long
    
    For nLoop = 0 To 5
        If Bdebug(nLoop, 0) > 0 Then
            Call DD_BltFast(0, 0, Bdebug(nLoop, 3), 1, Sprite128Surf, rSprite128Surf, Bdebug(nLoop, 1), Bdebug(nLoop, 2), DX_BLIT)
            Call DD_BltFast(0, 0, Bdebug(nLoop, 3), 1, Sprite128Surf, rSprite128Surf, Bdebug(nLoop, 1), Bdebug(nLoop, 2) + Bdebug(nLoop, 4), DX_BLIT)
            Call DD_BltFast(0, 0, 1, Bdebug(nLoop, 4), Sprite128Surf, rSprite128Surf, Bdebug(nLoop, 1), Bdebug(nLoop, 2), DX_BLIT)
            Call DD_BltFast(0, 0, 1, Bdebug(nLoop, 4) + 1, Sprite128Surf, rSprite128Surf, Bdebug(nLoop, 1) + Bdebug(nLoop, 3), Bdebug(nLoop, 2), DX_BLIT)
            If Bdebug(nLoop, 0) = 9 Then bPause = True
        End If
    Next nLoop

End Sub

Sub DD_DrawScore()
'Draw the scores on the doors

    Dim sTemp   As String * 10
    Dim nLoop   As Long
    Dim xPos    As Long
    Dim yPos    As Long
    Dim xSource As Long
    
    sTemp = LTrim(Str(nDispScore))
    
    xPos = 100
    yPos = 12
    For nLoop = 1 To Len(RTrim(sTemp))
        xSource = Val(Mid$(sTemp, nLoop, 1)) * 32
        Call DD_BltFast(0, xSource, xSource + 24, 24, TextSurf, rTextSurf, xPos, yPos, DX_BLITTRANS)
        xPos = xPos + 24
    Next nLoop

End Sub
Sub DD_DrawBorders()
'The border goes up the left and right hand sides, means that I dont have to
'clear the screen or clip the tiles in the middle.
    Dim nLoop   As Integer
    
    For nLoop = 0 To 3
        Call DD_BltFast(0, 255, 270, 128, Sprite128Surf, rSprite128Surf, 40, 128 * nLoop, DX_BLIT)
        Call DD_BltFast(0, 271, 311, 128, Sprite128Surf, rSprite128Surf, 0, 128 * nLoop, DX_BLIT)
    
        Call DD_BltFast(0, 255, 309, 128, Sprite128Surf, rSprite128Surf, 746, 128 * nLoop, DX_BLIT)
    Next nLoop
    Call DD_BltFast(0, 255, 270, 88, Sprite128Surf, rSprite128Surf, 40, 512, DX_BLIT)
    Call DD_BltFast(0, 271, 311, 88, Sprite128Surf, rSprite128Surf, 0, 512, DX_BLIT)
    
    Call DD_BltFast(0, 255, 309, 88, Sprite128Surf, rSprite128Surf, 746, 512, DX_BLIT)

End Sub
Sub DD_DrawPowerUps()
'The PowerUp Chart near the bottom of the screen
    Dim nLoop   As Long
    Dim nEle    As Long
    Dim nStartX As Long
    Dim nEndX   As Long
    Dim nStartY As Long
    Dim nEndY   As Long
    Dim xPos    As Long
    
'The zero element.collected in the powerup array contains the current selection
    nEle = PowerUps(0).Collected
    If nEle = 0 Then GoTo EndDrawPowerUps

    If pup_upgrade Then
        SetText (TXTWHITE)
    End If
    
    Select Case PowerUps(nEle).Type
        Case PUP_AUTOFIRE
            Call BackBuf.DrawText(PowerUps(nEle).Needed * 16 + 120, 548, "AUTO-FIRE", False)
        Case PUP_POWER
            Call BackBuf.DrawText(PowerUps(nEle).Needed * 16 + 120, 548, "FIREPOWER", False)
        Case PUP_DUALFIRE
            Call BackBuf.DrawText(PowerUps(nEle).Needed * 16 + 120, 548, "DUAL SHOT", False)
        Case PUP_SIDEFIRE
            Call BackBuf.DrawText(PowerUps(nEle).Needed * 16 + 120, 548, "SIDE SHOT", False)
        Case PUP_BACKFIRE
            Call BackBuf.DrawText(PowerUps(nEle).Needed * 16 + 120, 548, "BACK SHOT", False)
    End Select
    For nLoop = 1 To PowerUps(nEle).Needed
        Call DD_BltFast(0, 192, 208, 16, Sprite16Surf, rSprite16Surf, nLoop * 16 + 100, 560, DX_BLITTRANS)
    Next nLoop
    pup_counter = pup_counter + 1
    If pup_counter = PUP_DELAY Then
        pup_counter = 0
        pup_frame = pup_frame + 1
        If pup_frame > 8 Then pup_frame = 1
    End If
    For nLoop = 1 To PowerUps(nEle).Collected
        With GemDetail(pup_frame)
            nStartX = .StartX
            nEndX = .Width
            nStartY = .StartY
            nEndY = .Height
            xPos = nLoop * 16 + 106 - .OffsetX
        End With
        Call DD_BltFast(nStartY, nStartX, nEndX, nEndY, Sprite16Surf, rSprite16Surf, xPos, 548, DX_BLITTRANS)
    Next nLoop
    
    If pup_upgrade Then
        SetText (TXTRED)
        pup_ani = pup_ani - 1
        If pup_ani = 0 Then pup_upgrade = False
    End If
EndDrawPowerUps:
End Sub
Sub DD_DrawHealth()
'A simple routine for once.
' Draw a bar at the bottom of the screen that depicts the players current health
    Dim nLoop   As Long
    
    Call DD_BltFast(0, 380, 380 + (PHealth * 2), 12, Sprite128Surf, rSprite128Surf, 100, 580, DX_BLIT)

    If PLives > 1 Then
        For nLoop = 1 To PLives - 1
            Call DD_BltFast(0, P_SHIP_GRAPHIC, P_SHIP_GRAPHIC + 32, 20, Sprite32Surf, rSprite32Surf, 5, 600 - (25 * nLoop), DX_BLITCLIPTRANS)
        Next nLoop
    End If
End Sub
