# Corona SDK: Building a Space Shooter - Final Steps

Welcome to the final tutorial in our Space Shooter game series! In this tutorial, we'll handle the enter frame logic, collision detection, and the steps to build the final app.

## Where We Left Off. . .

Please be sure to check part 1 and part2 of the series to fully understand this tutorial.

## Step 1: Update

The update function handles all the actions that occur on enterframe, such as movie clip movements.

 1 2 function update(e)  3  --code  4 end 

## Step 2: Move Bullets

The following code identifies when a bullet(s) is on the screen and moves it (them) 10 pixels every frame.

 1 2 if(bullets.numChildren ~= 0) then  3  for i = 1, bullets.numChildren do  4  bullets[i].y = bullets[i].y - 10  5   6  -- Destroy Offstage Bullets  7 8  if(bullets[i].y < -bullets[i].height) then  9  bullets:remove(bullets[i])  10  display.remove(bullets[i])  11  bullets[i] = nil  12  end  13  end  14  end 

## Step 3: Move Enemies

Enemies are also moved using a similar method:

 1 2 if(enemies.numChildren ~= 0) then  3  for i = 1, enemies.numChildren do  4  if(enemies[i] ~= nil) then  5  enemies[i].y = enemies[i].y + 3 

## Step 4: Offstage Sprites

When the enemies or bullets are no longer visible on the stage, they are removed to save memory.

 1 2 if(enemies[i].y > display.contentHeight) then  3  enemies:remove(enemies[i])  4  display.remove(enemies[i])  5  --enemies[i] = nil  6  end  7  end  8  end  9  end 

## Step 5: Show Boss

The boss can be shown at any time in the game. In this example, the boss is shown when the score reaches 50 (destroy one enemy). You can modify this parameter to show the boss later in the game.

 1 2 if(scoreN == 50 and boss == nil) then  3  audio.play(bossSound)  4  boss = movieclip.newAnim({'bossA.png','bossA.png','bossA.png','bossA.png','bossA.png', 'bossA.png','bossA.png', 'bossB.png','bossB.png','bossB.png','bossB.png','bossB.png','bossB.png','bossB.png'})  5  boss.x = display.contentWidth * 0.5  6  boss.name = 'boss'  7  physics.addBody(boss)  8  boss.bodyType = 'static'  9  transition.to(boss, {time = 1500, y = boss.height + (boss.height * 0.5)})  10  boss:play()  11  boss:addEventListener('collision', collisionHandler)  12  end  13 end 

## Step 6: Collision Handler

This function handles all collisions, it uses the name parameter declared before to identify which sprites are colliding and performs a different action according to it.

 1 2 function collisionHandler(e)  3  if(e.other.name == 'bullet' and e.target.name == 'enemy') then  4  audio.play(explo)  5  display.remove(e.other)  6  display.remove(e.target)  7  scoreN = scoreN + 50  8  score.text = 'Score: ' .. tostring(scoreN)  9  score:setReferencePoint(display.TopLeftReferencePoint)  10  score.x = 1  11  elseif(e.other.name == 'bullet' and e.target.name == 'boss') then  12  audio.play(explo)  13  display.remove(e.other)  14  bossHealth = bossHealth - 1  15  scoreN = scoreN + 50  16  score.text = 'Score: ' .. tostring(scoreN)  17  score:setReferencePoint(display.TopLeftReferencePoint)  18  score.x = 1  19  if(bossHealth <= 0) then  20  display.remove(e.target)  21  alert('win')  22  end  23  elseif(e.other.name == 'ship') then  24  audio.play(explo)  25   26  display.remove(e.target)  27   28  -- Remove Live  29   30  display.remove(lives[lives.numChildren])  31   32  -- Check for Game Over  33   34  if(lives.numChildren < 1) then  35  alert('lose')  36  end  37  end  38 end 

## Step 7: Restart

 1 2 function restart()  3  listeners('remove')  4   5  display.remove(bullets)  6  display.remove(enemies)  7  display.remove(ship)  8  display.remove(alertView)  9   10  Main()  11 end 

## Step 8: Call Main Function

In order to initially start the game, the Main function needs to be called. With the above code in place, we'll do that here:

 1 2 Main() 

The Default.png file is an image that will be displayed right when you start the application while iOS loads the basic data to show the Main Screen. Add this image to your project source folder. The Corona compiler will then automatically add it as the load screen.

## Step 10: Icon

Using the graphics you created before, you can now create a nice and good looking icon. The icon size for the non-retina iPhone icon is 57x57px, but the retina version is 114x114px, and the iTunes store requires a 512x512px version. I suggest creating the 512×512 version first, and then scaling down for the other sizes.

It doesn’t need to have the rounded corners or the transparent glare. iTunes and the iPhone will do that for you.

## Step 11: Testing in Simulator

It's time to do the final test. Open the Corona Simulator, browse to your project folder, and then click open. If everything works as expected, you are ready for the final step!

## Step 12: Build

In the Corona Simulator go to File > Build and select your target device. Fill the required data and click build. Wait a few seconds and your app will be ready for device testing and/or submission for distribution!

## Conclusion

Experiment with the final result and try to make your custom version of the game!

I hope you liked this tutorial series and find it helpful. Thank you for reading!