From 3e46cb70dce89301f4862c0c140cc77137e6f1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven!=20Ragnaro=CC=88k?= Date: Tue, 29 Oct 2013 20:01:00 -0700 Subject: [PATCH] Forgot to give y'all a function. --- section-05/README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/section-05/README.md b/section-05/README.md index 2e7a5a4..79bb251 100644 --- a/section-05/README.md +++ b/section-05/README.md @@ -59,7 +59,8 @@ delta value as speed. You can also read delta as "change in" so `deltaX` means to rotate our objects as they fly around. We also define an eachObstacle method so we can iterate over each obstacle. The reason for specifying negative one or one is so that our flying obstacles don't all begin flying in the same -direction. +direction. We also need to clear all the obstacles when you get a Game Over. +To do that we remove them from the display, then set them to nil. ```lua local obstacleImages = { "icecream.png", "yarn.png", "penguin.png" } @@ -71,6 +72,13 @@ obstacles.eachObstacle = function(obstacles, doEach) end end +obstacles.clearAll = function(obstacles) + for i = 1, #obstacles do + display.remove(obstacles[i]) + obstacles[i] = nil + end +end + local newObstacle = function() local obstacle = display.newImageRect(obstacleImages[math.random(1, #obstacleImages)], 50, 50) local negativeOneOrOne = {1, -1} @@ -152,7 +160,9 @@ end Then write a `detectCollisions` function that checks if the ship collides with any obstacles and make sure it's called by our `eachFrame` function. If any -obstacle collides with the ship, call `resetGame`. +obstacle collides with the ship, call `resetGame`. You might notice that this +function isn't defined. What should happen when you reset the game? Write a +function that does those things. ```lua local detectCollisions = function()