123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /*
- * Copyright (c) 2010 Nokia Corporation.
- */
- import Qt 4.7
- Item {
- id: missile
- objectName: "missile"
- opacity: 0 // transparent by default
- property int fromYpos
- property int toYpos
- property variant myMissileSize
- property bool enemyMissile: false
- property int defaultX: 0
- property int defaultY: 0
- function storeDefaultPos() {
- defaultX = missile.x
- defaultY = missile.y
- }
- function setToDefaultPos() {
- missile.x = defaultX
- missile.y = defaultY
- opacity = 0.5
- }
- function createGraphicsForLevel() {
- missile.myMissileSize = LevelPlugin.graphSize(LevelPlugin.pathToMissilePic())
- missile.height = myMissileSize.height;
- missile.width = myMissileSize.width;
- if (missile.enemyMissile) {
- missileImage.source = "file:/"+LevelPlugin.pathToEnemyMissilePic()
- } else {
- missileImage.source = "file:/"+LevelPlugin.pathToMissilePic()
- }
- }
- // Execute fire!
- function fire(aXpox, aFromYpos, aToYpos) {
- missile.x = aXpox - missile.width / 2
- missile.y = aFromYpos
- missile.fromYpos = aFromYpos
- missile.toYpos = aToYpos
- missile.opacity = 1
- GameEngine.playSound(2) // NOTE: 3 for your missile sound
- flying.restart()
- }
- // Enemy fires!
- function enemyFire(aXpox, aFromYpos, aToYpos) {
- missile.x = aXpox - missile.width / 2
- missile.y = aFromYpos
- missile.fromYpos = aFromYpos
- missile.toYpos = aToYpos
- missile.opacity = 1
- GameEngine.playSound(3) // NOTE: 3 for enemy missile sound
- flyingEnemy.restart()
- }
- // Stop missile
- function stop() {
- flying.stop()
- }
- // Pause missile
- function pause(doPause) {
- if (doPause) {
- flying.pause()
- flyingEnemy.pause()
- } else {
- flying.resume()
- flyingEnemy.resume()
- }
- }
- Component.onCompleted: {
- if (!enemyMissile) {
- storeDefaultPos()
- setToDefaultPos()
- }
- }
- // Animates missile flying to the target
- SequentialAnimation {
- id: flying
- PropertyAnimation {target: missile; properties: "y";
- from: fromYpos; to: toYpos; duration: 2000; easing.type: Easing.InCubic }
- //PropertyAction {target: missile; properties: "opacity"; value: 0}
- ScriptAction { script: setToDefaultPos() }
- }
- SequentialAnimation {
- id: flyingEnemy
- PropertyAnimation {target: missile; properties: "y";
- from: fromYpos; to: toYpos; duration: 2000; easing.type: Easing.InCubic }
- PropertyAction {target: missile; properties: "opacity"; value: 0}
- }
- Image {
- id: missileImage
- smooth: true
- }
- }
|