I have some code that moves platforms down when touched. I’m trying to draw a ball on the platform and use physics to make the ball look like it jumps either up if pressed on the side of the screen it’s on or the other direction if pressed on the other side of the screen. Could someone help me with this?
Code:
-- Use this function to perform your initial
displayMode(FULLSCREEN)
function setup()
Side=0
Piececounter=1
Jumpdistance=300
shiftcounter = 0
y = {}
side = {}
for i=1,10 do
side[i] = math.random(0,1)
y[i] = Jumpdistance*i
end
shift = 0
end
-- This function gets called once every frame
function draw()
background(82,243,243)
-- Set stroke and fill color to white
fill(255,0,0)
stroke(255)
-- Update stroke width
strokeWidth(10)
smooth()
-- Set the line cap mode
lineCapMode(ROUND)
if(shift==1) then
shiftnow()
end
DrawPieces()
DrawMiddle()
DrawCharacter()
end
function shiftnow()
if (shiftcounter>0) then
shiftcounter = shiftcounter - 5
end
print(shiftcounter)
if(shiftcounter<=0)then
Piececounter = Piececounter + 1
if(Piececounter==11)then
Piececounter=1
end
shift=0
end
for i=1,10 do
y[i] = y[i] - 30
end
if(y[3]<0)then
table.remove(y,1)
table.remove(side,1)
table.insert(y,10,y[9]+Jumpdistance)
table.insert(side,10,math.random(0,1))
end
end
function DrawCharacter()
end
function DrawPieces()
for i=1,10 do
-- Draw the line
if(side[i]==0) then
fill(255,0,0)
stroke(255)
rect((WIDTH/2)-200,y[i],200,70)
else
fill(80, 117, 206, 255)
stroke(255)
rect((WIDTH/2),y[i],200,70)
end
end
end
function DrawMiddle()
stroke(255, 255, 255, 255)
line(WIDTH/2,-10,WIDTH/2,HEIGHT+10)
end
function touched (touch)
if(CurrentTouch.state==BEGAN)then
shift = 1
shiftcounter = 50
end
end