저는 ZeroBrane과 Tiled에서 2D 게임을하고 있는데 플레이어 점수 == 0 일 때 전체 레벨이 다시 시작되는 기능을 만들려고합니다. 그래서 모든 것이 원래 위치로 되돌아갑니다. 나는 아직도 n00b이므로 noob 언어로 설명해주십시오! 이것은 내가 지금 가지고있는 것입니다. 그렇게 오래 걸리지는 않았으므로 전체 스크립트를 게시하는 것으로 나타났습니다.LUA - 레벨을 다시 시작 하시겠습니까?
Level.Load ("Game.tmx")
--playeralive = true
-- this array saves all the data for the enemies
enemies ={
}
--Player info
player = {
object = nil,
score = 0,
health = 5,
speed = 3,
}
sounds = {
bump = Sound.Load("bump.wav", false, false),
bumpy = Sound.Load ("bumpy.wav", false, false),
}
function Start()
player.object = Level.GetObject ("Player")
enemies = Level.GetObject ("enemy")
Hud.Message (" Start ", 2)
DoSign()
DoDoor()
end
function Update()
move()
Respawn()
--HUD
Hud.Score ("Score : " ..player.score)
Hud.Health ("Health : " ..player.health)
--Controllers
--if playeralive == true then
Controller.Wasd(player.object, player.speed)
Camera.Follow(player.object)
--end
end
function Respawn()
if player.health == 0 then
player.health = 5
Level.RemoveObject(player.object)
--playeralive = false
Level.Spawn("Player", 47, 118, 197, nil)
player.object = Level.GetObject ("Player")
--playeralive = true
Camera.Follow(player.object)
end
end
function spawn()
player.Health = 5
Level.Spawn("player", 46, 118, 197, "Bite")
Debug.Log("spawn")
end
function move()
enemies = Level.GetObjects("enemy")
for i = 1, #enemies do --this controlsall the enemies not jsut one
Controller.Patrol(enemies[i], 2)
end
end
function bush()
bush = Level.GetObject ("bush")
end
function DoPlayer()
player.object = Level.GetObject("Player")
end
function DoSign()
Sign = Level.GetObject("Sign")
Sign2 = Level.GetObject ("Sign2")
end
function DoDoor()
door = Level.GetObject("door")
end
function info (target, source)
if target == player.object then
Hud.Message ("Pick up coins to proceed to the next area!", 3)
end
end
function info2 (target,source)
if target == player.object then
Hud.Message ("You win!" , 5)
end
end
function CoinPickup(target, source)
coin = Level.GetObjects("coin")
if target == player.object then
player.score = player.score + 1
Level.RemoveObject(source) -- source is the eact coin that triggered the function
if not Sound.IsPlaying(playingBump) then
playingBump = Sound.Play(sounds.bump)
if player.score == 2 then
Level.RemoveObject (door)
Level.Spawn (bush, 37, 311, 275, false)
Level.Spawn (bush, 37, 311, 250, false)
end
end
end
end
function DoorOpen(target, source)
if target == player.object
and player.score == 2
then Level.RemoveObject (source)
if not Sound.IsPlaying (playingBump) then
playingBump = Sound.Play (sounds.bumpy)
end
end
end
function DoorOpen2 (target, source)
if target == player.object
and player.score == 3
then Level.RemoveObject (source)
if not Sound.IsPlaying (playingBump) then
playingBump = Sound.Play (sounds.bumpy)
end
end
end
function DoorOpen3 (target, source)
if target == player.object
and player.score == 5
then Level.RemoveObject (source)
if not Sound.IsPlaying (playingBump) then
playingBump = Sound.Play (sounds.bumpy)
end
end
end
function DoorOpen4 (target, source)
if target == player.object
and player.score == 6
then Level.RemoveObject(source)
if not Sound.IsPlaying (playingBump) then
playingBump = Sound.Play (sounds.bumpy)
end
end
end
--player hits bushbytes
function Bushbytes(target, source)
if target == player.object then
if not player.beenHit then
player.health = player.health - 1
Timer.Start("MayBeHitAgain", 1, false)
end
player.beenHit = true
end
end
function MayBeHitAgain()
player.beenHit = false
end
죄송합니다. 귀하의 질문에 이해가되지 않습니다. 코드의 어떤 부분이 원하는 것을 수행하지 않는 것입니까? (당신은 어떤 일이 일어나기를 기대 했는가, 대신에 어떤 일이 일어 났는가?) 개인적으로 기꺼이 나아가는 것보다 더 많은 코드가 필요합니다. 예를 들어, 'Bushbytes'는 질문과 관련이 있습니까? – Phrogz
하하 미안하지만, 나는 많이 설명하지 않았다. 나는 단순히 레벨 기능 LUA를 다시 찾고 있었다. 나는 다른 곳에서 질문을 올렸고 그들은 "충분한 정보가 아니라 도울 수 없다"고 말했다. 그래서 이번에 나는 더 많은 정보를 제공하기로 결정했다. 어쨌든, 전체 레벨을 다시 시작하는 데 도움이 필요하십니까? – ChibiSugar