Game.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. /**
  5. * Hides the missiles.
  6. */
  7. function hideMissiles()
  8. {
  9. missile_1.stop();
  10. missile_1.opacity = 0;
  11. missile_2.stop();
  12. missile_2.opacity = 0;
  13. missile_3.stop();
  14. missile_3.opacity = 0;
  15. missile_4.stop();
  16. missile_4.opacity = 0;
  17. missile_5.stop();
  18. missile_5.opacity = 0;
  19. enemy_missile_1.opacity = 0;
  20. enemy_missile_2.opacity = 0;
  21. }
  22. /**
  23. *
  24. */
  25. function gameOver()
  26. {
  27. // Stop GameEngine timers
  28. GameEngine.enableEngineTimer(false);
  29. // Delete loaded plugin level
  30. deleteLevel();
  31. // Hiding
  32. myShip.opacity = 0;
  33. btnPause.opacity = 0;
  34. }
  35. /**
  36. * Pauses the game.
  37. *
  38. * @param doPause
  39. */
  40. function pauseGame(doPause)
  41. {
  42. missile_1.pause(doPause)
  43. missile_2.pause(doPause)
  44. missile_3.pause(doPause)
  45. missile_4.pause(doPause)
  46. missile_5.pause(doPause)
  47. enemy_missile_1.pause(doPause)
  48. enemy_missile_2.pause(doPause)
  49. if (doPause) {
  50. btnPause.opacity = 0
  51. myShip.focus = false;
  52. }
  53. else {
  54. btnPause.opacity = 1
  55. myShip.focus = true;
  56. }
  57. GameEngine.pauseLevel(doPause)
  58. }
  59. /**
  60. * Fires the player's missile.
  61. *
  62. * @param aXpox
  63. * @param aFromYpos
  64. * @param aToYpos
  65. */
  66. function fireMissile(aXpox, aFromYpos, aToYpos)
  67. {
  68. if (missile_1.opacity < 1) {
  69. missile_1.fire(aXpox,aFromYpos,aToYpos)
  70. }
  71. else if (missile_2.opacity < 1) {
  72. missile_2.fire(aXpox,aFromYpos,aToYpos)
  73. }
  74. else if (missile_3.opacity < 1) {
  75. missile_3.fire(aXpox,aFromYpos,aToYpos)
  76. }
  77. else if (missile_4.opacity < 1) {
  78. missile_4.fire(aXpox,aFromYpos,aToYpos)
  79. }
  80. else if (missile_5.opacity < 1) {
  81. missile_5.fire(aXpox,aFromYpos,aToYpos)
  82. }
  83. }
  84. /**
  85. * Fires enemy missile. This function is called from the Qt C++ code.
  86. *
  87. * @param aXpox
  88. * @param aFromYpos
  89. * @param aToYpos
  90. */
  91. function fireEnemyMissile(aXpox, aFromYpos, aToYpos)
  92. {
  93. if (enemy_missile_1.opacity == 0) {
  94. enemy_missile_1.enemyFire(aXpox, aFromYpos, aToYpos)
  95. }
  96. else if (enemy_missile_2.opacity == 0) {
  97. enemy_missile_2.enemyFire(aXpox, aFromYpos, aToYpos)
  98. }
  99. }
  100. /**
  101. * Creates the level QML component.
  102. */
  103. function createLevel()
  104. {
  105. var levelComponent =
  106. Qt.createComponent("file:/" + LevelPlugin.qmlRootPath() + "Level.qml");
  107. if (levelComponent.status == Component.Ready) {
  108. if (gameArea.levelPlugin) {
  109. deleteLevel();
  110. }
  111. gameArea.levelPlugin = levelComponent.createObject(levelId);
  112. if (gameArea.levelPlugin == null) {
  113. messageBox.showErrorMessage("Error: Failed to create level!", 6000);
  114. return 1;
  115. }
  116. }
  117. else {
  118. messageBox.showErrorMessage("Error: Failed to create level!", 6000);
  119. return 1;
  120. }
  121. missile_1.createGraphicsForLevel();
  122. missile_1.setToDefaultPos();
  123. missile_2.createGraphicsForLevel();
  124. missile_2.setToDefaultPos();
  125. missile_3.createGraphicsForLevel();
  126. missile_3.setToDefaultPos();
  127. missile_4.createGraphicsForLevel();
  128. missile_4.setToDefaultPos();
  129. missile_5.createGraphicsForLevel();
  130. missile_5.setToDefaultPos();
  131. enemy_missile_1.createGraphicsForLevel();
  132. enemy_missile_2.createGraphicsForLevel();
  133. myShip.createGraphicsForLevel();
  134. return 0;
  135. }
  136. /**
  137. * Deletes the current level.
  138. */
  139. function deleteLevel()
  140. {
  141. if (gameArea.levelPlugin) {
  142. GameEngine.clearQmlObjects();
  143. gameArea.levelPlugin.opacity = 0;
  144. gameArea.levelPlugin.destroy();
  145. gameArea.levelPlugin = 0;
  146. }
  147. }