Jump to content

SAB 2


smashly
 Share

Recommended Posts

SAB 2 is a small short simple game based off my first version of $hit A Brick.

Left and right arrow keys to move the paddle.

Spacebar to start, pause and resume game.

Shit A Brick by hitting the ball into the wall to dislodge a brick to get some score.

Capture a falling brick with the paddle to get some more score.

Miss the ball and your penalized 1/5 of your current score.

But don't worry you get a chance to retrieve the score back with interest.

When missing the ball your thrown into a bonus mode.

In bonus mode a smaller multi color brick will bound it's way down the screen.

Capture the multi colored brick with your paddle to get your lost score plus bonus back.

Game is over once all the bricks have been hit from the wall and no bricks exist on the court.

Scores:

Knocking a brick from the wall: 25 points

Capturing a falling brick;

White Brick: 40 points

Yellow Brick: 80 points

Orange Brick: 160 points

Red Brick: 320 points

Brown Brick: 640 points

Capturing the bonus mode brick: Lost score + upto 3 x lost score

(Bonus score is random can be from 1 ~ 3 multiplied by the value of Lost Score divide by 1 ~ 5)

Update:

Added beep sounds,

Added settings, allows for sound to be disabled and ball speed (right click Title bar to access settings).

Added more tolerance to hitting the end of the paddle with the ball.

Made bonus mode a little harder ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GDIplus.au3>
#include <WinApi.au3>
#include <Misc.au3>
#include <GUIMenu.au3>
#include <MenuConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)

HotKeySet("{SPACE}", "_Pause")

Global $Ini = @ScriptDir & "\SAB2.ini"
Global $hGui, $gW = 502, $gH = 670, $hMenu, $id_Settings
Global $hDC, $hDC_Buffer, $hFont1, $hFont2, $hOldFont, $hGr_Buffer, $hBrush, $hBMP, $hOldBMP, $hCBMP
Global $iHudScore, $iHudBestScore, $hH = 30, $hW = $gW / 2
Global $hSet, $sW = 175, $sH = 75, $sX = ($gW / 2) - ($sW / 2), $sY = $hH, $iSnd, $aSpeed[6]
Global $iCourt, $cSY, $tCourtRect, $cX = 0, $cY = $hH, $cW = $gW, $cH = $gH - $hH
Global $bX, $bY, $eX, $eY, $bW = 20, $bH = 20, $bC, $ibClr = 0xFF00FF00
Global $pW = 64, $pX = ($gW / 2) - ($pW / 2), $pH = 15, $pY = $cH - $pH, $pBW = 3 * $pW / 4, $pBX = ($gW / 2) - ($pBW / 2)
Global $aClr = StringSplit("0x0000CC|0x0000FF|0x00AAFF|0x00FFFF|0xFFFFFF|0x00FF00|0x000000", "|")
Global $aBrush[UBound($aClr)]
Global $rW = 48, $rH = 20, $rX = 2, $rY = 2
Global $aBrick[51][2], $aDropBrick[51][5]
Global $iScore, $iBestScore = IniRead($Ini, "BestScore", "1", "0"), $iBD, $Pause = 1, $iStart, $hKey
Global $iLost, $iBonus, $tBonus, $tX, $iBM, $tW = 3 * ($rW / 4), $iFinished = 0
Global $iSound = Int(IniRead($Ini, "Settings", "Sound", "1"))
Global $iSpeed = Number(IniRead($Ini, "Settings", "Speed", "0"))
Global $sTitle = "SAB 2 - Status: "
Global $sBegin = $sTitle & "Spacebar to begin"
Global $sPause = $sTitle & "Paused (Spacebar to resume)"
Global $sPlay = $sTitle & "Playing (Spacebar to pause)"
Global $sAdd = $sTitle & "Bonus add score"
Global $sMinus = $sTitle & "Penalty minus score"
Global $sOver = $sTitle & "Spacebar to play again"
Global $sSetting = $sTitle & "Settings"
Global $sTmpTitle

