Gravity.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 bool globalWorld: settings.fitByHeight
  9. property var worldArray: []
  10. property var pictureDelegate: Qt.createComponent(settings.fitByHeight ? "VerticalArtDelegate.qml" : "HorizontalArtDelegate.qml")
  11. World {
  12. // Global world at odds with relative positions!
  13. id: commonWorld
  14. timeStep: settings.pace/60.0
  15. }
  16. Component {
  17. id: columnComponent
  18. Item {
  19. id: column
  20. x: xOffset - effectiveXOffset
  21. width: parent.width/settings.columnCount
  22. anchors { top: parent.top; bottom: parent.bottom }
  23. property var pictureArray: []
  24. property var physicsWorld: settings.globalWorld ? commonWorld : columnWorld
  25. property bool fixedRotation: true
  26. property int xOffset: width * index
  27. property int effectiveXOffset: settings.globalWorld ? xOffset : 0
  28. World {
  29. id: columnWorld
  30. timeStep: settings.pace/60.0
  31. Component.onCompleted: worldArray.push(columnWorld)
  32. }
  33. RectangleBoxBody {
  34. world: physicsWorld
  35. height: 1
  36. anchors {
  37. left: parent.left
  38. right: parent.right
  39. top: parent.bottom
  40. }
  41. friction: 1
  42. density: 1
  43. }
  44. Timer {
  45. id: feedTimer
  46. running: true
  47. repeat: true
  48. interval: 1000*(settings.interval > 60 ? 60*(settings.interval-60) : settings.interval)*(Math.random()+1)
  49. onTriggered: {
  50. pictureArray.push(pictureDelegate.createObject(column, { y: -2000 }))
  51. if (pictureArray.length > settings.columnCount) {
  52. pictureArray.shift().detonate()
  53. }
  54. }
  55. }
  56. Connections {
  57. target: root
  58. onTogglePause: feedTimer.running = !feedTimer.running
  59. onNext: feedTimer.triggered()
  60. onToggleChaos: fixedRotation = !fixedRotation
  61. }
  62. Timer {
  63. id: initialPopulation
  64. property int runCount: 0
  65. interval: 500
  66. running: runCount < settings.columnCount
  67. repeat: true
  68. onTriggered: {
  69. runCount = runCount + 1;
  70. feedTimer.triggered()
  71. }
  72. }
  73. }
  74. }
  75. Rectangle {
  76. id: scene
  77. focus: true
  78. color: "black"
  79. anchors.fill: parent
  80. RectangleBoxBody {
  81. world: commonWorld
  82. height: 1
  83. anchors {
  84. left: parent.left
  85. right: parent.right
  86. top: parent.bottom
  87. }
  88. friction: 1
  89. density: 1
  90. }
  91. Repeater {
  92. model: settings.columnCount
  93. delegate: columnComponent
  94. }
  95. Keys.onLeftPressed: settings.columnCount = Math.max(settings.columnCount-1,1)
  96. Keys.onRightPressed: settings.columnCount++
  97. Keys.onUpPressed: root.togglePause()
  98. Keys.onDownPressed: root.toggleChaos() //root.next()
  99. // TODO: The boot (Monty Python foot) of death to be applied to the stacks
  100. RectangleBoxBody {
  101. id: rect
  102. enabled: false
  103. visible: false
  104. friction: 1.0
  105. density: 1000
  106. color: "red"
  107. width: 50; height: 50
  108. bullet: true
  109. SequentialAnimation {
  110. id: murderAnimation
  111. //loops: Animation.Infinite
  112. //running: true
  113. ScriptAction { script: { root.togglePause() } }
  114. ScriptAction { script: { rect.world = worldArray.pop() } }
  115. PropertyAction { target: rect; property: "x"; value: -rect.width }
  116. PropertyAction { target: rect; property: "y"; value: scene.height }
  117. ParallelAnimation {
  118. NumberAnimation { target: rect; property: "x"; to: 2560; duration: 1000 }
  119. NumberAnimation { target: rect; property: "y"; to: 0; duration: 1000 }
  120. }
  121. }
  122. }
  123. }
  124. }