Now consider the following:
<hr/>Code:Select Case JoystickDat.dwXpos '// 'right? '// Case Is > 50000 If Boat_ID <> 2 Then 'sound on condition If Master_SND_EN Then If AllowRowSND = 0 And Jumping = False And Allow_SND_Effects = True Then SND = sndPlaySound(App.Path & "\Water.wav", CSNDaSync) AllowRowSND = 1 'sound effect once only End If ' End If '// ' Rowing_Forward = True 'set flag Rowing_Backward = False 'set flag '// ' If Jumping Then ' 'lmitied control when airborne ' PlayerX = PlayerX + (PlayerX < 375) * -1 'inc 1 pixel Boat_ID = 4 'ors out img Else ' 'maintain screen limitations and inc boat forward PlayerX = PlayerX + (PlayerX < 250) * -(1 + Row_Speed) Row_Speed = Row_Speed + (Row_Speed < 20) * -2 Boat_ID = 2 'row img End If '// ' Else ' '// ' If Jumping Then ' Boat_ID = 4 'ors in img Else ' Boat_ID = 1 'ors out img End If ' End If '// 'joystick center? '// Case Is > 500 And JoystickDat.dwXpos < 50000 If Jumping = False Then If Master_SND_EN Then If Row_Speed = 5 And Allow_SND_Effects = True Then SND = sndPlaySound(App.Path & "\Water B.wav", CSNDaSync) End If End If '// Row_Speed = Row_Speed + (Row_Speed > 0) * 1 'grad dec speed ' '// ' If Rowing_Forward Then ' Boat_ID = Boat_ID + (Boat_ID = 2) * 1 'reset image Rowing_Forward = False 'flag AllowRowSND = 0 'en sound for next time Else ' Boat_ID = Boat_ID + (Boat_ID = 0) * -1 'reset image AllowRowSND = 0 'en sound Rowing_Backward = False 'flag End If End If '// 'left? '// Case Is < 500 If Boat_ID <> 0 Then 'sound on condition If Master_SND_EN Then If AllowRowSND = 0 And Jumping = False And Allow_SND_Effects = True Then SND = sndPlaySound(App.Path & "\Water.wav", CSNDaSync) AllowRowSND = 1 'en sound End If ' End If '// Rowing_Backward = True 'set action flag Rowing_Forward = False 'set flag '// ' If Jumping = False Then ' PlayerX = PlayerX + (PlayerX > 50) * 10 'inc 10 pixel backward Row_Speed = Row_Speed + (Row_Speed > 0) * 2 'grad dec speed ' Boat_ID = 0 'row back img Else 'lmitied control when airborne ' PlayerX = PlayerX + (PlayerX > 50) * 1 ' Boat_ID = 4 'ors out End If '// Else '// If Jumping Then Boat_ID = 4 'ors out img Else ' Boat_ID = 1 'ors in img End If End If End Select '//---// 'Y-axis '//---// Select Case JoystickDat.dwYpos '// 'up? '// Case Is < 500 If Jumping Then PlayerY = PlayerY + (PlayerY > 375) * 2 'inc 2 Else PlayerY = PlayerY + (PlayerY > 375) * 5 'inc 5 End If '// 'down '// Case Is > 50000 If Jumping Then PlayerY = PlayerY + (PlayerY < 475) * -2 'inc 2 pixel Else ' PlayerY = PlayerY + (PlayerY < 475) * -5 'inc 5 End If End Select
Now, while Select Case itself isn't used for all decision making, its main role here is for structure. It greatly improves clarity and organization. It clearly separates the algorithm into much more easily manageable parts. It's perhaps not quite that obvious in this example because there's really on 2 parts in each Select Case.
<br/>




Bookmarks