Missile.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) 2010 Nokia Corporation.
  3. */
  4. import Qt 4.7
  5. Item {
  6. id: missile
  7. objectName: "missile"
  8. opacity: 0 // transparent by default
  9. property int fromYpos
  10. property int toYpos
  11. property variant myMissileSize
  12. property bool enemyMissile: false
  13. property int defaultX: 0
  14. property int defaultY: 0
  15. function storeDefaultPos() {
  16. defaultX = missile.x
  17. defaultY = missile.y
  18. }
  19. function setToDefaultPos() {
  20. missile.x = defaultX
  21. missile.y = defaultY
  22. opacity = 0.5
  23. }
  24. function createGraphicsForLevel() {
  25. missile.myMissileSize = LevelPlugin.graphSize(LevelPlugin.pathToMissilePic())
  26. missile.height = myMissileSize.height;
  27. missile.width = myMissileSize.width;
  28. if (missile.enemyMissile) {
  29. missileImage.source = "file:/"+LevelPlugin.pathToEnemyMissilePic()
  30. } else {
  31. missileImage.source = "file:/"+LevelPlugin.pathToMissilePic()
  32. }
  33. }
  34. // Execute fire!
  35. function fire(aXpox, aFromYpos, aToYpos) {
  36. missile.x = aXpox - missile.width / 2
  37. missile.y = aFromYpos
  38. missile.fromYpos = aFromYpos
  39. missile.toYpos = aToYpos
  40. missile.opacity = 1
  41. GameEngine.playSound(2) // NOTE: 3 for your missile sound
  42. flying.restart()
  43. }
  44. // Enemy fires!
  45. function enemyFire(aXpox, aFromYpos, aToYpos) {
  46. missile.x = aXpox - missile.width / 2
  47. missile.y = aFromYpos
  48. missile.fromYpos = aFromYpos
  49. missile.toYpos = aToYpos
  50. missile.opacity = 1
  51. GameEngine.playSound(3) // NOTE: 3 for enemy missile sound
  52. flyingEnemy.restart()
  53. }
  54. // Stop missile
  55. function stop() {
  56. flying.stop()
  57. }
  58. // Pause missile
  59. function pause(doPause) {
  60. if (doPause) {
  61. flying.pause()
  62. flyingEnemy.pause()
  63. } else {
  64. flying.resume()
  65. flyingEnemy.resume()
  66. }
  67. }
  68. Component.onCompleted: {
  69. if (!enemyMissile) {
  70. storeDefaultPos()
  71. setToDefaultPos()
  72. }
  73. }
  74. // Animates missile flying to the target
  75. SequentialAnimation {
  76. id: flying
  77. PropertyAnimation {target: missile; properties: "y";
  78. from: fromYpos; to: toYpos; duration: 2000; easing.type: Easing.InCubic }
  79. //PropertyAction {target: missile; properties: "opacity"; value: 0}
  80. ScriptAction { script: setToDefaultPos() }
  81. }
  82. SequentialAnimation {
  83. id: flyingEnemy
  84. PropertyAnimation {target: missile; properties: "y";
  85. from: fromYpos; to: toYpos; duration: 2000; easing.type: Easing.InCubic }
  86. PropertyAction {target: missile; properties: "opacity"; value: 0}
  87. }
  88. Image {
  89. id: missileImage
  90. smooth: true
  91. }
  92. }