Hey! I would love some help and suggestions with my code! The collision detection I need the most help with, the cup and pickle do not collide. Thanks everyone! :)>-
-- Pickle in a Cup
function setup()
pickle = physics.body(CIRCLE, 20)
-- pickle.gravityScale = 1
pickle.x = WIDTH/8
pickle.y = HEIGHT-50
cup = vec2((WIDTH/8)-50, 100)
random=1
end
function draw()
pickle.type = STATIC
pickle.y = pickle.y - 14
sprite("Dropbox:chowder-cartoon-network-wallpaper-26",WIDTH/2,HEIGHT/2, WIDTH, HEIGHT)
sprite("Dropbox:chases-pickle", pickle.x, pickle.y, 80, 150)
fill(255, 255, 255, 255)
rect(cup.x,cup.y, 100, 100)
if cup.x < 0 then
cup.x=cup.x+WIDTH/4
end
if cup.x > 768 then
cup.x=cup.x-WIDTH/4
end
if pickle.y<0 then
random=math.random(1,4)
pickle.y=HEIGHT-50
if
random==1 then pickle.x=WIDTH/8 end
if random==2 then pickle.x=(3*WIDTH)/8 end
if random==3 then pickle.x=(5*WIDTH)/8 end
if random==4 then pickle.x= (7*WIDTH)/8 end
if pickle.y<=cup.y+100 and pickle.x<=cup.x+50 and pickle.x>=cup.x-50 then
random=math.random(1,4)
pickle.y=HEIGHT-50 end
if random==1 then pickle.x=WIDTH/8 end
if random==2 then pickle.x=(3*WIDTH)/8 end
if random==3 then pickle.x=(5*WIDTH)/8 end if random==4 then pickle.x= (7*WIDTH)/8 end
end
end
function touched(touch)
if cup.x > 0 and cup.x <768 then
if touch.state==BEGAN then
if touch.x < WIDTH/2 then
cup.x=cup.x-WIDTH/4
end
if touch.x > WIDTH/2
then cup.x=cup.x+WIDTH/4
end
end
end
end