Hi all. I’m new to Corona and I have a minor problem. I want to make a game where the player can move only right and left, while some balls are spawning and going down. If the ball hit the player, the ball will dissapear . But I want the ball to go through the “road” and after he went off the screen to dissapear from the game.
The player should avoid the balls from the top.
So, I want collision with player and road, but I don’t want collision with ball and road.
Down is my code. Sorry for my bad english.
Thank you!
[code]local physics = require(“physics”)
physics.start()
display.setStatusBar( display.HiddenStatusBar )
local background = display.newImage(“background.jpeg”)
background.y = 210
local road = display.newImage(“road.jpg”,0,430)
local player = display.newImage(“player.png”)
player.x = display.contentWidth/2
player.y = 350
local dreapta = display.newImage(“dreapta.png”)
dreapta.x = player.x +100
dreapta.y = 455
local stanga = display.newImage(“stanga.png”)
stanga.x = player.x - 100
stanga.y = 455
physics.addBody(road, {friction = 0.5})
road.bodyType = “static”
physics.addBody(player,{density=2.0,friction=0.5,bounce=0.3})
local function moveright (event)
player.x = player.x+5
end
dreapta:addEventListener(“touch”, moveright)
local function moveleft (event)
player.x = player.x-5
end
stanga:addEventListener(“touch”, moveleft)
function newBall()
rand = math.random(100)
if(rand<60) then
j = display.newImage(“ball.png”)
j.x = 60+math.random(160)
j.y = -100
physics.addBody(j, {density= 0.9,friction = 0.3, bounce = 0.3})
elseif (rand < 80) then
j = display.newImage(“ball.png”);
j.x = 60 + math.random( 160 )
j.y = -100
physics.addBody( j, { density=1.4, friction=0.3, bounce=0.2} )
else
j = display.newImage(“ball.png”);
j.x = 60 + math.random( 160 )
j.y = -100
physics.addBody( j, { density=0.3, friction=0.2, bounce=0.5} )
end
end
local dropBalls = timer.performWithDelay(500,newBall,100)[/code] [import]uid: 178587 topic_id: 31387 reply_id: 331387[/import]