working on bowling demo
git-svn-id: svn://anubis/anaglym/trunk@208 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
ce734b2ef0
commit
bf2485ced5
@ -61,14 +61,19 @@ function init_event()
|
||||
minx, miny, minz, maxx, maxy, maxz = reference_pin:getAABB()
|
||||
pin_minz = minz
|
||||
pin_maxz = maxz
|
||||
local box = ag.createBoxStatic(1, 1, 0.1)
|
||||
box:setColor(0, 0, 0)
|
||||
local box = ag.createBoxStatic(1, 10, 0.1)
|
||||
box:setVisible(false)
|
||||
box:setPosition(0, 0, lane_bottom - (maxz - minz) - 0.4)
|
||||
reference_pin:setPosition(0, 0, lane_bottom - maxz - 0.1)
|
||||
reference_ball = ag.createSphere(0.3)
|
||||
reference_ball:setColor(0.7, 0.1, 0.9)
|
||||
reference_ball:setMass(50)
|
||||
reference_ball:setPosition(0, -2, -1.5)
|
||||
resetPins()
|
||||
setupStars()
|
||||
setupScore()
|
||||
ag.setCamera(0, -10, 5, 0, 20, 0)
|
||||
game_state = "waiting"
|
||||
end
|
||||
|
||||
function update_event()
|
||||
@ -95,15 +100,15 @@ function drawFrameScore(width, height, frame, fs)
|
||||
balls = 3
|
||||
end
|
||||
for ball = 1, balls do
|
||||
-- if ((frame < current_frame) or (frame == current_frame and ball < current_ball)) then
|
||||
if ((frame < current_frame) or (frame == current_frame and ball < current_ball)) then
|
||||
local ball_base_x = base_x + local_width - (1 + balls - ball) * ball_size + 7
|
||||
local ball_base_y = base_y + size - ball_size + 7
|
||||
ag.drawText(fs[ball], 1, 0.6, 0, 14, ball_base_x, ball_base_y)
|
||||
-- if (frame < current_frame and fs["tot"] ~= 0) then
|
||||
if (frame < current_frame and fs["tot"] ~= 0) then
|
||||
local w, h = ag.getTextSize(fs["tot"], 16)
|
||||
ag.drawText(fs["tot"], 1, 0.6, 0, 16, base_x + local_width - 10 - w, base_y + 10)
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -116,4 +121,50 @@ end
|
||||
|
||||
function update_overlay_event(width, height)
|
||||
drawScore(width, height)
|
||||
if (game_state == "get_power" or game_state == "launched") then
|
||||
drawPowerBar(width, height)
|
||||
end
|
||||
end
|
||||
|
||||
function mousebutton_down_event(button, x, y)
|
||||
if (button == 1) then
|
||||
if (game_state == "waiting") then
|
||||
getPower()
|
||||
elseif (game_state == "get_power") then
|
||||
launchBall()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function getPower()
|
||||
game_state = "get_power"
|
||||
power = 0
|
||||
power_last_time = ag.elapsedTime()
|
||||
power_direction = 1
|
||||
end
|
||||
|
||||
function launchBall()
|
||||
game_state = "launched"
|
||||
launch_time = ag.elapsedTime()
|
||||
end
|
||||
|
||||
function drawPowerBar(width, height)
|
||||
local bar_width = 80
|
||||
local bar_height = 400
|
||||
if (game_state == "get_power") then
|
||||
local now = ag.elapsedTime()
|
||||
power = power + (now - power_last_time) / 250 * power_direction
|
||||
if (power > 1) then
|
||||
power = 1
|
||||
power_direction = -1
|
||||
elseif (power < 0) then
|
||||
power = 0
|
||||
power_direction = 1
|
||||
end
|
||||
power_last_time = now
|
||||
end
|
||||
ag.drawRect(1, 1, 1, bar_width, bar_height,
|
||||
width - 50 - bar_width / 2, height / 2)
|
||||
ag.fillRect(0.1, 1, 0.1, bar_width - 2, (bar_height - 2) * power,
|
||||
width - 50 - bar_width / 2, height / 2)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user