| Heli Merc: my first Shiva3D project |
|
| Saturday, 20 November 2010 09:37 |
|
Earlier in the year I purchased Shiva3D, the cross-platform multi-media development tool. Since then, whenever I have had a spare minute or two, I've invested some time learning it, creating several demo applications to explore Shiva's abilities. Overall, I've been impressed with Shiva, and how much of the functionality is supported by the Android engine used to run the apps. Sure, there are gaps, such as music not currently working and background images not showing, but overall, it appears easily good enough to create a game that will run on Android devices nearly as well as it does in the IDE, with very little platform specific code. With this in mind, I've decided to create something to run on my HTC Desire. Introducing "Heli Merc"The game's plot is simple (as game plots often are): The player is a helicopter pilot who is being paid handsomely to assist the "allied" side in a border dispute with a rival nation on a large, remote island. There are going to be numerous short missions that feature a specific task to complete mostly falling into the categories of defence, offence or rescue/recovery. Along the way, the player can spend cash to upgrade their helicopter. Why helicopters? I wanted to do a game with an arcade feel that didn't rely on an on-screen joypad controller because the Desire (and Nexus One) don't implement true multi-touch. Sure, they do pinch and zoom, but attempting to read the location of two simultaneous touches of the screen results in a stream of gibberish. To avoid this, I have to use the phone's accelerometers to control the action, and I felt that a helicopter was a suitable match for this input method. A single on-screen button will control weapon firing. Over the last few weeks I've put together a rough prototype to test out the controls and try out some ideas for graphics. I've settled on a semi-cartoony feel, mainly because it requires less detail, which means fewer textures and fewer polygons resulting in a faster frame rate and support lower-end hardware.
Designing a phone gameThe biggest issue I've encountered when working on phone development is the revelation that due to the hardware design, both Android and iPhone are pretty much limited to using textures totalling 1,024 by 1,024 pixels per frame. Ironically, it's faster to add more complex objects, rather than fake complexity by using textures as is typical in modern PC game design. With this in mind, I've designed the graphics for the prototype level to use as few textures as possible and make up for it with more polygons. The parallax scrolling hills and mountains that can be seen in the image are a good example of this. Rather than use a single rectangular polygon that has been textured with a picture of mountains, I've actually drawn the outline of the mountains using polygons. The three layers of mountains use a total of 500 polygons and in my testing, this approach has apparently not affected the frame rate at all on my Desire. After this, the next biggest issue to overcome has been how to handle infinite scrolling. Phone memory and resources are limited, so it's often not feasible to store a large level in memory. Instead, what I've done is create a background scene that is slightly larger than the area that the camera can see. Once the game starts, a duplicate copy of the background is made and placed to the left of the first. As the player moves to the left and the first block of graphics is no longer visible, it is moved ahead of the second block so that it will scroll into view. This is repeated over and over to give infinite scrolling. To handle foreground graphics, I've decided to create a single model for each level containing any detail that is necessary for the level. The game is essentially 2D, so the player is only really interacting with the foreground, and as it's only a thin strip, I can, through careful design, keep the resource usage to the minimum. The controlsTo give the helicopter a little realism, I'm using Shiva's convenient physics engine. When the level starts, the game calculates the throttle setting that is needed to generate sufficient up-force for the helicopter to cancel out gravity, giving a value that is will produce hovering. This is where the throttle defaults to, so that when the player is not touching the controls, the helicopter will settle in to a hover, making it easier to control. Tilting the phone away from the player will increase the throttle and the up-force, resulting in the helicopter moving higher, and tilting it down will reduce the throttle and up-force allowing gravity to take over. Left and right tilting controls the angle of attack, which transfers some of the up-force (dependant on the the angle) in the direction that the helicopter is facing so that it starts to move. If the player isn't tilting the phone up or down, then as the helicopter tilts, the throttle will automatically increase to provide more lift and keep the helicopter level while it moves forwards. To get the helicopter facing the direction it's moving, all I've done is to check it's velocity, and if it's moving left, then swing the helicopter that way until it's side on to the player. If it's moving right, then swing it in the reverse direction. It's then rotated to match the angle of attack, and the end result is it looks very much like a helicopter does when moving around. Finally, the rotor's rotation speed and the sound of the engine are both derived from the throttle setting as well. Since the throttle value ranges from 0.0 to 1.0, it's trivial to alter the rotor's rotation animation speed, and adjust the pitch to match the throttle setting. By tying the movement, animation and sound of the helicopter to one variable, throttle, it makes it much simpler to both code and detect bugs. So far, so goodThe basics are out the way now. I've got controls by joypad working on the PC which provides analogue control that is similar to input produced by tilting. Tilt control is working on the phone, though it's a bit sensitive at the moment, so I need to play around with that. Scrolling is implemented, the helicopter is moving around and when it gets close to the ground, it kicks up a cloud of dust. Graphics are adequate for now, but I'll work on them some more later. Best of all, it's running very quickly on my Froyo powered Desire, which means I'm on track to make sure it'll run OK on lower phone models such as the HTC Legend, though that'll have to be tested later to confirm. The next step is to start work on a trial level and implement things like enemies, bullets, and the player's death. Try out the latest version discussed in this blog post! Return to the Heli Merc section! blog comments powered by Disqus |