$hGui = GUICreate($sBegin, $gW, $gH)
GUISetBkColor(0x000000, $hGui)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GuiEvent", $hGui)
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_GuiEvent", $hGui)
GUISetOnEvent($GUI_EVENT_RESTORE, "_GuiEvent", $hGui)
$hMenu = _GUICtrlMenu_GetSystemMenu($hGui)
_GUICtrlMenu_AppendMenu($hMenu, $MF_SEPARATOR, 0, 0)
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_Settings, "Settings")
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
$iHudScore = GUICtrlCreateLabel("Score: 000000", 0, 0, $hW, $hH, $SS_CENTER)
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetFont(-1, 20, 700)
$iHudBestScore = GUICtrlCreateLabel("Best Score: " & StringFormat("%06i", $iBestScore), $hW, 0, $hW, $hH, $SS_CENTER)
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetFont(-1, 20, 700)
$iCourt = GUICtrlCreatePic("", $cX, $cY, $cW, $cH)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW, $hGui)

$hSet = GUICreate("Settings", $sW, $sH, $sX, $sY, BitOR($WS_OVERLAPPEDWINDOW, $WS_CHILD), $WS_EX_TOOLWINDOW, $hGui)
GUISetBkColor(0x00FF00, $hSet)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GuiEvent", $hSet)
$iSnd = GUICtrlCreateCheckbox("Disable Sound", 10, 5, 100, 20)
GUICtrlSetOnEvent(-1, "_GuiEvent")
If Not $iSound Then GUICtrlSetState($iSnd, $GUI_CHECKED)
GUICtrlCreateGroup("Ball Speed (1 = Fast, 5 = Slow) ", 5, 30, $sW - 10, 40)
For $i = 1 To 5
    $aSpeed[$i] = GUICtrlCreateRadio($i, 15 + (($i - 1) * 30), 45, 25, 20)
    GUICtrlSetOnEvent(-1, "_GuiEvent")
Next
If Not $iSpeed Then
    GUICtrlSetState($aSpeed[1], $GUI_CHECKED)
Else
    GUICtrlSetState($aSpeed[StringReplace($iSpeed, ".", "")], $GUI_CHECKED)
EndIf
GUISetState(@SW_HIDE, $hSet)

_Startup()

While 1
    Sleep(10)
    If $hKey And Not WinActive($hGui) Then
        If Not $Pause Then _Pause()
        HotKeySet("{SPACE}")
        $hKey = 0
    ElseIf WinActive($hGui) And Not $hKey Then
        HotKeySet("{SPACE}", "_Pause")
        $hKey = 1
    EndIf
WEnd

Func _GuiEvent()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Switch @GUI_WinHandle
                Case $hGui
                    _Shutdown()
                Case $hSet
                    _Settings()
            EndSwitch
        Case $GUI_EVENT_MINIMIZE
            If Not $Pause Then _Pause()
            GUISetState(@SW_MINIMIZE, $hGui)
        Case $GUI_EVENT_RESTORE
            GUISetState(@SW_RESTORE, $hGui)
        Case $iSnd
            If BitAND(GUICtrlRead($iSnd), $GUI_CHECKED) Then
                $iSound = 0
            Else
                $iSound = 1
            EndIf
            IniWrite($Ini, "Settings", "Sound", $iSound)
        Case $aSpeed[1]
            $iSpeed = 0
            IniWrite($Ini, "Settings", "Speed", $iSpeed)
        Case $aSpeed[2] To $aSpeed[5]
            $iSpeed = Number("." & GUICtrlRead(@GUI_CtrlId, 1))
            IniWrite($Ini, "Settings", "Speed", $iSpeed)
    EndSwitch
EndFunc   ;==>_GuiEvent

