The craft animation prototype:
-- JS3D C06 ?????
function setup()
-- ????
scene = craft.scene()
-- ????????????????????
scene.sky.active = true
scene.sun.active = true
scene.sun:get(craft.light).intensity = 0.5
scene.ambientColor = color(112, 158, 194)
-- ?????????????
scene.camera.position = vec3(0, 0, -800)
cam = scene.camera:get(craft.camera)
cam.fieldOfView = 60
cam.farPlane = 3000
makeAvatar()
makeTreeAt(200,0)
makeTreeAt(-200,0)
makeTreeAt(200,750)
makeTreeAt(-200,750)
end
-- ????
function makeAvatar()
-- ??????????3D?????
marker = scene:entity()
-- ????????
local model = craft.model.icosphere(30, 1, true)
local material = craft.material(asset.builtin.Materials.Standard)
body = scene:entity()
body:add(craft.renderer, model)
body.material = material
body.position = vec3(0,0,0)
body.parent = marker
scene.camera.parent = marker
-- Create hands feet,?????
local model = craft.model.icosphere(15,1,true)
local material = craft.material(asset.builtin.Materials.Standard)
leftHand = scene:entity()
leftHand:add(craft.renderer, model)
leftHand.material = material
leftHand.position = vec3(45,0,0)
leftHand.parent = body
rightHand = scene:entity()
rightHand:add(craft.renderer, model)
rightHand.material = material
rightHand.position = vec3(-45,0,0)
rightHand.parent = body
leftFoot = scene:entity()
leftFoot:add(craft.renderer, model)
leftFoot.material = material
leftFoot.position = vec3(20,-45,0)
leftFoot.parent = body
rightFoot = scene:entity()
rightFoot:add(craft.renderer, model)
rightFoot.material = material
rightFoot.position = vec3(-20,-45,0)
rightFoot.parent = body
-- ???????
isCartwheeling = false
isFlipping = false
isMovingRight = false
isMovingLeft = false
isMovingForeward = false
isMovingBack = false
end
function makeTreeAt(x,z)
trunk = scene:entity()
trunk.model = craft.model.cube(vec3(30,90,30))
trunk.material = craft.material(asset.builtin.Materials.Standard)
trunk.material.diffuse = color(123, 116, 60)
trunk.position = vec3(x, -75, z)
top = scene:entity()
top.model = craft.model.icosphere(60,1,true)
top.material = craft.material(asset.builtin.Materials.Standard)
top.material.diffuse = color(89, 198, 35)
top.y = 90
top.parent = trunk
end
function isWalking()
if isMovingRight then return true end
if isMovingLeft then return true end
if isMovingForeward then return true end
if isMovingBack then return true end
return false
end
function walk()
if (not isWalking()) then return end
local speed = 10
local size = 100
local time = ElapsedTime
position =math.sin(speed*time)*size
rightHand.z = position
leftHand.z = -position
rightFoot.z = -position
leftFoot.z = position
end
function acrobatics()
if (isCartwheeling) then
local t = ElapsedTime
local br = body.rotation
body.rotation = quat.eulerAngles(br.x, br.y, br.z+100*t)
end
if (isFlipping) then
local speed = 10
local size = 90
local time = ElapsedTime
p =time*size
body.rotation = quat.eulerAngles(0,0,p)
end
end
function update(dt)
-- ??????
walk()
acrobatics()
-- ????
scene:update(dt)
end
-- Codea ?????????60?
function draw()
update(DeltaTime)
-- ????
scene:draw()
end
-- ??????
function keyboard(key)
print(key.state)
local k = key
if k == "c" then isCartwheeling = not isCartwheeling end
if k == "f" then isFlipping = not isFlipping end
if k == "a" then marker.x = marker.x + 15; isMovingLeft = true end
if k == "d" then marker.x = marker.x - 15; isMovingRight = true end
if k == "w" then marker.z = marker.z + 15; isMovingForeward = true end
if k == "s" then marker.z = marker.z - 15; isMovingBack = true end
end
function touched(touch)
-- ????????
showKeyboard()
end
The Bone craft project: