Moto Trial Racer XNA is an example application and a motorcycle racing game on Windows Phone 7 & XNA Game Studio 4.0, demonstrating especially the use of Box2D.XNA. This application has been ported from corresponding Qt/QML example, and thereby also demonstrates and provides guidance on the porting and co-development between Qt and Windows Phone. Application concept and graphics are reused from QML version.
More information about the porting of the application can be found from the porting story page.
Design considerations
The following diagram shows the classes implemented in this application and the relations between those classes:
Game1
is the main class of the application and it derives from Microsoft.Xna.Framework.Game
. This class creates and handles the Level
class, all View
derived classes, and the AudioPlayer
class. The Game1
class also handles the game mechanics like timing, winning, and failing. The Level
class handles all the things related to the game world, like the physics, different game levels, the motorcycle, and notifying Game1
when the player should fail or win. Level
also has an access to AudioPlayer
. LevelEditor
derives from Level
. All the views that are shown on top the game world derives from View
. Game1
can have only one View
instance at a time and it creates and destroys the instance when needed. View
implements ButtonListener
interface so all the classes derived from it can create instances of Button
class and declare themselves as listeners for those buttons. LevelEditor
also implements ButtonsListener
. Only WinView
and LevelSaver
hold instances of TextInput
.
Instructions
Playing the game
A new game can be started by selecting New Game from the main menu and then the desired level from the shown list. After selecting the level the clock starts and the player can start driving the motorcycle. The goal is to get the motorcycle and the driver to the chequered flag as fast as possible. The game ends if any part of the motorcycle or player touches the spikes, or if the player's head touches any other object. If that happens, the same level can be tried again or another level can be selected. When the player gets to the chequered flag fast enough, he/she gets his/her name and time on the high scores list. The game can be paused, restarted, and exited at any time via the options menu.
The motorcycle is accelerated by tilting the device towards the player and braked by tilting the device away from the player. The center of mass can be moved backwards/forwards by pressing the arrow buttons in top corners of the game screen.
If you are running the game on emulator, you need to enable the keyboard by pressing PAGE UP key or PAUSE/BREAK key. When the keyboard is enabled the motorcycle can be accelerated by pressing the UP arrow key and braked by pressing the DOWN arrow key. In the level editor you can rotate an active object counterclockwise/clockwise by pressing 'A'/'D' key.
Creating own custom levels
The level editor can be launched from the main menu. In the level editor view new objects can be added by pressing the object buttons in top of the screen. After a new object is added, it can be dragged to any position. An active object can be also rotated by using two fingers. The starting point of the motorcycle can be adjusted by moving the motorcycle icon to the desired position. When the level is completed, it can be named and saved. The custom levels can be deleted by pressing and holding a level button in the level selecting view down for two seconds.
Sound effects
All the sounds used in the application - except the music in the main menu - have been downloaded from [The Freesound Project](http://www.freesound.org The Freesound Project).
- sagetyrtle: bells2
- mchladil: blast2
- paubg_pou: Motocross Arcs
- Sruddi1: Grunts