Created
December 26, 2011 11:54
-
-
Save wookay/1520978 to your computer and use it in GitHub Desktop.
Test MOAI chipmunk physics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- test_moai_chipmunk.lua | |
-- wookay.noh at gmail.com | |
package.path = package.path .. ";../?.lua" | |
require 'libmoai' | |
function test_moai_chipmunk() | |
local layer = Sim.layer() | |
layer.enableTouchEvents() | |
local deck = Deck.new("./images/cathead.png") | |
local prop = Prop.new(deck) | |
layer.add(prop) | |
local space = layer.addSpace({0,-2000}) | |
local body = space.addProp(prop, 0.8, 0.8, 'cat') | |
space.addWall(Screen.frame, 1, 0.1, 'wall') | |
layer.addListener(space.joint_listener()) | |
function layer.addButton(title, origin, fun) | |
local button = TextButton.new(title, fun) | |
button.frame = {origin, {120,40}} | |
button.wrap:setTextSize(15) | |
layer.add(button) | |
end | |
layer.addButton("applyForce(f,r)", {190,105}, function() | |
body.applyForce({0,2030},{0,0}) | |
end) | |
layer.addButton("applyImpulse(j,r)", {190,155}, function() | |
body.applyImpulse({100,500},{0,0}) | |
end) | |
layer.addButton("resetForces()", {190,205}, function() | |
body.resetForces() | |
end) | |
assert_equal(body.angVel, body.wrap:getAngVel()) | |
assert_equal(body.pos, {body.wrap:getPos()}) | |
body.wrap:setPos(1, 2) | |
assert_equal({1,2}, body.pos) | |
body.pos = {3,4} | |
assert_equal({3,4}, body.pos) | |
layer.addExitButton() | |
end | |
if is_main() then | |
UnitTest.run() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment