Skip to content

Commit

Permalink
Forgot to give y'all a function.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearsandwich committed Oct 30, 2013
1 parent d5b1d82 commit 3e46cb7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions section-05/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 3e46cb7

Please sign in to comment.