Code is working so far but some efficiency tips would definitely help. Thanks!
-- Car Road Game
function setup()
CarX = 100
CarY = (3*HEIGHT)/8
holeX = 1300
holeY = 0
holeX2=1300
holeY2=0
holeX3=1300
holeY3=0
holeX4=1300
holeY4=0
score=0
speed=10
angle=-1000
collision=false
s=45
startheight=HEIGHT/2
d=math.random(1,4)
e=math.random(1,4)
f=math.random(1,4)
g=math.random(1,4)
wave2=false
end
function draw()
background(92, 92, 92, 255)
strokeWidth(5)
fill(255, 255, 255, 255)
rect(0,HEIGHT/4,1100,10)
rect(0,HEIGHT/2,1100,10)
rect(0,(3*HEIGHT)/4,1100,10)
sprite("Dropbox:cargamestart", WIDTH/2,startheight, 1024)
if CurrentTouch.x<=360 and CurrentTouch.x>=195 and CurrentTouch.y>=150 and CurrentTouch.x<=600 then
startheight=20000
end
if startheight==20000 then
sprite("Dropbox:yellowcar",CarX,CarY,150)
sprite("Dropbox:8A66B6CC",holeX,holeY+5,140)
sprite("Dropbox:8A66B6CC", holeX2, holeY2+5,140)
sprite("Dropbox:8A66B6CC", holeX3, holeY3+5,140)
sprite("Dropbox:8A66B6CC", holeX4, holeY4+5, 140)
sprite("Dropbox:13165542591764506524plain-highway-exit-sign-svg-hi",900,HEIGHT/2,200)
fill(255, 255, 255, 255)
fontSize(65)
translate(885,HEIGHT/2)
rotate(270)
text(score/4,0,0)
holeX=holeX-speed
holeX2=holeX2-speed
holeX3=holeX3-speed
holeX4=holeX4-speed
end
--Boundaries
if CarY>=HEIGHT then
CarY=(7*HEIGHT)/8
end
if CarY<=0 then
CarY=(1*HEIGHT)/8
end
if holeX<=-100 and collision==false then
holeX=1300
end
if holeX==-100 then
score=score+1
end
if holeX==1300 then
d=math.random(1,4)
end
if holeX2<=-100 and collision==false then
holeX2=1300
end
if holeX2==-100 then
score=score+1
end
if holeX2==1300 then
e=math.random(1,4)
end
if holeX3<=-100 and collision==false then
holeX3=1300
end
if holeX3==-100 then
score=score+1
end
if holeX3==1300 then
f=math.random(1,4)
end
if holeX4<=-100 and collision==false then
holeX4=1300
end
if holeX4==-100 then
score=score+1
end
if holeX4==1300 then
g=math.random(1,4)
end
--Random Spawning
if d==1 then
holeY=HEIGHT/8
end
if d==2 then
holeY=(3*HEIGHT)/8
end
if d==3 then
holeY=(5*HEIGHT)/8
end
if d==4 then
holeY=(7*HEIGHT)/8
end
if e==1 then
holeY2=HEIGHT/8
end
if e==2 then
holeY2=(3*HEIGHT)/8
end
if e==3 then
holeY2=(5*HEIGHT)/8
end
if e==4 then
holeY2=(7*HEIGHT)/8
end
if f==1 then
holeY3=HEIGHT/8
end
if f==2 then
holeY3=(3*HEIGHT)/8
end
if f==3 then
holeY3=(5*HEIGHT)/8
end
if f==4 then
holeY3=(7*HEIGHT)/8
end
if g==1 then
holeY4=HEIGHT/8
end
if g==2 then
holeY4=(3*HEIGHT)/8
end
if g==3 then
holeY4=(5*HEIGHT)/8
end
if g==4 then
holeY4=(7*HEIGHT)/8
end
--Scoring
if holeX==CarX then
score=score+1
end
if holeX2==CarX then
score=score+1
end
if holeX3==CarX then
score=score+1
end
if holeX4==CarX then
score=score+1
end
--Waves
if score/4==5 and collision==false then
fontSize(30)
translate(0,-400)
rotate(angle)
fontSize(s)
fill(255, 154, 0, 255)
text("Wave 2",0,0)
wave2=true
end
angle=angle+5
if wave2==true then
speed=20
end
--Keeping from spawning in different lanes
if (e+f+g+d)==10 then
holeY=-10000
end
--Collision Detection
if holeX-CarX<=135 or holeX2-CarX<=135 or holeX3-CarX<=135 or holeX4-CarX<=135 then
CarX=CarX-speed
collision=true
end
end
function touched(touch)
if touch.state==BEGAN then
if touch.y>HEIGHT/2 then
CarY=CarY+HEIGHT/4
end
if touch.y<HEIGHT/2 then
CarY=CarY-HEIGHT/4
end
end
end