Gravity.qml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import QtQuick 2.5
  2. import Box2D 2.0
  3. Item {
  4. id: root
  5. signal togglePause
  6. signal toggleChaos
  7. signal next
  8. property var pictureDelegate: Qt.createComponent("HorizontalArtDelegate.qml")
  9. anchors.fill: parent
  10. QtObject {
  11. id: d
  12. property double pace: settings.pace/60.0
  13. property int itemCount: 0
  14. property int itemTravel: settings.itemTravel
  15. property int primedColumns: 0
  16. property int columnCount: settings.columnCount
  17. property bool running: primedColumns >= columnCount
  18. function reset() {
  19. itemCount = 0
  20. primedColumns = 0
  21. }
  22. onColumnCountChanged: reset()
  23. }
  24. World {
  25. id: bullshitWorld
  26. timeStep: d.pace
  27. running: d.running
  28. }
  29. World {
  30. id: commonWorld
  31. timeStep: d.pace
  32. running: d.running
  33. }
  34. Component {
  35. id: columnComponent
  36. Item {
  37. id: column
  38. property int stackHeight: 0
  39. property bool full: false
  40. onStackHeightChanged: {
  41. if (!column.full && (stackHeight > root.height)) {
  42. d.primedColumns += 1
  43. column.full = true
  44. }
  45. }
  46. function addImage() {
  47. var item = pictureDelegate.createObject(column, { x: -1000, y: -1000 })
  48. item.beyondThePale.connect(removeImage)
  49. stackHeight += (item.height + d.itemTravel)
  50. item.x = width * index
  51. item.y = floor.y - stackHeight
  52. d.itemCount++
  53. pictureArray.push(item)
  54. }
  55. function removeImage(image) {
  56. stackHeight -= (image.height + d.itemTravel)
  57. image.destroy()
  58. d.itemCount--
  59. }
  60. width: parent.width/d.columnCount
  61. anchors { top: parent.top; bottom: parent.bottom }
  62. property var pictureArray: []
  63. property var physicsWorld: commonWorld
  64. property bool fixedRotation: true
  65. Timer {
  66. id: pumpTimer
  67. interval: Math.random()*500 + 500
  68. repeat: true
  69. running: !full
  70. onTriggered: {
  71. addImage()
  72. }
  73. }
  74. Timer {
  75. id: deathTimer
  76. running: d.running
  77. repeat: true
  78. interval: 1000*(settings.interval > 60 ? 60*(settings.interval-60) : settings.interval)*(Math.random()+1)
  79. onTriggered: {
  80. if (pictureArray.length > 0) {
  81. var image = pictureArray.shift()
  82. image.world = bullshitWorld
  83. addImage()
  84. }
  85. }
  86. }
  87. Connections {
  88. target: root
  89. onTogglePause: deathTimer.running = !deathTimer.running
  90. onNext: deathTimer.triggered()
  91. onToggleChaos: fixedRotation = !fixedRotation
  92. }
  93. Timer {
  94. id: settleTimer
  95. running: false
  96. interval: 200
  97. onTriggered: deathTimer.triggered()
  98. }
  99. }
  100. }
  101. // floor
  102. RectangleBoxBody {
  103. id: floor
  104. world: commonWorld
  105. height: 0
  106. anchors {
  107. left: parent.left
  108. right: parent.right
  109. top: parent.bottom
  110. }
  111. friction: 1
  112. density: 1
  113. }
  114. DebugDraw {
  115. id: debugDraw
  116. enabled: false
  117. z: 1
  118. world: commonWorld
  119. anchors.fill: parent
  120. opacity: 0.75
  121. visible: enabled
  122. }
  123. Repeater {
  124. model: d.columnCount
  125. delegate: columnComponent
  126. }
  127. // TODO: The boot (Monty Python foot) of death to be applied to the stacks
  128. RectangleBoxBody {
  129. id: rect
  130. enabled: false
  131. visible: false
  132. friction: 1.0
  133. density: 1000
  134. color: "red"
  135. width: 50; height: 50
  136. bullet: true
  137. SequentialAnimation {
  138. id: murderAnimation
  139. //loops: Animation.Infinite
  140. //running: true
  141. ScriptAction { script: { root.togglePause() } }
  142. ScriptAction { script: { rect.world = worldArray.pop() } }
  143. PropertyAction { target: rect; property: "x"; value: -rect.width }
  144. PropertyAction { target: rect; property: "y"; value: root.height }
  145. ParallelAnimation {
  146. NumberAnimation { target: rect; property: "x"; to: 2560; duration: 1000 }
  147. NumberAnimation { target: rect; property: "y"; to: 0; duration: 1000 }
  148. }
  149. }
  150. }
  151. Rectangle {
  152. visible: settings.viewItemCount
  153. z: 1
  154. color: "black"
  155. anchors { right: parent.right; top: parent.top }
  156. width: itemCountLabel.width
  157. height: itemCountLabel.height
  158. Text {
  159. id: itemCountLabel
  160. font.pixelSize: 100
  161. text: d.itemCount
  162. color: "white"
  163. }
  164. }
  165. Keys.onUpPressed: root.togglePause()
  166. Keys.onDownPressed: root.toggleChaos() //root.next()
  167. }