Func _Pause()
    If $Pause Then
        $Pause = 0
        WinSetTitle($hGui, "", $sPlay)
        If $iFinished Then _PlayAgain()
        If $iBM Then
            AdlibRegister("_BonusMode", 10)
        Else
            AdlibRegister("_Bounce", 10)
        EndIf
        _WinAPI_DeleteObject($hCBMP)
    Else
        $Pause = 1
        WinSetTitle($hGui, "", $sPause)
        If $iBM Then
            AdlibUnRegister("_BonusMode")
            $iBM = 0
            _BonusMode()
            $iBM = 1
        Else
            AdlibUnRegister("_Bounce")
            _DrawCourt()
        EndIf
        _SetPic()
    EndIf
EndFunc   ;==>_Pause

Func _Startup()
    _GDIPlus_Startup()
    $hDC = _WinAPI_GetDC(GUICtrlGetHandle($iCourt))
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $cW, $cH)
    $hDC_Buffer = _WinAPI_CreateCompatibleDC(0)
    $hOldBMP = _WinAPI_SelectObject($hDC_Buffer, $hBMP)
    _WinAPI_SetBkMode($hDC_Buffer, $TRANSPARENT)
    $hFont1 = _WinAPI_CreateFont(20, 0, 0, 0, 700)
    $hFont2 = _WinAPI_CreateFont(31, 0, 0, 0, 700)
    $hOldFont = _WinAPI_SelectObject($hDC_Buffer, $hFont1)
    $hGr_Buffer = _GDIPlus_GraphicsCreateFromHDC($hDC_Buffer)
    _GDIPlus_GraphicsSetSmoothingMode($hGr_Buffer, 2)
    $hBrush = _GDIPlus_BrushCreateSolid($ibClr)
    For $i = 1 To $aClr[0]
        $aBrush[$i] = _WinAPI_CreateSolidBrush($aClr[$i])
    Next
    _DrawBricks()
    _SetPic()
EndFunc   ;==>_Startup

Func _Bounce()
    For $i = 1 To 3
        If _IsPressed("25") And $pX > 0 Then $pX -= 3
        If _IsPressed("27") And $pX < $gW - $pW Then $pX += 3
        If $bX <= 0 Then ;Hit side wall
            $eX = "$bX + " & (Random(1.6, 1.9) - $iSpeed)
            If $iSound Then Beep(500, 14)
        ElseIf $bX + $bW >= $cW Then
            $eX = "$bX -  " & (Random(1.6, 1.9) - $iSpeed)
            If $iSound Then Beep(500, 14)
        EndIf
        If $bY <= $cSY Then ;Brick Wall Hit
            $eY = "$bY +  " & (Random(1.7, 2.0) - $iSpeed)
            _WallHit()
            If $iSound Then Beep(600, 14)
        ElseIf $bY + $bH >= $pY And $bY + $bH <= $pY + 7 And $bX + $bW >= $pX And $bX <= $pX + $pW Then ;Hit paddle
            $bC = $bX + ($bW / 2)
            If $bC >= $pX + ($pW / 5) And $bC <= $pX + (($pW / 5) * 4) Then ;Hit center of paddle
                If ($bC <= $pX + (($pW / 5) * 2)) Or ($bC >= $pX + (($pW / 5) * 3)) Then
                    If StringInStr($eX, "-") Then $eX = "$bX - " & (Random(1.3, 1.6) - $iSpeed)
                    If StringInStr($eX, "+") Then $eX = "$bX + " & (Random(1.3, 1.6) - $iSpeed)
                    $eY = "$bY - " & Random(2.2, 2.6)
                Else
                    ;Hit just off center paddle
                    If StringInStr($eX, "-") Then $eX = "$bX - " & (Random(1.4, 1.7) - $iSpeed)
                    If StringInStr($eX, "+") Then $eX = "$bX + " & (Random(1.4, 1.7) - $iSpeed)
                    $eY = "$bY - " & (Random(2, 2.4) - $iSpeed)
                EndIf
            ElseIf $bC < $pX + ($pW / 5) Then ;Hit Left side of paddle
                $eX = StringReplace($eX, "+", "-")
                $eY = "$bY - " & (Random(1.9, 2.3) - $iSpeed)
            ElseIf $bC > $pX + (($pW / 5) * 4) Then ;Hit right side of paddle
                $eX = StringReplace($eX, "-", "+")
                $eY = "$bY - " & (Random(1.9, 2.3) - $iSpeed)
            EndIf
            If $iSound Then Beep(700, 14)
        ElseIf $bY >= $cH + 4 Then ;Ball at bottom of screen, Second chance retrieve lost score x3, bonus mode!
            If $iSound Then Beep(200, 100)
            AdlibUnRegister("_Bounce")
            _MissedBall()
            $bY = $cSY + 2
            $eY = "$bY +  " & (Random(1.5, 1.9) - $iSpeed)
            $iBM = 1
            WinSetTitle($hGui, "", $sPlay)
            Return AdlibRegister("_BonusMode", 10)
        EndIf
        $bX = Execute($eX)
        $bY = Execute($eY)
        _DrawCourt()
        If $aDropBrick[0][0] = 50 And _CheckEnd() Then
            AdlibUnRegister("_Bounce")
            _CheckBestScore()
            _MissedBall(3)
            WinSetTitle($hGui, "", $sOver)
            $iFinished = 1
            $Pause = 1
            Return
        EndIf
    Next
