1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of The Qt Company Ltd nor the names of its
21 ** contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
42 import Qt.labs.particles 1.0
50 // Background image for the level
53 source: "file:/"+LevelPlugin.pictureRootPath()+"background3.png"
54 fillMode: Image.PreserveAspectCrop
56 //anchors.fill: parent
62 // ***************************************************
63 // *** NOTE: This is mandatory for all level QML files
64 function pause(doPause) {
69 rightLeftAnim.resume()
75 // ***************************************************
76 // *** NOTE: This is mandatory for all level QML files
79 property int enemySpeed: LevelPlugin.enemySpeed()
80 property int enemyMaxWidth
82 // Create enemies dynamically
83 function createEnemies(amount) {
85 for (var i=0;i<amount;i++) {
87 Qt.createQmlObject('import QtQuick 1.0; Image { property bool hit:false; width:50; objectName:"enemy"; smooth:true; fillMode:Image.PreserveAspectFit; source:"file:/"+LevelPlugin.pictureRootPath()+"enemy1.png";}',enemiesGrid);
89 Qt.createQmlObject('import QtQuick 1.0; Image { property bool hit:false; width:50; objectName:"enemy"; smooth:true; fillMode:Image.PreserveAspectFit; source:"file:/"+LevelPlugin.pictureRootPath()+"enemy2.png";}',enemiesGrid);
95 // Calculate enemy max width
96 function calEnemyMaxWidth() {
97 var enemyCountInCol = LevelPlugin.enemyCount() / LevelPlugin.enemyRowCount();
98 enemyCountInCol++; // add some extra space needs for width
99 if (enemyCountInCol*LevelPlugin.graphSize(LevelPlugin.pictureRootPath()+"enemy1.png").width > gameArea.width) {
100 enemyMaxWidth = gameArea.width / (enemyCountInCol + 1);
103 enemyMaxWidth = LevelPlugin.graphSize(LevelPlugin.pictureRootPath()+"enemy1.png").width;
108 Component.onCompleted: {
109 // Calculate enemy max width
112 // Create enemies dynamically after component created
113 createEnemies(LevelPlugin.enemyCount())
116 enemiesGrid.y = enemiesGrid.height * -1
117 rightLeftAnim.restart()
118 upToDownAnim.restart()
120 // Flying stars animation, not in Maemo
121 if (!GameEngine.isMaemo()) {
122 starBurstTimer.restart()
125 GameEngine.playSound(4) // NOTE: Level start sound
131 interval: starParticles.lifeSpan+GameEngine.randInt(100,2000); running: false; repeat: true
133 starParticles.burst(GameEngine.randInt(4,10))
138 // Right-left animation
139 SequentialAnimation {
141 loops: Animation.Infinite
142 NumberAnimation { target:enemiesGrid; property:"x"; from: 0; to:gameArea.width - enemiesGrid.width; easing.type: Easing.OutQuad; duration: 3000 }
143 NumberAnimation { target:enemiesGrid; property:"x"; to: 0; easing.type: Easing.OutQuad; duration: 3000 }
146 // Up to down animation
147 PropertyAnimation { id: upToDownAnim; target:enemiesGrid; property:"y"; to: gameArea.height;
148 easing.type: Easing.Linear; duration: enemies.enemySpeed }
152 objectName: "enemiesGrid"
153 columns: LevelPlugin.enemyCount() / LevelPlugin.enemyRowCount()
157 // ***************************************************
158 // *** NOTE: This is mandatory for all level QML files
159 // Execute explode particle effect
160 function explode(x,y) {
161 explodeParticles.x = x
162 explodeParticles.y = y
163 explodeParticles.burst(20)
164 explodeParticles.opacity = 1
166 // ***************************************************
167 // *** NOTE: This is mandatory for all level QML files
168 // Explode particle effect
175 source: "file:/"+LevelPlugin.pictureRootPath()+"red_fire.png"
177 lifeSpanDeviation: 2000
182 velocityDeviation: 100
183 ParticleMotionGravity {
197 source: "file:/"+LevelPlugin.pictureRootPath()+"star3.png"
202 ParticleMotionGravity {