So, here is what’s going on i can launch the game on simulator but it looks like nothing is working as i expected . when objects collide it should display text ir remove 2 objects and start again . please help
–hide setStatusBar
display.setStatusBar(display.HiddenStatusBar)
–call for physics
local scoreTxt = 0
local physics = require “physics”
physics.start()
**physics.setGravity(0,0)
–setting background image center
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local background = display.newImage(“background.jpg”)
background.y = centerY
background.x = centerX
–playeroneface
local cake
local function createCake()
cake = display.newImage(“Cake.png”)
cake.x = 1200
cake.y = 240
physics.addBody(cake, “dynamic”)
end
createCake()
– creating happy
local happy
local function createHappy()
--playeroneface
happy = display.newImage(“happygirl.png”)
happy.x = 100
happy.y = 100
physics.addBody(happy, “dynamic”)
end
createHappy()
local angry = display.newImage(“angrymen1.png”)
angry.x = 1000
angry.y = 420
physics.addBody(angry, “static”)
local angry2 = display.newImage(“angrymen2.png”)
angry2.x = 830
angry2.y = 520
physics.addBody(angry2, “static”)
function touchScreen(event)
if event.phase == “began” then
--print(event.x)
transition.to(happy, {time=1000, x=event.x, y=event.y})
end
end
Runtime:addEventListener(“touch”, touchScreen)
function moveAngry()
transition.to(angry,{time=1000, x=math.random(150,1200),y=math.random(60,580), onComplete=moveAngry})
transition.to(angry2,{time=1000, x=math.random(180,1200),y=math.random(90,580)})
end
moveAngry()
function onCollision (event)
– testing code
local function onCollision(self, event)
if event.phase == “began” then
if (event.happy == “cake”) then
local text = display.newText(“you just hit the cake”, display.contentCenterX, display.contentCenterY, native.systemFontBold, 50)
else
happy:removeSelf()
cake:removeSelf()
local text = display.newText(“Game Over. Try Again”, display.contentCenterX, display.contentCenterY, native.systemFontBold, 50)
timer.performWithDelay(3000, function() text:removeSelf(); text = nil; cake = nill end)
timer.performWithDelay(4000, function()
--reset things after the collision
createHappy();
createCake();
angry.x = 880
angry.y = 600
angry2.x = 830
angry2.y = 520
end)
end
end
end
end
Runtime:addEventListener(“collision”, onCollision)
–Runtime:addEventListener(“collision”, cakeCollision)**