EndFunc   ;==>_Bounce

Func _PlayAgain()
    Dim $aDropBrick[51][5]
    $pX = ($gW / 2) - ($pW / 2)
    $pBX = ($gW / 2) - ($pBW / 2)
    $cSY = 0
    _DrawBricks()
    $iBM = 0
    $iScore = 0
    $iFinished = 0
    GUICtrlSetData($iHudScore, "Score: 000000")
EndFunc   ;==>_PlayAgain

Func _CheckBestScore()
    Local $tClear, $tRect
    If $iScore > $iBestScore Then
        $iBestScore = $iScore
        IniWrite($Ini, "BestScore", "1", $iBestScore)
        _MissedBall(2)
        GUICtrlSetData($iHudBestScore, "Best Score: " & StringFormat("%06i", $iBestScore))
    EndIf
EndFunc   ;==>_CheckBestScore

Func _CheckEnd()
    For $i = 1 To $aDropBrick[0][0]
        If IsDllStruct($aDropBrick[$i][0]) Or IsDllStruct($aDropBrick[$i][3]) Then Return 0
    Next
    Return 1
EndFunc   ;==>_CheckEnd

Func _BonusMode()
    Local $tRect, $tT, $tL, $tClear = _tRect(0, 0, $cW, $cH)
    For $i = 1 To 3
        _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($tClear), $aBrush[7])
        If $iBM Then
            If _IsPressed("25") And $pBX > 0 Then $pBX -= 3
            If _IsPressed("27") And $pBX < $cW - $pBW Then $pBX += 3
            $tT = DllStructGetData($tBonus, "Top")
            $tL = DllStructGetData($tBonus, "Left")
            If $tT < $cH Then
                If $tT + $rH >= $pY And $tT <= $pY And $tL + $tW >= $pBX And $tL <= $pBX + $pBW Then ;Bonus brick hit paddle
                    If $iSound Then Beep(800, 10)
                    _MissedBall(1)
                    WinSetTitle($hGui, "", $sPlay)
                    $tBonus = 0
                    AdlibUnRegister("_BonusMode")
                    _DrawBricks(1)
                    $iBM = 0
                    Return AdlibRegister("_Bounce", 10)
                EndIf
                If $tT > $pY - Random(30, 100, 1) Then
                    $tT += Random(0, 5, 1)
                Else
                    $tT += Random(0, 1, 1)
                EndIf
                DllStructSetData($tBonus, "Top", $tT)
                DllStructSetData($tBonus, "Bottom", $tT + $rH)
                If $tL <= 0 Then
                    $tX = "$tL + " & Random(3, 6, 1)
                    If $iSound Then Beep(500, 14)
                ElseIf $tL >= $cW - $pBW Then
                    $tX = "$tL - " & Random(3, 6, 1)
                    If $iSound Then Beep(500, 14)
                EndIf
                DllStructSetData($tBonus, "Left", Execute($tX))
                DllStructSetData($tBonus, "Right", Execute($tX) + $tW)
            Else
                If $iSound Then Beep(200, 100)
                $tBonus = 0
                AdlibUnRegister("_BonusMode")
                _DrawBricks(1)
                $iBM = 0
                Return AdlibRegister("_Bounce", 10)
            EndIf
        EndIf
        _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($tBonus), $aBrush[Random(1, 6, 1)])
        $tRect = _tRect($pBX, $pY, $pBW, $pH)
        _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($tRect), $aBrush[6])
        $tRect = 0
        _WinAPI_BitBlt($hDC, 0, 0, $cW, $cH, $hDC_Buffer, 0, 0, $SRCCOPY)
        If Not $iBM Then Return
    Next
