main.qml 4.7 KB

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