From 5f915f617eb26d76522ca16e027317ac767d27ad Mon Sep 17 00:00:00 2001 From: Simon Kellet Date: Sun, 21 Jul 2024 19:46:59 +0100 Subject: [PATCH] added restarting functions --- libs/restart.lua | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 libs/restart.lua diff --git a/libs/restart.lua b/libs/restart.lua new file mode 100644 index 0000000..6fd2e1d --- /dev/null +++ b/libs/restart.lua @@ -0,0 +1,49 @@ +-- Functions to handle restarting +-- all objects +-- Used in map switching and restarting! + +function ClearWalls() + for w in pairs(Walls) do + Walls[w] = nil + end + + Walls = {} +end + +function StopAllMusic() + -- TODO: maybe find a way + -- to find all 'streaming' + -- sounds and then stop them all! + musicBattle:stop() + musicMenu:stop() + musicPause:stop() + musicStory:stop() +end + +function ClearPlayerCollision() + UserPlayer1.collider:destroy() + UserPlayer2.collider:destroy() +end + +function ClearBullets(bullets) + for i, v in ipairs(bullets) do + v.collider:destroy() + end +end + +function RestartGame() + -- Stop the music + StopAllMusic() + + -- Clear the players collision + ClearPlayerCollision() + + -- Work through and delete all bullets + ClearBullets(Bullets1) + ClearBullets(Bullets2) + + --Clear Walls + --ClearWalls() + + -- Done! +end