EndFunc   ;==>_BonusMode

Func _MissedBall($iFlag = 0)
    HotKeySet("{SPACE}")
    $hKey = 0
    Local $tRect = _tRect(0, $cH, $cW, 30), $iStep = $cH, $aPM[3] = [0, ' + ', ' - '], $sText, $iStart
    If Not $iFlag Then
        WinSetTitle($hGui, "", $sMinus)
        $iStart = $cH
        $iLost = Round($iScore / 5)
        $iBonus = $iLost + Round(Random(1, 3, 1) * ($iLost / Random(1, 5, 1)))
        $tBonus = _tRect(Random(0, $cW - (3 * ($rW / 4)), 1), -$rH, 3 * ($rW / 4), $rH)
        $tX = '$tL' & $aPM[Random(1, 2, 1)] & Random(2, 4, 1)
        _WinAPI_SetTextColor($hDC_Buffer, $aClr[2])
        $sText = "-" & StringFormat("%06i", $iLost)
    ElseIf $iFlag = 1 Then
        WinSetTitle($hGui, "", $sAdd)
        $iStart = DllStructGetData($tBonus, "Top")
        _WinAPI_SetTextColor($hDC_Buffer, $aClr[6])
        $sText = "+" & StringFormat("%06i", $iBonus)
    ElseIf $iFlag = 2 Then
        WinSetTitle($hGui, "", "SAB 2 - Status: New Best Score")
        $iStart = $cH
        _WinAPI_SetTextColor($hDC_Buffer, $aClr[6])
        $sText = "New Best Score: " & StringFormat("%06i", $iBestScore)
    ElseIf $iFlag = 3 Then
        WinSetTitle($hGui, "", "SAB 2")
        $iStart = $cH
        _WinAPI_SetTextColor($hDC_Buffer, $aClr[6])
        $sText = "Game Over"
    EndIf
    _WinAPI_SelectObject($hDC_Buffer, $hFont2)
    For $i = $iStart To -30 Step -1
        _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($tCourtRect), $aBrush[7])
        _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($tRect), $aBrush[7])
        _WinAPI_DrawText($hDC_Buffer, $sText, $tRect, BitOR($DT_VCENTER, $DT_CENTER))
        _WinAPI_BitBlt($hDC, 0, 0, $cW, $cH, $hDC_Buffer, 0, 0, $SRCCOPY)
        $iStep -= 1
        DllStructSetData($tRect, "Top", $iStep)
        DllStructSetData($tRect, "Bottom", $iStep + 30)
        If $iFlag > 1 Then Sleep(10)
    Next
    _WinAPI_SelectObject($hDC_Buffer, $hFont1)
    If Not $iFlag Then
        _SetScore(-2)
    ElseIf $iFlag = 1 Then
        _SetScore(-3)
    EndIf
    $tRect = 0
    HotKeySet("{SPACE}", "_Pause")
    $hKey = 1
