working on bowling demo

git-svn-id: svn://anubis/anaglym/trunk@212 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-12-14 00:21:24 +00:00
parent 1a8d0cc700
commit 5ec32efdd0

View File

@ -1,6 +1,14 @@
ag.import("std")
function newGame()
setupScore()
newFrame()
position_x = 0
target_x = 0
game_state = "waiting"
end
function resetPins()
local head_x = 0
local head_y = 15
@ -73,12 +81,9 @@ function init_event()
reference_ball:setMass(10)
reference_ball:setPosition(0, -2, -1.5)
setupStars()
setupScore()
position_x = 0
target_x = 0
game_state = "waiting"
mouse_moved = false
newFrame()
newGame()
last_update_time = ag.elapsedTime()
setCamera(last_update_time)
end
@ -125,10 +130,10 @@ end
function mouse_motion_event(x, y, xrel, yrel)
if (mouse_moved and game_state == "waiting") then
target_x = target_x + xrel / 100
if (target_x < -2) then
target_x = -2
elseif (target_x > 2) then
target_x = 2
if (target_x < -3) then
target_x = -3
elseif (target_x > 3) then
target_x = 3
end
end
mouse_moved = true
@ -186,6 +191,16 @@ function update_overlay_event(width, height)
ag.drawLine(0, 1, 0, width / 2, height / 2 - cursor_size, width / 2, height / 2 + cursor_size)
ag.drawLine(0, 1, 0, width / 2 - cursor_size, height / 2, width / 2 + cursor_size, height / 2)
end
if (game_state == "gameover") then
local w, h = ag.getTextSize("GAME OVER", 72)
ag.drawText("GAME OVER", 1, 1, 0, 72, width / 2 - w / 2, height * 0.7 + 20)
local score_str = string.format("Score: %d", score[10]["tot"])
w, h = ag.getTextSize(score_str, 56)
ag.drawText(score_str, 1, 1, 0, 56, width / 2 - w / 2, height * 0.7 - 20 - h / 2)
end
end
function key_down_event(key)
end
function mousebutton_down_event(button, x, y)
@ -196,6 +211,8 @@ function mousebutton_down_event(button, x, y)
getAccuracy()
elseif (game_state == "get_accuracy") then
launchBall()
elseif (game_state == "gameover") then
newGame()
end
end
end
@ -219,7 +236,7 @@ function launchBall()
launch_time = ag.elapsedTime()
bowling_ball = reference_ball:clone()
bowling_ball:setPosition(position_x, -10, 1.26)
local fx = target_x + accuracy - position_x
local fx = target_x + accuracy * 1.2 - position_x
local fy = 30 -- should match setCamera()'s dy
local d = math.sqrt(fx*fx + fy*fy)
fx = fx / d
@ -299,7 +316,7 @@ function updateScore(pin_count)
score[f]["tot"] = prevscore + 10 + score[f+1][1]
end
else
score[f]["tot"] = score[f][1] + score[f][2]
score[f]["tot"] = prevscore + score[f][1] + score[f][2]
end
end
if (pin_count == 10 and current_frame < 10) then
@ -355,7 +372,7 @@ function drawAccuracyBar(width, height)
local bar_height = 60
if (game_state == "get_accuracy") then
local now = ag.elapsedTime()
accuracy = accuracy + (now - accuracy_last_time) / 250 * accuracy_direction
accuracy = accuracy + (now - accuracy_last_time) / 200 * accuracy_direction
if (accuracy > 1) then
accuracy = 1
accuracy_direction = -1