Create a Cut-the-Rope Inspired Game - Adding Interaction

This is the second installment in our Corona SDK Cut the Rope Inspired tutorial. In today’s tutorial, we’ll add to our interface and code 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 it.


Step 3: Hide Credits

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

Step 4: Show 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 Instructions

This code places the instructions image in the stage.


Step 6: Dog

Next we add the Dog image and place it in the center of the stage.


Step 7: Shadow Stars

This part creates the stars in the left corner.


Step 8: Physics

Now we add physics to the Dog and call the functions that will load the level and add the game listeners.


Step 9: Load Level

The following code uses a double for and a two dimensional table to place the level in the stage. First we check every item in the table to see if it's a 1 which represents the hanger. Next we chek for 2's which represents the stars. In true, a variable is created and physics is added to the body.


Step 10: Add Rope

Another for is used to add the rope. It is composed of 8 parts that are stored in a display Group.


Step 11: Joints

In this part we use physics joints to "glue" the parts of the rope, the rope to the hanger and the rope to the bone.


Step 12: Game Listeners

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


Step 13: Draw Line

This function uses the touch event and its phases to create a line in the stage when its swiped. It calculates the starting points in the began phase, draws when the finger is moved, and stops when it is lifted.


Step 14: Rope Collision

When the line collides with the rope, a part is removed, breaking the joint and making the bone fall.


Step 15: Star-Bone Collision

This function checks if the bone touches a star, fills a shadow star and plays a sound when true.


Step 16: Bone-Dog Collision

A sound plays and an alert is called when the dog catches the bone.


Step 17: Alert

This function will stop the game and display the Level Complete message by using the alert background and tweening it.


Step 18: 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 19: 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 20: 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 21: Testing in the 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 22: 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!

Tags:

Comments

Related Articles