Small coding issue

I am following this tutorial

https://www.youtube.com/watch?v=duYjS1AVAOE

The code that  I want to ask about is this

 mine1 = display.newImage("mine.png") mine1.x = 500 mine1.y = 100 mine1.speed = math.random(2,6) mine1.initY = mine1.y mine1.amp = math.random(20,100) mine1.angle = math.random(1,360) physics.addBody(mine1, "static", {density=.1, bounce=0.1, friction=.2, radius=12}) screenGroup:insert(mine1) mine2 = display.newImage("mine.png") mine2.x = 500 mine2.y = 100 mine2.speed = math.random(2,6) mine2.initY = mine2.y mine2.amp = math.random(20,100) mine2.angle = math.random(1,360) physics.addBody(mine2, "static", {density=.1, bounce=0.1, friction=.2, radius=12}) screenGroup:insert(mine2) mine3 = display.newImage("mine.png") mine3.x = 500 mine3.y = 100 mine3.speed = math.random(2,6) mine3.initY = mine3.y mine3.amp = math.random(20,100) mine3.angle = math.random(1,360) physics.addBody(mine3, "static", {density=.1, bounce=0.1, friction=.2, radius=12}) screenGroup:insert(mine3) 

Now  when the plan goes up, it blows, i don’t want it to blow no matter how high it goes, i just want to to blow if it hits a mine, how to do so

I think we need to see your jet code as well as any code defining the top of the screen.

here’s the entire file sir

http://pastebin.com/kfMMA2nQ

and another small issue, the plan is not responding to the movement, it goes down after 2 seconds

One thing I can see is this:

You create the jet and sets jet.collided to false

 jet.collided = false

Then in the onCollision event it will always call explode() because jet.collides will always be false but it doesn’t have any rules saying it must be a mine, just any collision will do. I guess jet.collided is here so two items can’t collide with the jet and create two explosions but now it will explode with whatever it hits.

function onCollision(event) if event.phase == "began" then if jet.collided == false then jet.collided = true jet.bodyType = "static" explode() --storyboard.gotoScene("restart", "fade", 400) end end end

What you can do is give the mines and the jet a name and then code like this:

if event.target.name == "mine" and event.other.name == "jet" then explode() end 

http://docs.coronalabs.com/api/event/collision/index.html

Best regards,

Tomas

I think we need to see your jet code as well as any code defining the top of the screen.

here’s the entire file sir

http://pastebin.com/kfMMA2nQ

and another small issue, the plan is not responding to the movement, it goes down after 2 seconds

One thing I can see is this:

You create the jet and sets jet.collided to false

 jet.collided = false

Then in the onCollision event it will always call explode() because jet.collides will always be false but it doesn’t have any rules saying it must be a mine, just any collision will do. I guess jet.collided is here so two items can’t collide with the jet and create two explosions but now it will explode with whatever it hits.

function onCollision(event) if event.phase == "began" then if jet.collided == false then jet.collided = true jet.bodyType = "static" explode() --storyboard.gotoScene("restart", "fade", 400) end end end

What you can do is give the mines and the jet a name and then code like this:

if event.target.name == "mine" and event.other.name == "jet" then explode() end 

http://docs.coronalabs.com/api/event/collision/index.html

Best regards,

Tomas