couch/main.lua

73 lines
1.6 KiB
Lua
Raw Normal View History

2021-01-13 16:47:16 -06:00
local ball
local camera
2021-01-13 18:51:58 -06:00
local LEFT = 263
local RIGHT = 262
local UP = 265
local DOWN = 264
2021-01-13 20:50:08 -06:00
local Q = 81
2021-01-13 18:51:58 -06:00
local vx = 0.0
local vz = 0.0
local ballvy = -1.0
2021-01-13 20:50:08 -06:00
local cam_rot_x = 0.0
2021-01-13 16:47:16 -06:00
function init()
camera = couch.Camera()
camera:MakeCurrent()
2021-01-13 20:08:39 -06:00
camera.transform:Translate(0.0, 0.0, 10.0)
2021-01-13 16:47:16 -06:00
ball = couch.Ball()
ball:SetupMesh()
couch.AddMeshToList(ball)
2021-01-13 18:51:58 -06:00
ball1 = couch.Ball()
ball1:SetupMesh()
couch.AddMeshToList(ball1)
ball1.transform:Translate(0.0, 3.0, 0.0)
2021-01-13 16:47:16 -06:00
end
function update(delta)
2021-01-13 18:51:58 -06:00
camera.transform:Translate(vx * delta, 0.0, vz * delta)
2021-01-13 20:50:08 -06:00
camera.transform.rotation.y = camera.transform.rotation.y + cam_rot_x * delta
2021-01-13 18:51:58 -06:00
local loc = ball1.transform.position
if loc.y > 4.0 then
ballvy = -1.0
elseif loc.y < 2.0 then
ballvy = 1.0
end
2021-01-13 20:08:39 -06:00
ball1.transform.position.y = ball1.transform.position.y + ballvy * delta
ball.transform.rotation.z = ball.transform.rotation.z + 1.0 * delta;
2021-01-13 20:50:08 -06:00
ball.transform.rotation.y = ball.transform.rotation.y + 1.0 * delta;
2021-01-13 20:08:39 -06:00
ball.transform.rotation.x = ball.transform.rotation.x + 1.0 * delta;
2021-01-13 18:51:58 -06:00
end
function onkey(key, code, action, mod)
if key == LEFT and action == 1 then
vx = -1.0
elseif key == RIGHT and action == 1 then
vx = 1.0
elseif (key == LEFT or key == RIGHT) and action == 0 then
vx = 0.0
end
if key == UP and action == 1 then
vz = -1.0
elseif key == DOWN and action == 1 then
vz = 1.0
elseif (key == DOWN or key == UP) and action == 0 then
vz = 0.0
end
2021-01-13 20:50:08 -06:00
if key == Q then
if action == 1 then
cam_rot_x = 1.0
else
cam_rot_x = 0.0
end
end
2021-01-13 16:47:16 -06:00
end