The Flying Bus Game
To start the game concept, a design team created an image set and some flash animations to be used as reference. With this first concept ready, I was able to create the first version of the game in less than a day using QML. After this bootstrap, there were some incremental changes, like new elements and new behaviors.
Regarding the organization, the game is divided in subfolders: resource folder, level folder and source folder.
The simple architecture used in this game can be applied to several others. Basically there are four main components: Canvas, Sprites, Level loader and the Game engine. They are detailed as follows:
Using QML, a canvas is a simple QML item which contains other QML items. In this game, the canvas has two layers: the background layer and the foreground layer.
The background layer contains all elements that do not interact with the player, including clouds, mountains, the sun, and so on. The foreground layer contains elements that can interact with the player, including enemies, bonus items and obstacles.
Player, enemies, bonus items and obstacles are considered sprites. All sprites in this game inherit the same QML component, so they have common properties, like position, size, opacity, velocity and so on. Each sprite is described in a separate file and can be as complex as you want regarding states and animations.
The loader is responsible for reading (XML) level files and to pass the correct information to the game engine, which will create sprites accordingly. QML provides an easy way to read an XML file using XmlListModel API, which is used by the loader.
The game engine is the core logic of the game. It’s responsible for dynamically creating the sprites according to the level information, and to handle the game logic which includes: scene movement, collision detection and game state control. Since the physics of this game is very simple the engine is very small. For more complex engines, a C++/QML application can also be an option.
From my experience, I would say that developing using QML brings a lot of advantages over using an imperative API to mount the UI; with QML you will notice a huge reduction in the number of lines of code necessary to create the UI.
As an example, porting some of my old C++/ applications to QML resulted in 75% fewer lines of code.
Regarding game development, QML can be a fast tool to create simple games like this one and it will ease a lot the development of such games due the powerful State/Animation API and its compact syntax.
Most of the game logic can be moved from the game engine to the QML side, reducing significantly the complexity of the engine.
l notice a huge reduction in the number of lines of code necessary to create the UI.
To download flying bus and several other demos:
git clone git://gitorious.org/qt-labs/mobile-demos.git
NOTE: Installing this Qt Quick demo app on your Symbian^3 device will also install a beta version of Qt 4.7.1 which may cause the Ovi Store client or other Qt-based applications to fail. Until we update the apps with Qt 4.7.2 we advise you to not use your personal phone.
If you have installed the Qt Quick demo apps and consequently Qt 4.7.1 onto your device and want to uninstall the apps and downgrade Qt follow these instructions.