2015-01-29 7 views
-1

저는 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 
+1

죄송합니다. 귀하의 질문에 이해가되지 않습니다. 코드의 어떤 부분이 원하는 것을 수행하지 않는 것입니까? (당신은 어떤 일이 일어나기를 기대 했는가, 대신에 어떤 일이 일어 났는가?) 개인적으로 기꺼이 나아가는 것보다 더 많은 코드가 필요합니다. 예를 들어, 'Bushbytes'는 질문과 관련이 있습니까? – Phrogz

+0

하하 미안하지만, 나는 많이 설명하지 않았다. 나는 단순히 레벨 기능 LUA를 다시 찾고 있었다. 나는 다른 곳에서 질문을 올렸고 그들은 "충분한 정보가 아니라 도울 수 없다"고 말했다. 그래서 이번에 나는 더 많은 정보를 제공하기로 결정했다. 어쨌든, 전체 레벨을 다시 시작하는 데 도움이 필요하십니까? – ChibiSugar

답변

0

당신은 이미 건강이 아래로 당신은 어떤 현재 상태를 지우고 "수준을 재설정"의 당신의 정의에 맞는 모든 일을 함께하는 논리를 확장 할 필요가 0으로 때 플레이어를 재현 Respawn 기능을 가지고있다.

예를 들어, 적을 가지고 있다면이를 제거하고 enemies 표를 지우고 싶을 것입니다. 문 상태, 이미 수거 한 동전 등을 재설정해야 할 수도 있습니다.

+0

respawn 함수는 약간 버그가 있습니다. 플레이어가 다시 응답하지만 카메라가 따라 가지 않는다는 의미입니다. 또한, 나는 한 지점에서 닫히는 문을 가지고 있으며, 플레이어가 respawns 할 때, 당신이 말했듯이, 문은 여전히 ​​닫혀 있습니다. 그러나 나는 모든 것을 다시 시작하는 방법을 모른다. 언급 한 모든 것과 정확히 같습니다. 나는 단순히 "재설정"또는 그와 비슷한 것을 쓸 수 없다? – ChibiSugar