Flying Bus Game: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
'''English''' [[Flying Bus Game Japanese|日本語]]
[[Category:Developing_with_Qt::Qt Quick::Demos]]<br />[[Category:Learning::Demos_and_Examples]]


=The Flying Bus Game=
'''English''' [[Flying_Bus_Game_Japanese|日本語]]


==Description==
= The Flying Bus Game =


In order to test <span class="caps">QML</span> power, I avoided writing any C++ code for this game. The engine is written entirely in JavaScript, and has no more than 300 lines of code (including comments).
[YouTubeID:LTDJrMu24b8]


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 <span class="caps">QML</span>. After this bootstrap, there were some incremental changes, like new elements and new behaviors.
== Description ==
 
In order to test QML power, I avoided writing any C++ code for this game. The engine is written entirely in JavaScript, and has no more than 300 lines of code (including comments).
 
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.
Regarding the organization, the game is divided in subfolders: resource folder, level folder and source folder.


The resource folder contains every asset of the game. For this game specifically, there are only image files; the level folder contains <span class="caps">XML</span> files that describes each level of the game and the source folder contains <span class="caps">QML</span> files and JavaScript files.
The resource folder contains every asset of the game. For this game specifically, there are only image files; the level folder contains XML files that describes each level of the game and the source folder contains QML files and JavaScript files.


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:
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:


===Canvas===
=== Canvas ===


Using <span class="caps">QML</span>, a canvas is a simple <span class="caps">QML</span> item which contains other <span class="caps">QML</span> items. In this game, the canvas has two layers: the background layer and the foreground layer.
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.
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.


===Sprites===
=== Sprites ===
 
Player, enemies, bonus items and obstacles are considered sprites. All sprites in this game inherit the same <span class="caps">QML</span> 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.
 
===Level loader===
 
The loader is responsible for reading (<span class="caps">XML</span>) level files and to pass the correct information to the game engine, which will create sprites accordingly. <span class="caps">QML</span> provides an easy way to read an <span class="caps">XML</span> file using XmlListModel <span class="caps">API</span>, which is used by the loader.
 
===Game engine===
 
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 <span class="caps">QML</span> brings a lot of advantages over using an imperative <span class="caps">API</span> to mount the UI; with <span class="caps">QML</span> you will notice a huge reduction in the number of lines of code necessary to create the UI.
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.


As an example, porting some of my old C++/ applications to <span class="caps">QML</span> resulted in 75% fewer lines of code.
=== Level loader ===


Regarding game development, <span class="caps">QML</span> 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 <span class="caps">API</span> and its compact syntax.
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.


Most of the game logic can be moved from the game engine to the <span class="caps">QML</span> side, reducing significantly the complexity of the engine.<br /> l notice a huge reduction in the number of lines of code necessary to create the UI.
=== Game engine ===


==Download==
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.
<br />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.
<br />As an example, porting some of my old C''+/ applications to QML resulted in 75% fewer lines of code.


===Source 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.


http://qt.gitorious.org/qt-labs/mobile-demos/trees/master/qtflyingbus<br /> To download flying bus and several other demos: <br /> git clone git://gitorious.org/qt-labs/mobile-demos.git
Most of the game logic can be moved from the game engine to the QML side, reducing significantly the complexity of the engine.<br />l notice a huge reduction in the number of lines of code necessary to create the UI.


===Binaries===
== Download ==


Mac: http://get.qt.nokia.com/demos/mac/qtflyingbus.dmg<br /> Maemo: http://get.qt.nokia.com/demos/maemo/qtflyingbus_0.1-1_armel.deb<br /> Symbian: http://get.qt.nokia.com/demos/symbian/qtflyingbus_installer.sis<br /> Windows: http://get.qt.nokia.com/demos/windows/qtflyingbus_setup.exe
=== Source Code ===


'''<span class="caps">NOTE</span>:''' 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.
http://qt.gitorious.org/qt-labs/mobile-demos/trees/master/qtflyingbus<br />To download flying bus and several other demos:<br />git clone git://gitorious.org/qt-labs/mobile-demos.git


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 [[Qt-Quick-Demo-Apps-Downgrade|these instructions]].
=== Binaries ===


===Categories:===
Mac: http://get.qt.nokia.com/demos/mac/qtflyingbus.dmg<br />Maemo: http://get.qt.nokia.com/demos/maemo/qtflyingbus_0.1-1_armel.deb<br />Symbian: http://get.qt.nokia.com/demos/symbian/qtflyingbus_installer.sis<br />Windows: http://get.qt.nokia.com/demos/windows/qtflyingbus_setup.exe


* [[:Category:Developing with Qt|Developing_with_Qt]]
'''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.
** [[:Category:Developing with Qt::Qt Quick|Qt_Quick]]
*** [[:Category:Developing with Qt::Qt Quick::Demos|Demos]]
* [[:Category:Learning|Learning]]
** [[:Category:Learning::Demos and Examples|Demos_and_Examples]]

Revision as of 14:41, 23 February 2015


English 日本語

The Flying Bus Game

[YouTubeID:LTDJrMu24b8]

Description

In order to test QML power, I avoided writing any C++ code for this game. The engine is written entirely in JavaScript, and has no more than 300 lines of code (including comments).

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 resource folder contains every asset of the game. For this game specifically, there are only image files; the level folder contains XML files that describes each level of the game and the source folder contains QML files and JavaScript files.

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:

Canvas

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.

Sprites

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.

Level loader

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.

Game engine

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.

Download

Source Code

http://qt.gitorious.org/qt-labs/mobile-demos/trees/master/qtflyingbus
To download flying bus and several other demos:
git clone git://gitorious.org/qt-labs/mobile-demos.git

Binaries

Mac: http://get.qt.nokia.com/demos/mac/qtflyingbus.dmg
Maemo: http://get.qt.nokia.com/demos/maemo/qtflyingbus_0.1-1_armel.deb
Symbian: http://get.qt.nokia.com/demos/symbian/qtflyingbus_installer.sis
Windows: http://get.qt.nokia.com/demos/windows/qtflyingbus_setup.exe

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.