QuickTowerMainTable.qml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import QtQuick 1.0
  2. Rectangle {
  3. id: mainwindow
  4. width: 500
  5. height: 500
  6. Rectangle {
  7. id: table
  8. anchors.fill: parent
  9. gradient: Gradient {
  10. GradientStop {
  11. position: 0.0; color: "green"
  12. }
  13. GradientStop {
  14. position: 0.5; color: "yellow"
  15. }
  16. GradientStop {
  17. position: 1.0; color: "blue"
  18. }
  19. }
  20. opacity: 0.8
  21. Rectangle {
  22. id: bottomline
  23. width: 500
  24. height: 20
  25. anchors.baseline: parent.bottom
  26. anchors.baselineOffset: -20
  27. color: "red"
  28. }
  29. Rectangle {
  30. id: nextline
  31. width: bottomline.width/2
  32. height: 20
  33. anchors.baseline: bottomline.top
  34. anchors.baselineOffset: -200
  35. color: "red"
  36. }
  37. Rectangle {
  38. id: player;
  39. width: 20; height: 20; radius:10
  40. anchors.baseline: bottomline.top
  41. anchors.baselineOffset: -height
  42. property int startx
  43. property int starty
  44. onXChanged: {
  45. if (jump.running==false)
  46. {
  47. if ( (player.anchors.baselineOffset==-200)
  48. || (player.anchors.baselineOffset==0) )
  49. {
  50. fall.stop();
  51. }
  52. else
  53. {
  54. fall.start();
  55. }
  56. }
  57. }
  58. onYChanged:
  59. {
  60. if (jump.running==false)
  61. {
  62. if ( (player.anchors.baselineOffset==-200)
  63. || (player.anchors.baselineOffset==0) )
  64. {
  65. fall.stop();
  66. }
  67. else
  68. {
  69. fall.start();
  70. }
  71. }
  72. }
  73. }
  74. PropertyAnimation{
  75. from: -200; to: 0
  76. duration: 10000
  77. target: bottomline
  78. properties: "anchors.baselineOffset"
  79. running: false
  80. loops: Animation.Infinite
  81. }
  82. }
  83. PropertyAnimation{
  84. id: jump
  85. from: player.starty; to: player.starty-200
  86. duration: 400
  87. target: player
  88. properties: "anchors.baselineOffset"
  89. easing.type: Easing.OutQuad
  90. }
  91. PropertyAnimation{
  92. id: fall
  93. from: player.anchors.baselineOffset; to: 0
  94. duration: 400
  95. target: player
  96. properties: "anchors.baselineOffset"
  97. easing.type: Easing.InQuad
  98. }
  99. PropertyAnimation{
  100. id: goright;
  101. target: player;
  102. properties: "x";
  103. from: player.x; to:table.width-player.width;
  104. duration: 2000*(1-(player.startx/table.width));
  105. }
  106. PropertyAnimation{
  107. id: goleft;
  108. target: player;
  109. properties: "x";
  110. from: player.x; to:0;
  111. duration: 2000*(player.startx/table.width);
  112. }
  113. focus: true
  114. Keys.onPressed:{
  115. if (event.key == Qt.Key_Left) {
  116. if (goleft.running==false)
  117. {
  118. goright.stop();
  119. player.startx=player.x;
  120. goleft.start();
  121. }
  122. }
  123. if (event.key == Qt.Key_Right) {
  124. if (goright.running==false)
  125. {
  126. goleft.stop();
  127. player.startx=player.x
  128. goright.start();
  129. }
  130. }
  131. if (event.key == Qt.Key_Space)
  132. {
  133. player.starty=player.anchors.baselineOffset
  134. jump.start();
  135. }
  136. }
  137. Keys.onReleased:{
  138. goright.stop();
  139. goleft.stop();
  140. }
  141. }