So… I started learning Corona last week, and now I’ve hit a problem.
I’m making a small game where you’re supposed to fly a ship through an asteroid field. Currently all I have a re place holders though.
Now here’s the issue I’m having. The ship and the asteroids don’t seem to register collisions with each other.
Here’s the code I’m using, and I know, it’s very amateurish, but please disregard that.
Anyone that could help?
[code]
_W = display.contentWidth
_H = display.contentHeight
–local level1 = (require “level1”)
local physics = (require “physics”)
–local backgroundMusic = audio.loadStream(“background.mp3”)
–local backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=-1, fadein=5000 } )
local background = display.newGroup ()
local rocks = display.newGroup()
Dead = false
shipExist = false
physics.start()
physics.setGravity( 0, 0 )
local rock
local ship
physics.setDrawMode (“hybrid”)
–[[
local map1
level1 = function (event)
map1 = display.newImage(“map1.png”)
map2 = display.newImage(“map2.png”, 3600, 0)
–map1.yScale = 0.5
physics.addBody (map1, “static”, {isSensor=true})
physics.addBody (map2, “static”, {isSensor=true})
end
level1 ()
]]–
for i = 1, 10000 do – use 1 - 10000 objects
x = math.random (0, _W*100) – random place on width, between 0 and max
y = math.random (0, _H) – random place on height between 0 and max
z = math.random (1, 3) – random size between 1 and 3 pixels
star = display.newCircle(background, x, y, z ) – Object itself
t = math.random (100, 255) – random RGB content
r = math.random (100, 255) – random RGB content
e = math.random (100, 255) – random RGB content
star: setFillColor ( t, r, e ) – the color of each random object in a random color
end
for i = 1, 500 do – use 1 - 10000 objects
x = math.random (_W*1.1, _W*10) – random place on width, between 0 and max
y = math.random (0, _H) – random place on height between 0 and max
z = math.random (10, 15) – random size between 1 and 3 pixels
rock = display.newCircle( rocks, x, y, z ) – Object itself
physics.addBody (rock, “static”)
transition.to(rock, {time = 100000, alpha=1, x=(-20000)})
–map1.x = map1.x-3
–map2.x = map2.x-3
end
for i = 1, 300 do – use 1 - 10000 objects
x = math.random (_W*10, _W*20) – random place on width, between 0 and max
y = math.random (0, _H) – random place on height between 0 and max
z = math.random (10, 15) – random size between 1 and 3 pixels
rock = display.newCircle( rocks, x, y, z ) – Object itself
physics.addBody (rock, “static”)
transition.to(rock, {time = 100000, alpha=1, x=(-20000)})
–map1.x = map1.x-3
–map2.x = map2.x-3
end
background:insert(star)
background:insert(rock)
Runtime:addEventListener (“enterFrame”,
function()
–transition.to(rocks, {time = 10000, alpha=0, x=(-10000)})
background.x = background.x-5
–map1.x = map1.x-3
–map2.x = map2.x-3
end
)
createShip = function (event)
ship = display.newCircle (rocks, 0, 0, 7)
ship.x = _H*.5
ship.y = _W*.5
shipExist = true
physics.addBody (ship, “static”)
end
createShip(event)
–rocks1:insert(rock1)
–rocks2:insert(rock2)
ship:addEventListener(“collision”,
function(event)
print(“Ouch”)
end
)
Runtime:addEventListener(“touch”,
function(event)
if Dead == true then
return
else
if shipExist == true then
ship.x = event.x
ship.y = event.y
end
end
end
)
[blockcode] [import]uid: 197831 topic_id: 33452 reply_id: 333452[/import]
[import]uid: 197831 topic_id: 33452 reply_id: 132960[/import]