Gravity.qml 4.0 KB

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