Lua 我发明了一种激光,需要2次击中才能杀死2型小行星,1次击中才能杀死1型小行星。我做错了什么?
因此,我一直在对lua中名为“StarExplorer”的sdk游戏进行调整。我有一个想法,有两种小行星,一种需要激光两次撞击才能真正死亡。我在创建小行星时没有任何错误,它需要2次撞击才能死亡。虽然它仍然不需要2杆顶模 代码:Lua 我发明了一种激光,需要2次击中才能杀死2型小行星,1次击中才能杀死1型小行星。我做错了什么?,lua,Lua,因此,我一直在对lua中名为“StarExplorer”的sdk游戏进行调整。我有一个想法,有两种小行星,一种需要激光两次撞击才能真正死亡。我在创建小行星时没有任何错误,它需要2次撞击才能死亡。虽然它仍然不需要2杆顶模 代码: 为什么有两个同名的函数?第一个是否已过时?显示。删除(obj2),但小行星可能是一个obj1? local function onCollision( event ) if ( event.phase == "began" ) then loc
为什么有两个同名的函数?第一个是否已过时?
显示。删除(obj2)
,但小行星可能是一个obj1
?
local function onCollision( event )
if ( event.phase == "began" ) then
local obj1 = event.object1
local obj2 = event.object2
if ( ( obj1.myName == "laser" and obj2.myName == "asteroid" ) or
( obj1.myName == "asteroid" and obj2.myName == "laser" ) or
( obj1.myName == "lasers" and obj2.myName == "asteroid" ) )
then
-- Remove both the laser and asteroid
display.remove( obj2 )
-- Play explosion sound!
audio.play( explosionSound )
for i = #asteroidsTable, 1, -1 do
if ( asteroidsTable[i] == obj1 or asteroidsTable[i] == obj2 ) then
table.remove( asteroidsTable, i )
break
end
end
-- Increase score
score = score + 100
scoreText.text = "Score: " .. score
elseif ( ( obj1.myName == "ship" and obj2.myName == "asteroid" ) or
( obj1.myName == "asteroid" and obj2.myName == "ship" ) )
then
if ( died == false ) then
died = true
-- Play explosion sound!
audio.play( explosionSound )
-- Update lives
lives = lives - 1
livesText.text = "Lives: " .. lives
if ( lives == 0 ) then
display.remove( ship )
display.remove(emitter)
timer.performWithDelay( 2000, endGame )
else
ship.alpha = 0
emitter.alpha = 0
timer.performWithDelay( 2000, restoreShip )
end
end
end
end
end
local function onCollision( event )
if ( event.phase == "began" ) then
local obj1 = event.object1
local obj2 = event.object2
if ( ( obj1.myName == "laser" and obj2.myName == "asteroid" ) or
( obj1.myName == "asteroid" and obj2.myName == "laser" ) or
( obj1.myName == "lasers" and obj2.myName == "asteroid" ) )
then
-- Remove both the laser and asteroid
display.remove( obj2 )
-- Play explosion sound!
audio.play( explosionSound )
for i = #asteroidsTable, 1, -1 do
if ( asteroidsTable[i] == obj1 or asteroidsTable[i] == obj2 ) then
table.remove( asteroidsTable, i )
break
end
end
-- Increase score
score = score + 200
scoreText.text = "Score: " .. score
elseif ( ( obj1.myName == "ship2" and obj2.myName == "asteroid" ) or
( obj1.myName == "asteroid" and obj2.myName == "ship2" ) )
then
if ( died == false ) then
died = true
-- Play explosion sound!
audio.play( explosionSound )
-- Update lives
lives = lives - 4
livesText.text = "Lives: " .. lives
if ( lives == 0 ) then
display.remove( ship2 )
display.remove(emitter)
timer.performWithDelay( 2000, endGame )
else
ship2.alpha = 0
emitter.alpha = 0
timer.performWithDelay( 2000, restoreShip )
end
end
end
end
end