我在学校这样做。我正在添加一个预先存在的程序。
我想要做的是每次燃料罐遇到我的火箭船时增加燃料标签中的燃料。我已经创建了一个checkFuel命令并将其添加到火箭飞船运动中,因此每次火箭船移动时以及燃料罐运动结束时都会检查。
这个问题似乎是因为我将燃料罐运动发送给我50毫秒,如果罐和火箭船仍然相交,它会增加燃料。所以代替50燃料,它增加了150燃料计数。
如果小行星遇到火箭飞船,我会使用相同的代码来减去生命,但它会减去所有生命并在1次碰撞后结束游戏。
` // Getting the fuel canister moving
command moveFuelCanister
if sMoving then
set top of image "Fuel Canister.png" to top of image "Fuel Canister.png"+15
if top of image "Fuel Canister.png" > 768 then
set the randomSeed to the long seconds
put random(1024) into randomWidth
set location of image "Fuel Canister.png" to randomWidth,0
end if
send moveFuelCanister to me in 50 milliseconds
end if
checkFuel
end moveFuelCanister
//Checking if the ship hits the fuel
command checkFuel
if intersect(image "rocketshipUp", image "Fuel Canister.png" ,"pixels") \
OR intersect(image "rocketshipDown", image "Fuel Canister.png" ,"pixels") \
OR intersect(image "rocketshipLeft", image "Fuel Canister.png" ,"pixels") \
OR intersect(image "rocketshipRight", image "Fuel Canister.png" ,"pixels")
then
add 50 to gFuelLevel
put "Fuel Level: " & gFuelLevel into field "Fuellevellbl"
end if
end checkFuel `
答案 0 :(得分:0)
有几种方法可以解决这个问题。你可以:
最后一个选项对游戏的工作方式进行的改动最少,但如果没有看到所有代码,则很难确切地说出你想要做什么。
这是最后一个选项:
command moveFuelCanister
if sMoving then
set top of image "Fuel Canister.png" to top of image "Fuel Canister.png"+15
if top of image "Fuel Canister.png" > 768 then
set the randomSeed to the long seconds
put random(1024) into randomWidth
set location of image "Fuel Canister.png" to randomWidth,0
set the uHit of image "Fuel Canister.png" to false
end if
send moveFuelCanister to me in 50 milliseconds
end if
checkFuel
end moveFuelCanister
//Checking if the ship hits the fuel
command checkFuel
if not the uHit of image "Fuel Canister.png" \
and (intersect(image "rocketshipUp", image "Fuel Canister.png" ,"pixels") \
OR intersect(image "rocketshipDown", image "Fuel Canister.png" ,"pixels") \
OR intersect(image "rocketshipLeft", image "Fuel Canister.png" ,"pixels") \
OR intersect(image "rocketshipRight", image "Fuel Canister.png" ,"pixels"))
then
set the uHit of image "Fuel Canister.png" to true
add 50 to gFuelLevel
put "Fuel Level: " & gFuelLevel into field "Fuellevellbl"
end if
end checkFuel
其他选项可能是改变图像以显示击中后空燃料罐落下。
答案 1 :(得分:0)
另一个想法是,使用脚本局部变量来确保每次点击只增加一个燃料......
//Checking if the ship hits the fuel
local sAddFuel --** Use a script local var for checking collisions **
command checkFuel
if intersect(image "rocketshipUp", image "Fuel Canister.png" ,"pixels") \
OR intersect(image "rocketshipDown", image "Fuel Canister.png" ,"pixels") \
OR intersect(image "rocketshipLeft", image "Fuel Canister.png" ,"pixels") \
OR intersect(image "rocketshipRight", image "Fuel Canister.png" ,"pixels") then
add 1 to sAddFuel --** counts up for each intersect command **
else
put 0 into sAddFuel --** Resets back to zero when no intersect **
end if
if sAddFuel = 1 then --** Will only add fuel for 1st collision **
add 50 to gFuelLevel
put "Fuel Level: " & gFuelLevel into field "Fuellevellbl"
end if
end checkFuel