Guys, help me again please 
so basically i am testing a game where a ship (main player) will just die when it gets hit (collide) with a bomb. The player can get a shield powerup where it will create shield around the ship and it will prevent him from death when collide with the bomb. However, if the ship/shield collide with the bomb, the shield should get destroyed/gone so the next bomb would destroy the ship again (original collision).
I am stuck because every time the shield has been activated, it simply won’t run the codes to collide with the bomb.
Here are the codes basically:
[code]-- SPRITE
– #Set sprite
ship = sprite.newSpriteSheet(“shipsprite.png”, 95, 134)
shipset = sprite.newSpriteSet (ship, 1, 6)
sprite.add (shipset, “playerleft”, 4, 3, 150, 0)
sprite.add (shipset, “playerright”, 1, 3, 200, 0)
player = sprite.newSprite(shipset)
player.x = 160
player.y = 450
player.name = “player”
player:prepare(“playerleft”)
physics.addBody(player, {density = 0, friction = 0, bounce = 0})
player.bodyType = “static”
shield = display.newImage(“shield.png”)
shield.x = player.x
shield.y = player.y
shield.alpha = 0
local playerGroup = display.newGroup()
playerGroup:insert(player)
playerGroup:insert(shield)
– #Sprite movement
function stop (event)
if event.phase ==“ended” then
motionx = 0
motiony = 0
player:pause()
end
end
Runtime:addEventListener(“touch”, stop )
function moveplayer (event)
if gameIsActive == true then
player.x = player.x + motionx
player.y = player.y + motiony
shield.x = player.x
shield.y = player.y
end
end
timer1 = timer.performWithDelay(1,moveplayer,0)
function touchleft (event)
if gameIsActive == true then
motionx = -speed
motiony = 0
player:prepare(“playerleft”)
player:play(“playerleft”)
end
end
left:addEventListener(“touch”, touchleft)
function touchright (event)
if gameIsActive == true then
motionx = speed
motiony = 0
player:prepare(“playerright”)
player:play(“playerright”)
end
end
right:addEventListener(“touch”, touchright)
function wrapit (event)
if player.x < 40 then
player.x = 40
elseif player.x > 300 then
player.x = 300
end
end
Runtime:addEventListener(“enterFrame”, wrapit)
– #Sprite collision
function catchStar(e)
if (e.other.name == “star”) then
starCaught = starCaught + 1
score = score + 1
scoreNum.text = score
scoreNum:setReferencePoint(display.CenterLeftReferencePoint)
scoreNum.x = 54
audio.play(getStar)
e.other:removeSelf()
e.other = nil
elseif (e.other.name == “shieldpowerup”) then
shield.alpha = 0.5
e.other:removeSelf()
e.other = nil
elseif (e.other.name == “bomb” and shield.alpha == 0) then
showRestartButton()
local gameOverText = display.newText(“GAME OVER”, 85, 250, Arial, 30)
physics.pause()
paused = true
gameIsActive = false
e.other:removeSelf()
e.other = nil
elseif (e.other.name == “bomb” and shield.alpha == 0.5) then
shield.alpha = 0
end
end
player:addEventListener(‘collision’, catchStar)
[/code]
and regarding the shieldPowerup itself, here’s the code:
function shieldPowerup ( objectType, x, y )
shieldpowerup = display.newImage("tameng.png")
shieldpowerup.name = "shieldpowerup"
shieldpowerup.x = math.random(320)
shieldpowerup.y = -100
shieldpowerup.rotation = 10
physics.addBody(shieldpowerup, { density=2.0, friction=0.5, bounce=0.3})
end
so basically i can have the bomb to collide with the player and the game will be over and i can have the shield powerup to collide with the player to activate the shield by changing the transparency. The shield then move following the player but that’s about it. If the shield has been “activated”, the bomb won’t run any codes when it hits the player, why is this?? I have changed the shield size so the ship head is ahead of the shield animation itself but still… [import]uid: 114765 topic_id: 21440 reply_id: 321440[/import]