Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Code 08b - Physics BallBounce
- -- Will upload to Codea
- -- Bruce Elliott
- -- April 2013
- -- Ball will fall in the direction of the iPad tilt
- -- when it hits a wall it will bounce
- -- Fix the orientation and use fullscreen
- supportedOrientations(PORTRAIT)
- displayMode(FULLSCREEN)
- -- How much bounce there is change to get different bounce
- bouncy = .5
- -- Create a physics edge
- function createWall(x1, y1, x2, y2)
- local temp = physics.body(EDGE, vec2(x1,y1), vec2(x2,y2))
- temp.type = STATIC
- temp.restitution = bouncy
- return temp
- end
- function setup()
- -- Create circle named ball
- ball = physics.body(CIRCLE, 28)
- ball.x = WIDTH/2
- ball.y = HEIGHT/2
- ball.restitution = bouncy
- ball.sleepingAllowed = false
- end
- function draw()
- background(40,40,50)
- fill(255)
- strokeWidth(5)
- stroke(255)
- -- Build physics walls
- createWall(50,50,50,HEIGHT -50)
- createWall(50,50,WIDTH -50,50)
- createWall(WIDTH -50,50,WIDTH -50,HEIGHT -50)
- createWall(WIDTH -50,HEIGHT-50,50,HEIGHT-50)
- -- Draw visible walls
- line(50,50,50,HEIGHT-50)
- line(50,50,WIDTH-50,50)
- line(WIDTH-50,50,WIDTH-50,HEIGHT-50)
- line(WIDTH-50,HEIGHT-50,50,HEIGHT-50)
- -- Gravity set to device gravity
- physics.gravity(Gravity)
- -- Draw visible ball uses physics ball values
- ellipse(ball.x, ball.y, ball.radius*2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement