Main.lua 917 B

1234567891011121314151617181920212223242526272829
  1. scene = PhysicsScene(0, Vector3(200, 200, 200))
  2. ground = ScenePrimitive(ScenePrimitive.TYPE_PLANE, 10, 10)
  3. ground:loadTexture("Resources/green_texture.png")
  4. scene:addPhysicsChild(ground, 6, 0)
  5. for i = 1, 100 do
  6. local box = ScenePrimitive(ScenePrimitive.TYPE_BOX, 0.5,0.5,0.5)
  7. box:loadTexture("Resources/pink_texture.png")
  8. box:Roll(-45 + math.random() % 90)
  9. box:Pitch(-45 + math.random() % 90)
  10. box:setPosition(-2 + math.random() % 4, i*0.5, -2 + math.random() % 4)
  11. scene:addPhysicsChild(box, 0, 1)
  12. end
  13. scene:getDefaultCamera():setPosition(7, 7, 7)
  14. scene:getDefaultCamera():lookAt(Vector3(0, 0, 0), Vector3(0, 1, 0))
  15. collisionSound = Sound("Resources/hit.wav")
  16. function onCollisionEvent(t, event)
  17. local physEvent = safe_cast(event, PhysicsSceneEvent)
  18. if physEvent.appliedImpulse > 2 then
  19. collisionSound:Play()
  20. end
  21. end
  22. scene:addEventListener(nil, onCollisionEvent, PhysicsSceneEvent.COLLISION_EVENT)