could so someone tell me why the home button goes to scene 1 very quickly and then automatically goes to scene 2 without you touching the screen? Also if anyone has any other tips that would be great! Thanks!
function setup()
scene=1
end
-- This function gets called once every frame
function draw()
displayMode(FULLSCREEN)
if scene==1 then
--start menu
background(115, 226, 219, 255)
fill(255, 0, 0, 0)
strokeWidth(10)
stroke(0, 108, 255, 255)
rect(260, 300, 500, 100)
fill(184, 0, 255, 255)
fontSize(50)
font("Courier-Bold")
text("Highway Suicide", 505, 500)
fill(0, 20, 255, 255)
fontSize(36)
font("Courier-Bold")
text("Tap Anywhere to Start", 505, 350)
if CurrentTouch.state==BEGAN then
scene=2
setup2()
end
--game
strokeWidth(0)
elseif scene==2 then
background(43, 177, 21, 255)
-- This sets a dark background color
sprite("Documents:BrushyRoad", WIDTH/2, y)
sprite("Documents:BrushyRoad", WIDTH/2, y2)
-- Do your drawing here
--Road
fill(0, 0, 0, 255)
rect(190, -1, 100, HEIGHT+2)
rect(295, -1, 100, HEIGHT+2)
rect(400, -1, 100, HEIGHT+2)
rect(505, -1, 100, HEIGHT+2)
rect(610, -1, 100, HEIGHT+2)
rect(715, -1, 100, HEIGHT+2)
--Road Lines
fill(252, 255, 0, 255)
rect(290, -1, 5, HEIGHT+2)
rect(395, -1, 5, HEIGHT+2)
rect(500, -1, 5, HEIGHT+2)
rect(605, -1, 5, HEIGHT+2)
rect(710, -1, 5, HEIGHT+2)
--Barriers
fill(131, 128, 128, 255)
rect(180+1, -1, 10, HEIGHT+2)
rect(815-1, -1, 10, HEIGHT+2)
--Car Movement/Cars
sprite("Documents:Ferrari", car, 100, 50, 75)
sprite("Documents:Lambo Dcar", dcar1x, dcar1y, 50, 75)
sprite("Documents:F1 Dcar", dcar2x, dcar2y, 50, 75)
sprite("Documents:Lambo Dcar", dcar3x, dcar3y, 50, 75)
sprite("Documents:F1 Dcar", dcar4x, dcar4y, 50, 75)
sprite("Documents:Lambo Dcar", dcar5x, dcar5y, 50, 75)
sprite("Documents:F1 Dcar", dcar6x, dcar6y, 50, 75)
fill(0, 253, 255, 255)
rect(830, 15, 100, 130)
rect(830, 150, 100, 130)
sprite("Tyrian Remastered:Arrow Right", 877, 80, 90, 120)
sprite("Tyrian Remastered:Arrow Left", 877, 215, 90, 120)
dcar1y=dcar1y-car1speed
dcar2y=dcar2y-car2speed
dcar3y=dcar3y-car3speed
dcar4y=dcar4y-car4speed
dcar5y=dcar5y-car5speed
dcar6y=dcar6y-car6speed
if dcar1y<1 then
dcar1y=HEIGHT
car1speed=math.random(4,10)
end
if dcar2y<1 then
dcar2y=HEIGHT
car1speed=math.random(4,10)
end
if dcar3y<1 then
dcar3y=HEIGHT
car1speed=math.random(4,10)
end
if dcar4y<1 then
dcar4y=HEIGHT
car4speed=math.random(4,10)
end
if dcar5y<1 then
dcar5y=HEIGHT
car5speed=math.random(4,10)
end
if dcar6y<1 then
dcar6y=HEIGHT
car6speed=math.random(4,10)
end
if y<(0-(HEIGHT/2)) then
y=HEIGHT+(HEIGHT/2)
end
if y2<(0-(HEIGHT/2)) then
y2=HEIGHT+(HEIGHT/2)
end
y=y-4
y2=y2-4
--Button Collision Detection
if var==ENDED and CurrentTouch.state==BEGAN and CurrentTouch.x>829 and CurrentTouch.x<931 and CurrentTouch.y>14 and CurrentTouch.y<146 then
var=BEGAN
car=car + 105
end
if var==ENDED and CurrentTouch.state==BEGAN and CurrentTouch.x>829 and CurrentTouch.x<931 and CurrentTouch.y>149 and CurrentTouch.y<281 then
var=BEGAN
car=car - 105
end
if car<180 then
car=180
sprite("Small World:Explosion", 180, 170, 250, 250)
end
if car>815 then
car=815
sprite("Small World:Explosion", 815, 170, 250, 250)
scene=3
end
if CurrentTouch.state==ENDED then
var=ENDED
end
--collision detection
if car+25>dcar1x-25 and car-25<dcar1x+25 and 100>dcar1y-30 and 100<dcar1y+30 then
sprite("Small World:Explosion", car, cary, 250, 250)
scene=3
end
if car+25>dcar2x-25 and car-25<dcar2x+25 and 100>dcar2y-30 and 100<dcar2y+30 then
sprite("Small World:Explosion", car, cary, 250, 250)
scene=3
end
if car+25>dcar3x-25 and car-25<dcar3x+25 and 100>dcar3y-30 and 100<dcar3y+30 then
sprite("Small World:Explosion", car, cary, 250, 250)
scene=3
end
if car+25>dcar4x-25 and car-25<dcar4x+25 and 100>dcar4y-30 and 100<dcar4y+30 then
sprite("Small World:Explosion", car, cary, 250, 250)
scene=3
end
if car+25>dcar5x-25 and car-25<dcar5x+25 and 100>dcar5y-30 and 100<dcar5y+30 then
sprite("Small World:Explosion", car, cary, 250, 250)
scene=3
end
if car+25>dcar6x-25 and car-25<dcar6x+25 and 100>dcar6y-30 and 100<dcar6y+30 then
sprite("Small World:Explosion", car, cary, 250, 250)
scene=3
end
elseif scene==3 then
--End Screen
fill(255, 0, 0, 255)
sprite("Cargo Bot:Background Fade", WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
fontSize(80)
font("Didot-Bold")
text("Game Over", WIDTH/2, HEIGHT/2)
--Gameover
sprite("Documents:reset", 50, 715, 100, 100)
sprite("Documents:home", 530, 50, 100, 100)
if CurrentTouch.state==BEGAN and CurrentTouch.x>0 and CurrentTouch.x<100 and CurrentTouch.y>680 and CurrentTouch.y<750
then scene=2
setup2()
end
if CurrentTouch.state==BEGAN and CurrentTouch.x>445 and CurrentTouch.x<555 and CurrentTouch.y>0 and CurrentTouch.y<110
then setup()
scene=1
end
end
end
function setup2()
y=HEIGHT/2
y2=HEIGHT+2+(HEIGHT/2)
car=555
cary=200
dcar1x=240
dcar2x=345
dcar3x=450
dcar4x=555
dcar5x=660
dcar6x=765
dcar1y=HEIGHT+math.random(0,250)
car1speed=math.random(4,8)
dcar2y=HEIGHT+math.random(0,250)
car2speed=math.random(4,8)
dcar3y=HEIGHT+math.random(0,250)
car3speed=math.random(4,8)
dcar4y=HEIGHT+math.random(0,250)
car4speed=math.random(4,8)
dcar5y=HEIGHT+math.random(0,250)
car5speed=math.random(4,8)
dcar6y=HEIGHT+math.random(0,250)
car6speed=math.random(4,8)
end