Chapter 10. Underfoot – Selectively Leveraging the Physics System

So far, we've used Corona's support for the Box2D physics system primarily as a collision detector. It's been used in three projects and we've immediately turned off the gravity in every case. In at least one case, most bodies we create are sensors. This project will explore how to use more of the actual physics-based features to build a platform game with gravity and solid floors and walls.

What do we build?

For this project, we will start with a partly completed platform game; it contains all sprites, and a tile map module similar to that used in Project 7, Caves of Glory – Mastering Maps and Zones and Project 9, Into the Woods – Computer Navigation of Environments. We will add physics to this world to create the world interactions that support game play; walls and floors that stop the player, collision detection with enemies that doesn't allow them to actually push the player or cause things to bounce off each other, and climbable ladders. We'll use collision filtering, in combination with sensor body elements, to keep only the physics interactions that are actually useful to us.

What does it do?

You'll start out with working modules to load a map from a file, load characters with sprites and accept control signals for them, supply control events for your character from user input, track score, and recognize level completion. The game implements a simple platformer, where you jump from block to block, score points by jumping on top of enemies to squish them, and navigate ladders and pools of water. The player will move the character to the left-hand side or right-hand side by holding the screen on the desired side, climb by tilting the device backward or forward, and jump whenever they release the screen (including a tap for standing jumps).

Why is it great?

This project will address one aspect of the physics module that we've let slide up to this point: multi-element bodies (fixtures in Box2D's internal parlance). We've used them a little in the shooter projects, solely as a way to create concave physics shapes without freaking out Box2D. However, in this case, we'll really go down the fixtures rabbit hole, using different collision filters for different fixtures as well as creating bodies that contain both solid fixtures and sensor fixtures.

How are we going to do it?

The tasks for this project will focus on controlling physics interactions.

  • Building physics for the map
  • Making characters interact with the world
  • Driving character behavior
  • Responding to collisions with other characters
  • Bouncing off enemies as appropriate
  • Controlling gravity to enable climbing
  • Selecting collisions by manipulating contacts
  • Adding polish with custom fonts

What do I need to get started?

You will need to copy the contents of the version 0 folder in the project pack directory into a new project folder. These directions assume that you call this directory Underfoot.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.172.200