Advertisement
  1. Code
  2. Corona SDK
Code

Create a Lunar Lander Inspired Game – Adding Interaction

by
Difficulty:IntermediateLength:ShortLanguages:

This is the second installment in our Corona SDK Lunar Lander tutorial. In today’s tutorial, we’ll add to our interface and the game interaction. Read on!


Where We Left Off. . .

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


Step 1: Start Button Listeners

This function adds the necesary listeners to the TitleView buttons:


Step 2: Show Credits

The credits screen is shown when the user taps the about button, a tap listener is added to the credits view to remove this.


Step 3: Hide Credits

When the credits screen is tapped, it'll be tweened out of the stage and removed.


Step 4: Show the Game View

When the Start button is tapped, the title view is tweened and removed revealing the game view. There are many parts involved in this view, so we'll split them in the next steps.


Step 5: Add Moons

This code places the moons in the stage.


Step 6: Big Moon

A bigger moon is used as the landing spot. Use the next code to place it:


Step 7: Landing Spot

The landing spot is represented by an arrow graphic. A name property is created to help identify these elements when a collision occurs.


Step 8: Rocket

Next, we add the rocket. This will be our user-controlled element.


Step 9: Stars

The following code will place the stars on the screen:


Step 10: Controls

In order to move the Rocket in the screen we'll need a game pad, this code will take care of that. A tap listener will be added later to each button to handle the movement.


Step 11: Add Physics

Here we add the physics to the graphic elements.


Step 12: Game Listeners

This function adds the necessary listeners to start the game logic.


Step 13: Move Player Function

The direction variable is changed by this function, this will make the rocket go in the pressed direction.


Step 14: Rocket Movement

These lines move the rocket according to the direction stablished by the movePlayer function created in step 13.


Step 15: Rocket-Moon Collision

The next code listens for a variable set to true when a collision occurs between the rocket and a moon, the variable value is changed by the onCollision function that will be created later.

When true, the rocket will be placed at its original position and put into an sleep state to prevent a collision with the moon under it.


Step 16: Rocket-Star Collision

A similar method is used in the rocket-star collision detection.


Step 17: Landing Point Collision

The level will be complete when the player has collected the four stars and lands on the bigger moon. The following code handles that.


Step 18: Collision Function

This function runs when the rocket collides with another body. The name of the body is then checked to perform the right action. Basically, a sound is played and a variable is set to true (for the update function to see) according to the other body name.


Step 19: Call Main Function

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


Step 20: Loading Screen

The Default.png file is an image that will be displayed right when you start the application while the iOS loads the basic data to show the Main Screen. Add this image to your project source folder, it will be automatically added by the Corona compliler.


Step 21: 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 512x512 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 22: 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 23: 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!

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.