main.qml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. import Qt 4.7
  2. import "scripts.js" as Game
  3. Rectangle {
  4. id : gameArea
  5. width: 360
  6. height: 630
  7. property int score: 0
  8. property int lives: 3
  9. property int clickCount : 0
  10. property int hideTimerInterval: 1500
  11. property int gameTimerInterval: 1000
  12. StartScreen {
  13. id : mainView
  14. height: parent.height
  15. width: parent.width
  16. visible : true
  17. }
  18. GameScreen {
  19. id : gameView
  20. height: parent.height
  21. width: parent.width
  22. x : parent.width
  23. scoreText: score
  24. livesText: lives
  25. visible: false
  26. }
  27. InfoScreen {
  28. id: infoView
  29. height: parent.height
  30. width: parent.width
  31. x : parent.width
  32. visible : false
  33. }
  34. HighScoreScreen {
  35. id: highScoreView
  36. height: parent.height
  37. width: parent.width
  38. x : parent.width
  39. visible : false
  40. }
  41. Timer {
  42. id: gameTimer
  43. interval: gameTimerInterval
  44. running: false
  45. repeat: true
  46. onTriggered: Game.gameLoop(true)
  47. }
  48. Timer {
  49. id: hideTimer1
  50. interval: 1500
  51. running: false
  52. repeat: false
  53. onTriggered: Game.hideMonkey(1)
  54. }
  55. Timer {
  56. id: hideTimer2
  57. interval: 1500
  58. running: false
  59. repeat: false
  60. onTriggered: Game.hideMonkey(2)
  61. }
  62. Timer {
  63. id: hideTimer3
  64. interval: 1500
  65. running: false
  66. repeat: false
  67. onTriggered: Game.hideMonkey(3)
  68. }
  69. Timer {
  70. id: hideTimer4
  71. interval: 1500
  72. running: false
  73. repeat: false
  74. onTriggered: Game.hideMonkey(4)
  75. }
  76. Timer {
  77. id: hideTimer5
  78. interval: 1500
  79. running: false
  80. repeat: false
  81. onTriggered: Game.hideMonkey(5)
  82. }
  83. Timer {
  84. id: hideTimer6
  85. interval: 1500
  86. running: false
  87. repeat: false
  88. onTriggered: Game.hideMonkey(6)
  89. }
  90. Timer {
  91. id: hideTimer7
  92. interval: 1500
  93. running: false
  94. repeat: false
  95. onTriggered: Game.hideMonkey(7)
  96. }
  97. Timer {
  98. id: hideTimer8
  99. interval: 1500
  100. running: false
  101. repeat: false
  102. onTriggered: Game.hideMonkey(8)
  103. }
  104. Image {
  105. id: image2
  106. width: 40
  107. height: 40
  108. anchors.right: parent.right
  109. anchors.rightMargin: 5
  110. anchors.top: parent.top
  111. anchors.topMargin: 5
  112. fillMode: Image.PreserveAspectFit
  113. opacity: 0.4
  114. source: "images/close.png"
  115. MouseArea {
  116. anchors.fill: parent
  117. onClicked: {
  118. appData.close();
  119. }
  120. }
  121. }
  122. states: [
  123. State {
  124. name: "game"
  125. PropertyChanges {
  126. target: mainView
  127. x: - ( gameArea.width )
  128. height: gameArea.height
  129. }
  130. PropertyChanges {
  131. target: gameView
  132. x: 0
  133. height: gameArea.height
  134. }
  135. },
  136. State {
  137. name: "info"
  138. PropertyChanges {
  139. target: mainView
  140. x: - ( gameArea.width )
  141. height: gameArea.height
  142. }
  143. PropertyChanges {
  144. target: infoView
  145. x: 0
  146. height: gameArea.height
  147. }
  148. },
  149. State {
  150. name: "highscore"
  151. PropertyChanges {
  152. target: gameView
  153. x: - ( gameArea.width )
  154. height: gameArea.height
  155. }
  156. PropertyChanges {
  157. target: mainView
  158. x: - ( gameArea.width )
  159. height: gameArea.height
  160. }
  161. PropertyChanges {
  162. target: highScoreView
  163. x: 0
  164. height: gameArea.height
  165. }
  166. }
  167. ]
  168. transitions: [
  169. Transition {
  170. from: "game"
  171. to: "highscore"
  172. SequentialAnimation {
  173. ScriptAction {
  174. script: {
  175. highScoreView.visible = true;
  176. highScoreView.state = ""
  177. }
  178. }
  179. NumberAnimation { properties: "x"; duration: 300; easing.type: "OutInSine"}
  180. ScriptAction {
  181. script: {
  182. gameView.visible = false;
  183. }
  184. }
  185. }
  186. },
  187. Transition {
  188. from: "highscore"
  189. to: ""
  190. SequentialAnimation {
  191. ScriptAction {
  192. script: {
  193. mainView.visible = true
  194. }
  195. }
  196. NumberAnimation { properties: "x"; duration: 300; easing.type: "OutInSine"}
  197. ScriptAction {
  198. script: {
  199. highScoreView.visible = false;
  200. }
  201. }
  202. }
  203. },
  204. Transition {
  205. from: ""
  206. to: "game"
  207. SequentialAnimation {
  208. ScriptAction {
  209. script: {
  210. gameView.visible = true;
  211. }
  212. }
  213. NumberAnimation { properties: "x"; duration: 300; easing.type: "OutInSine"}
  214. ScriptAction {
  215. script: {
  216. mainView.visible = false;
  217. }
  218. }
  219. }
  220. },
  221. Transition {
  222. from: "game"
  223. to: ""
  224. SequentialAnimation {
  225. ScriptAction {
  226. script: {
  227. mainView.visible = true;
  228. }
  229. }
  230. NumberAnimation { properties: "x"; duration: 300; easing.type: "OutInSine"}
  231. ScriptAction {
  232. script: {
  233. gameView.visible = false;
  234. }
  235. }
  236. }
  237. },
  238. Transition {
  239. from: ""
  240. to: "info"
  241. SequentialAnimation {
  242. ScriptAction {
  243. script: {
  244. infoView.visible = true;
  245. }
  246. }
  247. NumberAnimation { properties: "x"; duration: 300; easing.type: "OutInSine"}
  248. ScriptAction {
  249. script: {
  250. mainView.visible = false;
  251. }
  252. }
  253. }
  254. },
  255. Transition {
  256. from: "info"
  257. to: ""
  258. SequentialAnimation {
  259. ScriptAction {
  260. script: {
  261. mainView.visible = true;
  262. }
  263. }
  264. NumberAnimation { properties: "x"; duration: 300; easing.type: "OutInSine"}
  265. ScriptAction {
  266. script: {
  267. infoView.visible = false;
  268. }
  269. }
  270. }
  271. },
  272. Transition {
  273. from: ""
  274. to: "highscore"
  275. SequentialAnimation {
  276. ScriptAction {
  277. script: {
  278. highScoreView.visible = true;
  279. highScoreView.state = ""
  280. }
  281. }
  282. NumberAnimation { properties: "x"; duration: 300; easing.type: "OutInSine"}
  283. ScriptAction {
  284. script: {
  285. mainView.visible = false;
  286. }
  287. }
  288. }
  289. }
  290. ]
  291. }