I am very new to coding and am recreating a simple game as seen on the corona youtube channel. Once i relaunch the simulator the main object “pacmanghost1” flies off the screen. I have tried to set gravity at 0. i am not getting any errors but most have something wrong or in the wrong order. Any help is appreciated. code is below:
thanks
blake
–
– main.lua
–
– Your code here
local physics = require “physics”
physics.start()
physics.setGravity(0,0)
local pacmanghost1 = display.newImage( “pacmanghost1.png” )
pacmanghost1 : setFillColor(10, 0, 0)
pacmanghost1.x = 160
pacmanghost1.y = 200
pacmanghost1 : scale(.10, .10)
physics.addBody(pacmanghost1, “dynamic”)
local pacmanghost2 = display.newImage(“pacmanghost2.png”)
pacmanghost2.x = 200
pacmanghost2.y = 300
pacmanghost2 : scale(.10, .10)
physics.addBody(pacmanghost2, “dynamic”)
local pacmanghost3 = display.newImage(“pacmanghost3.png”)
pacmanghost3.x = 250
pacmanghost3.y = 400
pacmanghost3 : setFillColor(0, 10, 0)
pacmanghost3 : scale(.10, .10)
physics.addBody(pacmanghost3, “dynamic”)
function touchScreen ( event )
if event.phase == “began” then
transition.to(pacmanghost1, {time=1000, x=event.x, y=event.y})
end
end
Runtime : addEventListener (“touch”, touchScreen)
–transition.to(pacmanghost1, {x=250, y=250, time=10000})
–local text = display.newText( “Blake’s”, 160, 200, “Arial”, 60 )
–local text = display.newText( “Arcade”, 160, 300, “Arial”, 80 )
function movepacmanghost2()
transition.to(pacmanghost2, {time=1000, x=math.random(20, 290), y=math.random(10, 500), onComplete=movepacmanghost2})
transition.to(pacmanghost3, {time=1000, x=math.random(20, 290), y=math.random(10, 500), onComplete=movepacmanghost3})
end
movepacmanghost2()
function onCollision ( event )
print(“collide!”)
end
Runtime : addEventListener (“collision”, onCollision)