This is the current attempt at an 8-bit shooter that I am working on and I’m currently having difficulties with the bullets. I’m hoping to get help on this so the bullet/bullets shoot in certain intervals and are based on touch. I also hope to get the bullets to continue drawing until it goes off the screen even when touching the other button.
-- Final App
-- Use this function to perform your initial setup
function setup()
timeout=ElapsedTime+2
arrowR=readImage("Documents:Arrow")
arrowL=readImage("Documents:ArrowL")
swordX1=WIDTH/2
swordY1=HEIGHT/2
swordX2=WIDTH/2
swordY2=HEIGHT/2
characterX=WIDTH/2-30
characterY=250
characterW=60
characterH=100
weaponX1=characterX
weaponY1=characterY+50
weaponX2=characterX-50
weaponY2=characterY+50
bulletX1=WIDTH/2-70
bulletY1=300
bulletX2=WIDTH/2-90
bulletY2=300
bullet2X1=WIDTH/2-70
bullet2X2=WIDTH/2-90
bulletXR1=WIDTH/2+70
bulletXR2=WIDTH/2+90
bullet2XR1=WIDTH/2+70
bullet2XR2=WIDTH/2+90
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(255, 255, 255, 255)
touching()
-- Do your drawing here
stroke(0)
--floor
strokeWidth(15)
line(0,250,WIDTH,250)
strokeWidth(7)
rect(-5,-5,WIDTH+10,250)
--movement arrows
rect(94,29,161,110)
rect(494,29,161,110)
sprite(arrowR,WIDTH/2+200,HEIGHT/2-300,150,100)
sprite(arrowL,WIDTH/2-200,HEIGHT/2-300,150,100)
--body
strokeWidth(2)
rect(characterX,characterY,characterW,characterH)
--weapon
line(weaponX1,weaponY1,weaponX2,weaponY2)
end
function touching()
if CurrentTouch.state == BEGAN or CurrentTouch.state == MOVING or CurrentTouch.state == ENDED then
if CurrentTouch.x>=94 and CurrentTouch.x<=255 and CurrentTouch.y>=29 and CurrentTouch.y<=139 then weaponX1=WIDTH/2-30 weaponX2=WIDTH/2-80 bullet1LFire()
else if CurrentTouch.x>=494 and CurrentTouch.x<=655 and CurrentTouch.y>=29 and CurrentTouch.y<=139 then weaponX1=WIDTH/2+30 weaponX2=WIDTH/2+80 bullet1RFire()
end
end
end
end
function bullet1LFire()
bulletX1=bulletX1-2
bulletX2=bulletX2-2
line(bulletX1,bulletY1,bulletX2,bulletY2)
if (ElapsedTime>timeout) then
if CurrentTouch.state == BEGAN or CurrentTouch.state == MOVING then bullet2X1=bullet2X1-2 bullet2X2=bullet2X2-2 line(bullet2X1,bulletY1,bullet2X2,bulletY2)
end
end
end
function bullet1RFire()
bulletXR1=bulletXR1+2
bulletXR2=bulletXR2+2
line(bulletXR1,bulletY1,bulletXR2,bulletY2)
if (ElapsedTime>timeout) then
if CurrentTouch.state == BEGAN or CurrentTouch.state == MOVING then bullet2XR1=bullet2XR1+2 bullet2XR2=bullet2XR2+2 line(bullet2XR1,bulletY1,bullet2XR2,bulletY2)
end
end
end