This is a custom game that I made and I am looking for suggestions to better the game and/or condense the code. Thanks.
function setup()
displayMode(FULLSCREEN)
c1 = physics.body(CIRCLE,65)
c1.x = WIDTH/2
c1.y = 100
c1.gravityScale = 0
state = 1
highscore = readLocalData("highscore")
if not highscore then
highscore = 0
end
r1 = physics.body(POLYGON,
vec2(-10,10),
vec2(-10,-10),
vec2(10,-10),
vec2(10,10))
r2 = physics.body(POLYGON,
vec2(-10,10),
vec2(-10,-10),
vec2(10,-10),
vec2(10,10))
r3 = physics.body(POLYGON,
vec2(-10,10),
vec2(-10,-10),
vec2(10,-10),
vec2(10,10))
r4 = physics.body(POLYGON,
vec2(-10,10),
vec2(-10,-10),
vec2(10,-10),
vec2(10,10))
r5 = physics.body(POLYGON,
vec2(-10,10),
vec2(-10,-10),
vec2(10,-10),
vec2(10,10))
r6 = physics.body(POLYGON,
vec2(-10,10),
vec2(-10,-10),
vec2(10,-10),
vec2(10,10))
r7 = physics.body(POLYGON,
vec2(-10,10),
vec2(-10,-10),
vec2(10,-10),
vec2(10,10))
r8 = physics.body(POLYGON,
vec2(-10,10),
vec2(-10,-10),
vec2(10,-10),
vec2(10,10))
r9 = physics.body(POLYGON,
vec2(-10,10),
vec2(-10,-10),
vec2(10,-10),
vec2(10,10))
r1.x = math.random(56.889,967.111)
r1.y = HEIGHT+200
r2.x = math.random(56.889,967.111)
r2.y = HEIGHT+200
r3.x = math.random(56.889,967.111)
r3.y = HEIGHT+200
r4.x = math.random(56.889,967.111)
r4.y = HEIGHT+200
r5.x = math.random(56.889,967.111)
r5.y = HEIGHT+200
r6.x = math.random(56.889,967.111)
r6.y = HEIGHT+200
r7.x = math.random(56.889,967.111)
r7.y = HEIGHT+200
r8.x = math.random(56.889,967.111)
r8.y = HEIGHT+200
r9.x = math.random(56.889,967.111)
r9.y = HEIGHT+200
score = 0
end
function draw()
background(40, 40, 50)
fill(38, 29, 233, 255)
if state == 1 then
font("Copperplate-Bold")
fontSize(50)
fill(255, 255, 255, 255)
text("Touch and Hold To Start",500,HEIGHT/2)
end
if state == 2 then
wave1()
reset()
score = score+.1
font("Copperplate-Bold")
fontSize(50)
fill(255, 255, 255, 255)
textMode(CORNER)
text(score)
fill(255, 20, 0, 255)
ellipse(c1.x,c1.y,65)
end
if state == 3 then
font("Copperplate-Bold")
fill(242, 242, 242, 255)
fontSize(50)
text("GAME OVER",350,HEIGHT/2)
score = score+0
font("Copperplate-Bold")
fontSize(50)
fill(255, 255, 255, 255)
text(score)
if score > highscore then
highscore = score
saveLocalData("highscore",score)
end
text("Highscore",365,350)
fontSize(100)
text(highscore,385,200)
end
endgame()
end
function touched(touch)
c1.x = touch.x
c1.y = touch.y
if touch.state == ENDED then
state = 3
end
if touch.state == BEGAN then
setup()
state = 2
end
end
function wave1()
rect(r1.x,r1.y,56.889,56.889)
rect(r2.x,r2.y,56.889,56.889)
rect(r3.x,r3.y,56.889,56.889)
rect(r4.x,r4.y,56.889,56.889)
rect(r5.x,r5.y,56.889,56.889)
rect(r6.x,r6.y,56.889,56.889)
rect(r7.x,r7.y,56.889,56.889)
rect(r8.x,r8.y,56.889,56.889)
rect(r9.x,r9.y,56.889,56.889)
end
function reset()
if r1.y < -56.889 then
r1.y = HEIGHT+100
r1.x = math.random(56.889,967.111)
end
if r2.y < -56.889 then
r2.y = HEIGHT+100
r2.x = math.random(56.889,967.111)
end
if r3.y < -56.889 then
r3.y = HEIGHT+100
r3.x = math.random(56.889,967.111)
end
if r4.y < -56.889 then
r4.y = HEIGHT+100
r4.x = math.random(56.889,967.111)
end
if r5.y < -56.889 then
r5.y = HEIGHT+100
r5.x = math.random(56.889,967.111)
end
if r6.y < -56.889 then
r6.y = HEIGHT+100
r6.x = math.random(56.889,967.111)
end
if r7.y < -56.889 then
r7.y = HEIGHT+100
r7.x = math.random(56.889,967.111)
end
if r8.y < -56.889 then
r8.y = HEIGHT+100
r8.x = math.random(56.889,967.111)
end
if r9.y < -56.889 then
r9.y = HEIGHT+100
r9.x = math.random(56.889,967.111)
end
end
function endgame()
if c1:testOverlap(r1) then
state = 3
end
if c1:testOverlap(r2) then
state = 3
end
if c1:testOverlap(r3) then
state = 3
end
if c1:testOverlap(r4) then
state = 3
end
if c1:testOverlap(r5) then
state = 3
end
if c1:testOverlap(r6) then
state = 3
end
if c1:testOverlap(r7) then
state = 3
end
if c1:testOverlap(r8) then
state = 3
end
if c1:testOverlap(r9) then
state = 3
end
end