Online Book Reader

Home Category

iPhone Game Development - Chris Craft [64]

By Root 1599 0
You could take a simple digital reading of true or false for each of the four directions—up, down, left, right. Or you could take a more advanced analog reading with a range from, say, 0 to 1 for each of the four directions—up, down, left, right.

Using a digital reading would be more like playing a racing game on a desktop computer and using the keyboard to drive the car. Either you are pressing one of the left, right, up, or down arrow keys or you are not. Most players feel this is a little awkward and unrealistic. (We doubt anyone would want to drive a real car using only the left, right, up, and down keys to steer!) By using the iPhone's accelerometer, you create a natural range of motion more akin to a real steering wheel. Players can turn a little bit to the left or turn really hard to the left. Happy players make happy developers, so we will cover using the accelerometer for analog driving controls in the AmuckRacer example later in this chapter.

The next goal is “The game needs to increase in difficulty as it's played.” This is usually a very easy goal to achieve. You could simply make the car go faster and faster over time. Or you could increase the frequency of road obstacles, such as other vehicles or oil slicks. Another option would be to have the course become more challenging over time. The more the road veers to the left and right, the harder it becomes to stay on the track.

Another goal is “If the player drives off the road, the car should drastically lose speed.” You can check the car's position against the road's location, and if the car is off the road, lower the car's speed sufficiently. This will require using the collision detection methods we will cover later in this chapter.

Similarly we have the requirement of “If the player collides with another car or an oil slick, the car should come to a stop.” When you check to see if the car is on the road, you can also check to see if the car sprite is touching any other obstacle like another car or an oil slick. If there isa collision, you can bring the car to a stop and require the player to try and make up the lost time.

Consider the goal of “The player must make it to a checkpoint in order to continue playing to the next round.” How can we best accomplish this requirement? It would make sense that the player would have to make it to a checkpoint that is a certain distance away in a certain amount of time. Distance is just speed multiplied by time. You can track time very easily using the iPhone SDK's NSTimer object. You can track the player's speed with an application variable.

Then, using these two values, you can calculate the distance the player has covered at any given point in the game. Let's plan on having a display that shows the user how much time he has remaining and how much distance he has left to make it to the next checkpoint.

For the goal that “The game should include some viral aspect to help increase sales,” let's plan on letting the player send his friends an e-mail anytime he breaks the game's high score. This way we get the word out about our game, and friends can race amongst themselves.

Coding the application

You know the basics of how the game will work, and what it will take to make it all happen. You have reviewed the goals and steps required to accomplish those goals. Now you are ready to start creating this application. Before we open Xcode, it's a good idea to create an application mock-up or storyboard to help visualize what the end application will look like. See Figure 5.5 for one possible idea.

This prototype is intentionally rough, but in a way it helps us simplify the problem and focus on what is really important. We have the latest model red rectangle car, a road, and a lot of area that is not road. That is the meat of the application, and you will probably agree that, at its core, things are pretty straightforward.

Creating the project

We will continue to use the Utility Application template for this application. We will use the Main View for the main game screen, and we will use the information screen for

Return Main Page Previous Page Next Page

®Online Book Reader