So I have a game that takes a image and has these other images falling down with a spawn function and a timer. I want to know how to add collision. the main character is controlled by touch.
local object
local fingerTouch
local background
local physics = require("physics")
physics.start()
physics.setGravity(0, 4)
background = display.newImage("bg.png")
local HUD = display.newImage("hud.png")
local score = 0
local scoreText
scoreText = display.newText(score, 150, 10, Helvetica, 50)
local function scoreTimer()
score = score + 1
scoreText.text = score
if (score == 30) then
score = score + 10000
scoreText.text = score
end
end
scoretmr = timer.performWithDelay(1000,scoreTimer,0)
object = display.newImage( "rainbowdash.png" )
object.x = 160
object.y = 400
fingerTouch = function(e)
if e.phase == "moved" then
object.x = e.x
object.y = e.y
end
end
Runtime:addEventListener( "touch", fingerTouch )
local function spawnCrate()
local balloon = display.newImage("red.png");
balloon.x = math.random(320);
balloon.y = -100;
physics.addBody( balloon, { density=2.0, friction=0.5, bounce=0.3 } )
end
timer.performWithDelay(650,spawnCrate,800000000)
That is what I have written so far? Can anyone help? [import]uid: 39840 topic_id: 17370 reply_id: 317370[/import]
[import]uid: 52491 topic_id: 17370 reply_id: 65761[/import]