Allow adjusting aim with mouse wheel
parent
444e4305c5
commit
61b08d5293
30
main.lua
30
main.lua
|
|
@ -289,6 +289,16 @@ local function find_unattached_bubbles()
|
|||
return unattached
|
||||
end
|
||||
|
||||
-- don't allow aiming backwards or straight sideways
|
||||
local function clamp_launcher_angle(angle)
|
||||
if (angle >= 0 and angle <= tau / 4) or angle >= tau * 25 / 26 then
|
||||
angle = tau * 25 / 26
|
||||
elseif angle >= tau / 4 and angle <= tau * 14 / 26 then
|
||||
angle = tau * 14 / 26
|
||||
end
|
||||
return angle
|
||||
end
|
||||
|
||||
local function start_level()
|
||||
game.game_over = false
|
||||
game.paused = false
|
||||
|
|
@ -965,6 +975,17 @@ function love.mousepressed(x, y, button, is_touch, presses)
|
|||
end
|
||||
end
|
||||
|
||||
function love.wheelmoved(x, y)
|
||||
if y ~= 0 then
|
||||
local angle = game.launcher_rotation
|
||||
angle = angle + (y < 0 and 0.01 or -0.01)
|
||||
game.launcher_rotation = clamp_launcher_angle(angle)
|
||||
if game.show_aim_guide then
|
||||
generate_aim_guide(game.launcher_rotation)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function love.mousemoved(x, y, dx, dy, is_touch)
|
||||
if not game.game_over then
|
||||
local diff_x = x - game.launcher_x
|
||||
|
|
@ -976,14 +997,7 @@ function love.mousemoved(x, y, dx, dy, is_touch)
|
|||
angle = angle + tau
|
||||
end
|
||||
|
||||
-- don't allow aiming backwards
|
||||
if (angle >= 0 and angle <= tau / 4) or angle >= tau * 25 / 26 then
|
||||
angle = tau * 25 / 26
|
||||
elseif angle >= tau / 4 and angle <= tau * 14 / 26 then
|
||||
angle = tau * 14 / 26
|
||||
end
|
||||
|
||||
game.launcher_rotation = angle
|
||||
game.launcher_rotation = clamp_launcher_angle(angle)
|
||||
|
||||
if game.show_aim_guide then
|
||||
generate_aim_guide(game.launcher_rotation)
|
||||
|
|
|
|||
Loading…
Reference in New Issue