EndFunc   ;==>_MissedBall

Func _WallHit()
    Local $tL
    For $i = 5 To 50 Step 5
        $tL = DllStructGetData($aBrick[$i][0], "Left")
        If $bX + $bW / 2 >= $tL - 2 And $bX + $bW / 2 <= $tL + $rW + 2 And $aBrick[$i][1] <> 6 And TimerDiff($iBD) > 30 Then
            _SetScore(-1)
            $aDropBrick[0][0] += 1
            $aDropBrick[$aDropBrick[0][0]][0] = _tRect($tL, $cSY, $rW, $rH)
            $aDropBrick[$aDropBrick[0][0]][1] = $aBrick[$i][1]
            $aDropBrick[$aDropBrick[0][0]][2] = TimerInit()
            If $tL <= 10 + (4 * $rW) Then
                $aDropBrick[$aDropBrick[0][0]][4] = _tRect($tL + $rW, $cSY, $rW, $rH)
            Else
                $aDropBrick[$aDropBrick[0][0]][4] = _tRect($tL - $rW, $cSY, $rW, $rH)
            EndIf
            For $j = $i To $i - 4 Step -1
                If $j = $i - 4 Then $aBrick[$j][1] = 6
                If $j <> $i - 4 Then $aBrick[$j][1] = $aBrick[$j - 1][1]
                _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($aBrick[$j][0]), $aBrush[$aBrick[$j][1]])
            Next
            $iBD = TimerInit()
            ExitLoop
        EndIf
    Next
EndFunc   ;==>_WallHit

Func _DrawBricks($iFlag = 0)
    Local $brCnt = 1, $tRect = _tRect(0, 0, $cW, ($rH + 2) * 5)
    _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($tRect), $aBrush[6])
    $tRect = 0
    For $i = 1 To 50
        If $iFlag Then
            _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($aBrick[$i][0]), $aBrush[$aBrick[$i][1]])
        Else
            $aBrick[$i][0] = _tRect($rX, $rY, $rW, $rH)
            $aBrick[$i][1] = $brCnt
            _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($aBrick[$i][0]), $aBrush[$aBrick[$i][1]])
            If Not Mod($i, 5) Then
                If Not $cSY Then
                    $cSY = $rY + $rH
                    $bY = $cSY + 2
                    $eY = "$bY + 1"
                    $bX = Random(0, $cW - $bW, 1)
                    $eX = "$bX + 1.5"
                    $tCourtRect = _tRect(0, $cSY, $cW, $cH - $cSY)
                EndIf
                $rX += $rW + 2
                $rY = 2
                $brCnt = 1
            Else
                $brCnt += 1
                $rY += $rH + 2
            EndIf
        EndIf
    Next
    $rY = 2
    $rX = 2
    $tRect = _tRect($pX, $pY, $pW, $pH)
    _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($tRect), $aBrush[6])
    $tRect = 0
    _WinAPI_BitBlt($hDC, 0, 0, $cW, $cH, $hDC_Buffer, 0, 0, $SRCCOPY)
EndFunc   ;==>_DrawBricks

Func _SetScore($iValue)
    Local $iTmp1 = $iScore
    Switch $iValue
        Case -3
            $iTmp1 += $iBonus
            $iBonus = 0
            $iLost = 0
        Case -2
            $iTmp1 -= $iLost
        Case -1
            $iTmp1 += 25
        Case 1
            $iTmp1 += 640
        Case 2
            $iTmp1 += 320
        Case 3
            $iTmp1 += 160
        Case 4
            $iTmp1 += 80
        Case 5
            $iTmp1 += 40
    EndSwitch
    If $iScore <> $iTmp1 Then
        $iScore = $iTmp1
        GUICtrlSetData($iHudScore, "Score: " & StringFormat("%06i", $iScore))
    EndIf
EndFunc   ;==>_SetScore

