Allow adjusting aim with mouse wheel

main
Tyler Scott 2022-02-13 13:46:52 +07:00
parent 444e4305c5
commit 61b08d5293
1 changed files with 22 additions and 8 deletions

View File

@ -289,6 +289,16 @@ local function find_unattached_bubbles()
return unattached return unattached
end 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() local function start_level()
game.game_over = false game.game_over = false
game.paused = false game.paused = false
@ -965,6 +975,17 @@ function love.mousepressed(x, y, button, is_touch, presses)
end end
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) function love.mousemoved(x, y, dx, dy, is_touch)
if not game.game_over then if not game.game_over then
local diff_x = x - game.launcher_x local diff_x = x - game.launcher_x
@ -976,14 +997,7 @@ function love.mousemoved(x, y, dx, dy, is_touch)
angle = angle + tau angle = angle + tau
end end
-- don't allow aiming backwards game.launcher_rotation = 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
game.launcher_rotation = angle
if game.show_aim_guide then if game.show_aim_guide then
generate_aim_guide(game.launcher_rotation) generate_aim_guide(game.launcher_rotation)