首先,您可以将每个 if else 更改为以下内容:
BITMAP_PATH = "Graphics/Pictures/Input Map/switch"
if @selection==1 && @unlock1
pbSEPlay("BW2MenuChoose",65)
bitmap_switch = $switches[310] ? 'off' : 'on' # sets path to off/on
@graphics["switch"].setBitmap(BITMAP_PATH + bitmap_switch)
!$switches[310] # it changes value of boolean to opposite value
end
只有一个条件的选择可以这样写:
if @selection==0 && @unlock0
pbSEPlay("buzzer",65)
end
您也可以尝试为@selection 编写 case 表达式。也许你可以把它弄得更干一些,但我不太明白每个 @unlock 的用途。
编辑:
BITMAP_PATH = "Graphics/Pictures/Input/switch"
SELECTION_SWITCHES = [nil, 310, 300, 339, 338, 330, 318]
def pbChangeSwitch
case
when 0
case @selection
when 0,7
pbSEPlay("buzzer",65) if instance_variable_get("@unlock#{@selection}")
when 1..6
if instance_variable_get("@unlock#{@selection}")
pbSEPlay("BW2MenuChoose",65)
bitmap_switch = $switches[SELECTION_SWITCHES[@selection]] ? 'off' : 'on'
@sprites["switch"].setBitmap(BITMAP_PATH + bitmap_switch)
index = SELECTION_SWITCHES[@selection]
$switches[index] = !$switches[index]
end
end
Graphics.update
请在最后一行添加$。 bitmap_switch 不能是true 或false,因为你添加到BITMAP_PATH,所以它必须是'off' 或'on'。