Saturday, December 10, 2011

second test post

This is a second test post for code.

display.setStatusBar( display.HiddenStatusBar )
physics = require("physics")
physics.start( true )
physics.setGravity(0, 0)
middleX = display.contentWidth/2
middleY = display.contentHeight/2
math.randomseed(os.time())
math.random()
--physics.setDrawMode( "hybrid" )

function changeColor(event)
if event.phase == "began" then
randomRed = math.random(0,255)
randomBlue = math.random(0,255)
randomGreen = math.random(0,255)
ball:setFillColor(randomRed,randomBlue,randomGreen, 255)
timer.performWithDelay(100, makeBall)
end
end


leftWall = display.newRect( 0, 0, 10, 480 )
rightWall = display.newRect( 310, 0, 10, 480 )
topWall = display.newRect( 0, 0, 320, 10 )
bottomWall = display.newRect( 0, 470, 480, 10 )

physics.addBody(leftWall, "static", {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})
physics.addBody(rightWall, "static", {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})
physics.addBody(topWall, "static", {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})
physics.addBody(bottomWall, "static", {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})

background = display.newImage( "bkg_clouds.png" )

function makeBall()
ball = display.newCircle( math.random(100,300), math.random(100,400), 30 )
physics.addBody(ball, "dynamic", {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false, radius=30})
ball:applyForce(math.random(1000,10000),math.random(1000,10000),0,0)
end

makeBall()
ball:addEventListener("collision", changeColor)

Friday, December 9, 2011