我希望我的形状不要超出窗口区域。例如,当我按下左键时,形状会移出窗口区域,但我希望它撞到一边并留在那里。
def update
if button_down?(Gosu::KbRight)
if @shape_x != (WIDTH - SHAPE_DIM)
@shape_x += 3
end
end
if button_down?(Gosu::KbLeft)
if @shape_x != (WIDTH - SHAPE_DIM)
@shape_x -= 3
end
end
if button_down?(Gosu::KbUp)
@shape_y -= 3
end
if button_down?(Gosu::KbDown)
@shape_y += 3
end
end