diff --git a/lib/demo/bowling.lua b/lib/demo/bowling.lua index 39d876b..23d7bd5 100644 --- a/lib/demo/bowling.lua +++ b/lib/demo/bowling.lua @@ -72,14 +72,41 @@ function init_event() resetPins() setupStars() setupScore() - ag.setCamera(0, -10, 5, 0, 20, 0) + position_x = 0 + target_x = 0 game_state = "waiting" + last_update_time = ag.elapsedTime() end function update_event() + ag.setCamera(position_x, -10, 5, target_x, 20, 0) + local now = ag.elapsedTime() + if (ag.isKeyDown("a") or ag.isKeyDown("left")) then + position_x = position_x - (now - last_update_time) / 300 + if (position_x < -2) then + position_x = -2 + end + end + if (ag.isKeyDown("d") or ag.isKeyDown("right")) then + position_x = position_x + (now - last_update_time) / 300 + if (position_x > 2) then + position_x = 2 + end + end + last_update_time = now + ag.callList(stars) end +function mouse_motion_event(x, y, xrel, yrel) + target_x = target_x + xrel / 100 + if (target_x < -2) then + target_x = -2 + elseif (target_x > 2) then + target_x = 2 + end +end + function drawFrameScore(width, height, frame, fs) local size = 60 local ball_size = 24 @@ -146,6 +173,8 @@ end function launchBall() game_state = "launched" launch_time = ag.elapsedTime() + bowling_ball = reference_ball:clone() + bowling_ball:setPosition(position_x, -10, 4) end function drawPowerBar(width, height)