main.qml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. }
  15. signal pause
  16. signal next
  17. Component {
  18. id: pictureComponent
  19. ImageBoxBody {
  20. id: picture
  21. function detonate() { destroyAnimation.start() }
  22. //I thought this accepted forcing either width/height
  23. //fillMode: Image.PreserveAspectFit
  24. height: implicitHeight/implicitWidth*width
  25. width: parent.width
  26. density: 0.01
  27. friction: 1.0
  28. fixedRotation: true
  29. world: parent.physicsWorld
  30. bodyType: Body.Dynamic
  31. source: "file://" + imageModel.randomPicture()
  32. //restitution: 0.0
  33. onXChanged: x = 0
  34. SequentialAnimation {
  35. id: destroyAnimation
  36. NumberAnimation { target: picture; property: "height"; to: 0; duration: 1000 }
  37. ScriptAction { script: { picture.destroy(); } }
  38. }
  39. }
  40. }
  41. Component {
  42. id: columnComponent
  43. Item {
  44. id: column
  45. x: width * index
  46. width: parent.width/settings.columnCount
  47. anchors { top: parent.top; bottom: parent.bottom }
  48. property var pictureArray: []
  49. property var physicsWorld: World {
  50. timeStep: 6.0/60.0
  51. }
  52. RectangleBoxBody {
  53. world: physicsWorld
  54. height: 1
  55. anchors {
  56. left: parent.left
  57. right: parent.right
  58. top: parent.bottom
  59. }
  60. friction: 1
  61. density: 1
  62. }
  63. Timer {
  64. id: feedTimer
  65. running: true
  66. repeat: true
  67. interval: 1000*(settings.interval > 60 ? 60*(settings.interval-60) : settings.interval)*(Math.random()+1)
  68. onTriggered: {
  69. pictureArray.push(pictureComponent.createObject(column, { y: -2000 }))
  70. if (pictureArray.length > settings.columnCount) {
  71. pictureArray.shift().detonate()
  72. }
  73. }
  74. }
  75. Connections {
  76. target: root
  77. onPause: feedTimer.running = !feedTimer.running
  78. onNext: feedTimer.triggered()
  79. }
  80. Timer {
  81. id: initialPopulation
  82. property int runCount: 0
  83. interval: 500
  84. running: runCount < settings.columnCount
  85. repeat: true
  86. onTriggered: {
  87. runCount = runCount + 1;
  88. feedTimer.triggered()
  89. }
  90. }
  91. }
  92. }
  93. Rectangle {
  94. focus: true
  95. color: "black"
  96. anchors.fill: parent
  97. Repeater {
  98. model: settings.columnCount
  99. delegate: columnComponent
  100. }
  101. Keys.onLeftPressed: settings.columnCount = Math.max(settings.columnCount-1,1)
  102. Keys.onRightPressed: settings.columnCount++
  103. Keys.onUpPressed: root.pause()
  104. Keys.onDownPressed: root.next()
  105. }
  106. }