main.qml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import QtQuick 2.5
  2. import QtQuick.Window 2.2
  3. import Box2D 2.0
  4. Window {
  5. id: root
  6. visibility: Window.FullScreen
  7. width: 1024
  8. height: 768
  9. property int columnCount: 4
  10. property int interval: 5
  11. Component {
  12. id: pictureComponent
  13. ImageBoxBody {
  14. id: picture
  15. function detonate() { destroyAnimation.start() }
  16. fillMode: Image.PreserveAspectFit
  17. height: implicitHeight/implicitWidth*width
  18. width: parent.width
  19. density: 0
  20. fixedRotation: true
  21. world: parent.physicsWorld
  22. bodyType: Body.Dynamic
  23. source: "file://" + imageModel.randomPicture()
  24. restitution: 0.0
  25. SequentialAnimation {
  26. id: destroyAnimation
  27. ScriptAction { script: { picture.destroy(); } }
  28. }
  29. }
  30. }
  31. Component {
  32. id: columnComponent
  33. Item {
  34. id: column
  35. x: width * index
  36. width: parent.width/columnCount
  37. anchors { top: parent.top; bottom: parent.bottom }
  38. property var pictureArray: []
  39. property var physicsWorld: World {
  40. timeStep: 0.1
  41. }
  42. RectangleBoxBody {
  43. world: physicsWorld
  44. height: 1
  45. anchors {
  46. left: parent.left
  47. right: parent.right
  48. top: parent.bottom
  49. }
  50. friction: 1
  51. density: 1
  52. }
  53. Timer {
  54. id: feedTimer
  55. running: true
  56. repeat: true
  57. interval: 1000*(root.interval > 60 ? 60*(root.interval-60) : root.interval)
  58. onTriggered: {
  59. pictureArray.push(pictureComponent.createObject(column, { y: -500 }))
  60. if (pictureArray.length > root.columnCount) {
  61. pictureArray.shift().detonate()
  62. }
  63. }
  64. }
  65. Timer {
  66. id: initialPopulation
  67. property int runCount: 0
  68. interval: 500
  69. running: runCount < root.columnCount
  70. repeat: true
  71. onTriggered: {
  72. runCount = runCount + 1;
  73. feedTimer.triggered()
  74. }
  75. }
  76. }
  77. }
  78. Rectangle {
  79. color: "black"
  80. anchors.fill: parent
  81. Repeater {
  82. model: columnCount
  83. delegate: columnComponent
  84. }
  85. }
  86. }