So here’s the entire code I’m using:
-- Slider
supportedOrientations(PORTRAIT)
displayMode(OVERLAY)
displayMode(FULLSCREEN)
function setup()
shipPosition = vec2(WIDTH/2,50)
shipsprite = readImage("Space Art:Red Ship")
shipspriteL = readImage("Space Art:Red Ship Bank Left")
shipspriteR = readImage("Space Art:Red Ship Bank Right")
bulletsprite = readImage("Tyrian Remastered:Bullet Fire C")
enemysprite = {}
enemysprite[1] = readImage("Tyrian Remastered:Space Ice 4")
enemysprite[2] = readImage("Tyrian Remastered:Space Ice 9")
enemysprite[3] = readImage("Tyrian Remastered:Plane Boss")
dx = 0
backingMode(RETAINED)
bullets = {}
lastBulletTime = 0
enemies = {}
lastEnemyTime = 0
score = 0
scoreStartTime = 0
end
function draw()
fill(0, 0, 0, 75)
rect(-1,-1,WIDTH+2,HEIGHT+2)
if ElapsedTime-lastEnemyTime > 2-math.min(1,(ElapsedTime-scoreStartTime)/100) then
makeEnemy()
end
for i,v in pairs(enemies) do
if v.body.collided == true then
v.body:destroy()
table.remove(enemies,i)
else
if v.body.position.y < -v.body.radius then
score = 0
scoreStartTime = ElapsedTime
elseif v.body.position.x < -v.body.radius or
v.body.position.x > WIDTH + v.body.radius then
v.body:destroy()
table.remove(enemies,i)
end
end
end
for i,v in ipairs(enemies) do
sprite(v.img,v.body.position.x,v.body.position.y)
end
if touch and ElapsedTime-lastBulletTime > 1 then
makeBullet()
end
for i,v in pairs(bullets) do
if v.collided == true then
v:destroy()
table.remove(bullets,i)
end
end
for i,v in ipairs(bullets) do
sprite("Tyrian Remastered:Energy Orb 2",v.position.x,v.position.y)
end
dx = Gravity.x * 15
if math.abs(dx) < 1 then
dx = 0
end
shipPosition.x = shipPosition.x + dx
shipPosition.x = math.max(0,math.min(shipPosition.x,WIDTH))
if dx == 0 then
sprite(shipsprite,shipPosition.x,shipPosition.y)
elseif dx > 0 then
sprite(shipspriteR,shipPosition.x,shipPosition.y)
else
sprite(shipspriteL,shipPosition.x,shipPosition.y)
end
fill(255,255,255,255)
textMode(CENTER)
textAlign(CENTER)
fontSize(20)
font("Zapfino")
text("Score: "..score,WIDTH/1.3,HEIGHT-20)
end
function makeBullet()
local bullet = physics.body(CIRCLE,5)
bullet.position = vec2(shipPosition.x,90)
bullet.bullet = true
bullet.gravityScale = 0
bullet.linearVelocity = vec2(dx,750)
bullet.type1 = "bullet"
bullets[#bullets+1] = bullet
lastBulletTime = ElapsedTime
sound(SOUND_SHOOT, 28355)
end
function touched(t)
if t.state == BEGAN and not touch then
touch = t
if ElapsedTime-lastBulletTime > .25 then
makeBullet()
end
elseif t.state == ENDED then
touch = nil
end
end
And lastly...
function makeEnemy()
local enemy = {}
enemy.type = math.random(#enemysprite)
enemy.img = enemysprite[enemy.type]
local size = math.max(enemy.img.width,enemy.img.height)
enemy.body = physics.body(CIRCLE,size/2)
enemy.body.position = vec2(math.random(0+size/2,WIDTH-size/2),HEIGHT+size/2)
enemy.body.bullet = true
enemy.body.gravityScale = 0
enemy.body.linearVelocity = vec2(0,-math.random(30,125))
enemy.body.type1 = "enemy"
enemies[#enemies+1] = enemy
lastEnemyTime=ElapsedTime
end
function collide(contactinfo)
if (contactinfo.bodyA.type1 == "enemy" or
contactinfo.bodyB.type1 == "enemy") and
(contactinfo.bodyA.type1 == "bullet" or
contactinfo.bodyB.type1 == "bullet") then
sound(SOUND_EXPLODE, 10733)
– sprite(“Tyrian Remastered:Explosion Huge”)
contactinfo.bodyA.collided = true
contactinfo.bodyB.collided = true
score = score + 1
end
end
I was wondering about how I could have a button at the top right hand corner (while the game is running) that said "Pause" and when you pressed it, the game paused, and a menu popes up in the middle of the screen is that had a button that said "resume"
When touched, the menu went away, and the game continued where it was.
Help me???