LUA - перезапустить уровень?
Я работаю над 2D-игрой в ZeroBrane и Tiled, и пытаюсь создать функцию, при которой, когда игрок набирает == 0, весь уровень перезапускается, так что все возвращается на прежнее место. Я все еще n00b, поэтому, пожалуйста, объясните на языке noob! Это то, что у меня сейчас, это не так долго, поэтому я решил опубликовать весь сценарий.
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 ответ
У тебя уже есть Respawn
функция, воссоздающая игрока, когда его здоровье снижается до 0. Вы должны расширить эту логику, очистив любое текущее состояние и выполнив все, что соответствует вашему определению "сброс уровня".
Например, если у вас есть враги, вы, вероятно, хотите удалить их и очистить enemies
Таблица. Вам также может понадобиться сбросить состояние дверей, все собранные монеты и так далее.