Game Development Reference
In-Depth Information
public interface IWall
function get x():Number;
function set x(value:Number):void;
function get y():Number;
function set y(value:Number):void;
function getRect(coordinateSpace:DisplayObject):Rectangle;
function hitTestObject(obj:DisplayObject):Boolean;
As you can see, the three interfaces share a great deal of func-
tionality and almost all methods that are native to DisplayObjects.
In fact, IHazard and IWall have identical method signatures. How-
ever, they must both exist so that the engine can differentiate
between one type of object and another. However, you could create
an interface based on all the common traits of these (called, say,
IDisplayObject ) and simply extend it to add specific functionality.
I did not do that in this case, however, because using interfaces on
the iPhone is already slightly slower at runtime, and because there
were only three of them, I opted to not abstract them one layer
further. If you had a version of this game with several other com-
ponents such as pickups or transporters, it would begin to make
sense to try to consolidate functionality into shared interfaces.
That sums up the engine components of Marble Runner. Next,
ll take a look at the application-specific classes for this imple-
mentation. These classes consist of the following:
the base document class for the game
the title screen
HowToPlay . as
the rules screen
Leaderboard . as
the screen displaying the top scores, and the
class that handles all communication with the back-end services
GameClip . as
the screen that instantiates the game engine and
displays UI elements like the score and timer
Marble . as
the class that implements IBall for the game
the sole class we
ll use to implement IWall
the hazard used in the second level
Results . as
the screen displayed at the end of a level
The only one of these classes we won
t examine is How To Play.
that it has a
button that returns to the title screen.
MarbleRunner: The Document Class
final public class MarbleRunner extends MovieClip
static public const EVENT_NAVIGATE:String = " navigate " ;
Search Nedrilad ::

Custom Search