Func _GetBrickScore($iBrick)
    Switch $iBrick
        Case -1
            Return "+25"
        Case 1
            Return "+640"
        Case 2
            Return "+320"
        Case 3
            Return "+160"
        Case 4
            Return "+80"
        Case 5
            Return "+40"
    EndSwitch
EndFunc   ;==>_GetBrickScore

Func _DrawCourt()
    Local $tT, $tB, $tL, $tR, $tRect
    _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($tCourtRect), $aBrush[7])
    For $i = 1 To UBound($aDropBrick, 1) - 1
        If IsDllStruct($aDropBrick[$i][4]) Then
            $tT = DllStructGetData($aDropBrick[$i][4], "Top")
            If $tT <= $cSY + 100 Then
                _WinAPI_SetTextColor($hDC_Buffer, $aClr[6])
                _WinAPI_DrawText($hDC_Buffer, _GetBrickScore(-1), $aDropBrick[$i][4], BitOR($DT_VCENTER, $DT_CENTER))
                $tT += 1
                DllStructSetData($aDropBrick[$i][4], "Top", $tT)
                DllStructSetData($aDropBrick[$i][4], "Bottom", $tT + $rH)
            Else
                _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($aDropBrick[$i][4]), $aBrush[7])
                $aDropBrick[$i][4] = 0
            EndIf
        EndIf
        If IsDllStruct($aDropBrick[$i][3]) Then
            $tT = DllStructGetData($aDropBrick[$i][3], "Top")
            $tB = DllStructGetData($aDropBrick[$i][3], "Bottom")
            If $tT >= $pY - 150 Then
                _WinAPI_SetTextColor($hDC_Buffer, $aClr[$aDropBrick[$i][1]])
                _WinAPI_DrawText($hDC_Buffer, _GetBrickScore($aDropBrick[$i][1]), $aDropBrick[$i][3], BitOR($DT_VCENTER, $DT_CENTER))
                $tT -= 1
                DllStructSetData($aDropBrick[$i][3], "Top", $tT)
                DllStructSetData($aDropBrick[$i][3], "Bottom", $tT + $rH)
            Else
                _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($aDropBrick[$i][3]), $aBrush[7])
                $aDropBrick[$i][3] = 0
            EndIf
        EndIf
        If Not IsDllStruct($aDropBrick[$i][0]) Then ContinueLoop
        $tT = DllStructGetData($aDropBrick[$i][0], "Top")
        $tB = DllStructGetData($aDropBrick[$i][0], "Bottom")
        $tL = DllStructGetData($aDropBrick[$i][0], "Left")
        $tR = DllStructGetData($aDropBrick[$i][0], "Right")
        If $tB >= $pY Then
            If ($tL >= $pX And $tL <= $pX + $pW) Or ($tR >= $pX And $tR <= $pX + $pW) Then
                If $iSound Then Beep(800, 10)
                _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($aDropBrick[$i][0]), $aBrush[7])
                $aDropBrick[$i][3] = $aDropBrick[$i][0]
                $aDropBrick[$i][0] = 0
                _SetScore($aDropBrick[$i][1])
                ContinueLoop
            EndIf
        EndIf

        If $tT = $cH Then
            $aDropBrick[$i][0] = 0
            ContinueLoop
        EndIf
        _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($aDropBrick[$i][0]), $aBrush[$aDropBrick[$i][1]])
        If TimerDiff($aDropBrick[$i][2]) >= ($aDropBrick[$i][1] + 1) * $aDropBrick[$i][1] Then
            $tT += 1
            DllStructSetData($aDropBrick[$i][0], "Top", $tT)
            DllStructSetData($aDropBrick[$i][0], "Bottom", $tT + $rH)
            $aDropBrick[$i][2] = TimerInit()
        EndIf
    Next
    _GDIPlus_GraphicsFillEllipse($hGr_Buffer, $bX, $bY, $bW, $bH, $hBrush)
    $tRect = _tRect($pX, $pY, $pW, $pH)
    _WinAPI_FillRect($hDC_Buffer, DllStructGetPtr($tRect), $aBrush[6])
    $tRect = 0
    _WinAPI_BitBlt($hDC, 0, 0, $cW, $cH, $hDC_Buffer, 0, 0, $SRCCOPY)
