@Jarc Here’s some code, but I only have it working going in the down direction. The bottom and top line stops you going in the down direction, but the other directions just give you the collision warning. When the line stops you, you can move in the up direction once you get into the up area of the joystick.
PS. Added more code. Works in all directions, but needs more work.
displayMode(FULLSCREEN)
function setup()
hdx,hdy=0,0
Stop=0
parameter.watch("dy")
cx,cy=0,0
sx,sy=WIDTH/2,HEIGHT/2
dx,dy=0,0
fill(255)
stroke(255)
strokeWidth(1)
c1 = physics.body(CIRCLE,50) -- sprite collision circle
c1.type=DYNAMIC
c1.x=WIDTH/2
c1.y=400
c1.sleepingAllowed=false
c1.bullet=true
c2 = physics.body(CIRCLE,50) -- sprite collision circle
c2.type=STATIC
c2.x=WIDTH/2
c2.y=700
c2.sleepingAllowed=false
c2.bullet=true
l1= physics.body (EDGE, vec2(50,50),vec2(WIDTH-50,50))
l2= physics.body (EDGE, vec2(50,HEIGHT-50),vec2(WIDTH-50,HEIGHT-50))
l3= physics.body (EDGE, vec2(50,50),vec2(50,HEIGHT-50))
l4= physics.body (EDGE, vec2(WIDTH-50,50),vec2(WIDTH-50,HEIGHT-50))
end
function draw()
background(40, 40, 50)
noFill()
if cx>0 and cy>0 then
drawCirc()
end
line(50,50,WIDTH-50,50)
line(50,HEIGHT-50,WIDTH-50,HEIGHT-50)
line(50,50,50,HEIGHT-50)
line(WIDTH-50,50,WIDTH-50,HEIGHT-50)
if Stop==1 then
if hdx<0 then
if dx>0 then
Stop=0
end
end
if hdx>0 then
if dx<0 then
Stop=0
end
end
if hdy<0 then
if dy>0 then
Stop=0
end
end
if hdy>0 then
if dy<0 then
Stop=0
end
end
else
sx=sx+dx
sy=sy+dy
end
c1.x=sx
c1.y=sy
ellipse(c1.x,c1.y,100)
ellipse(c2.x,c2.y,100)
fill(255)
fontSize(20)
msg="No collision"
if Stop==1 then
msg="Collision"
end
text(msg,WIDTH/2,HEIGHT/2)
end
function touched(t)
if t.state==BEGAN then
cx,cy=t.x,t.y
end
if t.state==MOVING then
if insideCircle(t.x,t.y) then
dx=(t.x-cx)/10
dy=(t.y-cy)/10
else
cx,cy=0,0
dx,dy=0,0
end
end
if t.state==ENDED then
cc,cy=0,0
dx,dy=0,0
end
end
function insideCircle(x,y)
-- check if touch is inside of circle or ellipse
a,b=100,100 -- radius of circle or a,b of ellipse
if (x-cx)^2/a^2+(y-cy)^2/b^2 <= 1 then
return true
end
return false
end
function drawCirc()
fill(255, 255, 255, 50)
ellipse(cx,cy,50) -- draw circle center
fontSize(15)
fill(233, 80, 133)
text("Up",cx,cy+80)
text("Down",cx,cy-80)
text("Right",cx+80,cy)
text("Left",cx-80,cy)
fontSize(10)
text("DTL",cx-60,cy+60)
text("DTR",cx+60,cy+60)
text("DBL",cx-60,cy-60)
text("DBR",cx+60,cy-60)
noFill()
stroke(255,255,255,50)
strokeWidth(4)
ellipse(cx,cy,200) -- draw outer circle
end
function collide(c) -- this gets called when a collision occurs
if c.state==BEGAN then
print("\
collision")
print("radius of body A ",c.bodyA.radius)
print("radius of body B ",c.bodyB.radius)
Stop=1
hdx=dx
hdy=dy
end
end