Hi guys, I’ve been trying to fix this for the whole day now it works great but when it ends the game the whole screen flashes randomly. But if you open the parameters frame to the left it fixes the problem but the text it’s supposed to show is gone.
ship_pos = vec2(WIDTH * .5,40)
enemies = {}
bullets = {}
framebullet = 0
frameenemy = 0
current_rate = 30
score = 0
lives = 3
txt = nil
txtframe = 0
roundtime = 0
reduce = false
vel = 3
stop = false
canmove = false
canclr = true
function touched(t)
if t.state == BEGAN then
canmove = true
elseif t.state == ENDED then
canmove = false
end
end
function draw()
if canmove then
if CurrentTouch.x < WIDTH * .5 and not stop then
ship_pos.x = ship_pos.x - 5
elseif not stop then
ship_pos.x = ship_pos.x + 5
end
end
roundtime = roundtime + 1
framebullet = framebullet + 1
frameenemy = frameenemy + 1
if canclr then
smooth()
background(0,0,0)
end
sprite("Project:Apple ship",ship_pos.x,ship_pos.y,30,30)
if framebullet > 50 and not stop then
framebullet = 0
local projectile = vec2(ship_pos.x,ship_pos.y + 5)
table.insert(bullets,projectile)
end
if frameenemy > current_rate and not stop then
frameenemy = 0
local newenemy = vec2(math.random(math.floor(WIDTH * .9)),HEIGHT * .9)
table.insert(enemies,newenemy)
end
for i,v in pairs(bullets) do
if v.y + 4 > HEIGHT and not stop then
table.remove(bullets,i)
end
if not stop then
v.y = v.y + 4
fill(255, 255, 255, 255)
ellipse(v.x,v.y,18,18)
end
end
for i,v in pairs(enemies) do
if v.y < HEIGHT * .004 and not stop then
table.remove(enemies,i)
end
if not stop then
v.y = v.y - vel
sprite("Project:spaceship",v.x,v.y,30,30)
end
if ship_pos:dist(v) < 18 and not stop then
table.remove(enemies,i)
txt = "You lost a life! You have "..lives-tonumber("1").." more."
end
for ii,v2 in pairs(bullets) do
if v2:dist(v) < 15 and not stop then
score = score + 50
table.remove(enemies,i)
table.remove(bullets,ii)
end
end
end
font("Optima-ExtraBlack")
fontSize(30)
fill(255, 255, 255, 255)
text("Score: "..score,WIDTH * .8,HEIGHT * .95)
text("Lives: "..lives,WIDTH * .8,HEIGHT * .9)
if txt and txtframe <= 70 and not stop then
if reduce == false then
reduce = true
lives = lives - 1
end
txtframe = txtframe + 1
fill(255, 0, 0, 255)
text(txt,WIDTH * .5,HEIGHT * .5)
end
if txtframe >= 70 and not stop then
txtframe = 0
reduce = false
txt = nil
end
if lives <= 0 and not stop then
stop = true
canclr = false
end
if roundtime > 89 and not stop then
roundtime = 0
if current_rate > 3 then
vel = vel + .12
current_rate = current_rate - 1
end
end
end