#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Physics Test!

edited January 2015 Posts: 100

Thanks to some help from coolCodea:

``````-- Physics

function setup()
physics.continuous=true
diam = 60
w1 = physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
w2 = physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
w3 = physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
w4 = physics.body(EDGE, vec2(0, HEIGHT), vec2(WIDTH, HEIGHT))
ball = physics.body(CIRCLE, 30)
ball.gravityScale = 1
ball.restitution = .8
ball.x = 50
ball.y = 50
ball.linearVelocity = vec2(5000, 5000)
end

function draw()
--Set up color stuff
background(0, 0, 0)

--Set up ball stuff
fill(255,0,0)
strokeWidth(0)

--Draw the ball using x,y position of physics object
ellipse(ball.x,ball.y,diam)

--Set up wall stuff
stroke(255, 255, 255, 255)
strokeWidth(2)

--Draw walls
line(0, 0, WIDTH, 0)
line(0, 0, 0, HEIGHT)
line(WIDTH, 0, WIDTH, HEIGHT)
line(0, HEIGHT, WIDTH, HEIGHT)
end

function touched(t)
if t.state == MOVING then
ball.linearVelocity = vec2(t.deltaX*100,t.deltaY*100)
end
end
``````
Tagged:
Sign In or Register to comment.