EndFunc   ;==>_DrawCourt

Func _tRect($iX, $iY, $iW, $iH)
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, "Left", $iX)
    DllStructSetData($tRect, "Top", $iY)
    DllStructSetData($tRect, "Right", $iX + $iW)
    DllStructSetData($tRect, "Bottom", $iY + $iH)
    Return $tRect
EndFunc   ;==>_tRect

Func _SetPic()
    Local $hCDC, $hOld
    $hCBMP = _WinAPI_CreateCompatibleBitmap($hDC, $cW, $cH)
    $hCDC = _WinAPI_CreateCompatibleDC(0)
    $hOld = _WinAPI_SelectObject($hCDC, $hCBMP)
    _WinAPI_BitBlt($hCDC, 0, 0, $cW, $cH, $hDC_Buffer, 0, 0, $MERGECOPY)
    _WinAPI_SelectObject($hCDC, $hOld)
    _WinAPI_DeleteDC($hCDC)
    _WinAPI_DeleteObject(GUICtrlSendMsg($iCourt, 0x0172, 0, $hCBMP))
EndFunc   ;==>_SetPic

Func _Settings()
    If BitAND(WinGetState($hSet), 2) Then
        HotKeySet("{SPACE}", "_Pause")
        WinSetTitle($hGui, "", $sTmpTitle)
        GUICtrlSetState($iCourt, $GUI_SHOW)
        GUISetState(@SW_HIDE, $hSet)
    Else
        If Not $Pause Then _Pause()
        HotKeySet("{SPACE}")
        $sTmpTitle = WinGetTitle($hGui)
        WinSetTitle($hGui, "", $sSetting)
        GUICtrlSetState($iCourt, $GUI_HIDE)
        GUISetState(@SW_SHOW, $hSet)
    EndIf
EndFunc   ;==>_Settings

Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $idFrom
    $idFrom = BitAND($wParam, 0xFFFF)
    Switch $idFrom
        Case $id_Settings
            _Settings()
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SYSCOMMAND

Func _Shutdown()
    AdlibUnRegister("_Bounce")
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGr_Buffer)
    _WinAPI_SelectObject($hDC_Buffer, $hOldFont)
    _WinAPI_DeleteObject($hFont1)
    _WinAPI_DeleteObject($hFont2)
    For $i = 1 To $aClr[0]
        _WinAPI_DeleteObject($aBrush[$i])
    Next
    _WinAPI_SelectObject($hDC_Buffer, $hOldBMP)
    _WinAPI_DeleteObject($hBMP)
    _WinAPI_DeleteDC($hDC_Buffer)
    _WinAPI_DeleteDC($hDC)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Shutdown

The game comes with the standard warranty of "It works on my PC" :)

Enjoy

Cheers

Edited by smashly
Link to comment
Share on other sites

Really great work on this! It's pretty fun..

A few little things I would tweak:

Scoring seems to be a bit weird due to the fact that the way to get the highest score is to just keep on dying and getting the bright flashy brick. Usually you get rewarded for not dying...

In normal game play it seems like the brick the user uses has issues when the ball tries to hit near the very edge.. there were a couple times when I thought it should of bounced off the corner but I just died instead..

I like the end game screen.. very classic and simple ;)

Edited by Achilles
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Thank you for the feedback and glad you all enjoyed.

@ wakillon added speed setting (for ball only, but it actually affects the balls bounce as well)

@Achilles, yep my collision detection blows..lol

The game itself wasn't really meant to be to challenging hence the cheap bonus mode.

I was sorta thinking outside the conventional way you get scores in a game, but I do agree it definitely needs tweaking.

Mild update to first post.

Cheers

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...