main.qml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.01
  20. friction: 1.0
  21. fixedRotation: true
  22. world: parent.physicsWorld
  23. bodyType: Body.Dynamic
  24. source: "file://" + imageModel.randomPicture()
  25. //restitution: 0.0
  26. SequentialAnimation {
  27. id: destroyAnimation
  28. ScriptAction { script: { picture.destroy(); } }
  29. }
  30. }
  31. }
  32. Component {
  33. id: columnComponent
  34. Item {
  35. id: column
  36. x: width * index
  37. width: parent.width/columnCount
  38. anchors { top: parent.top; bottom: parent.bottom }
  39. property var pictureArray: []
  40. property var physicsWorld: World {
  41. timeStep: 6.0/60.0
  42. }
  43. RectangleBoxBody {
  44. world: physicsWorld
  45. height: 1
  46. anchors {
  47. left: parent.left
  48. right: parent.right
  49. top: parent.bottom
  50. }
  51. friction: 1
  52. density: 1
  53. }
  54. Timer {
  55. id: feedTimer
  56. running: true
  57. repeat: true
  58. interval: 1000*(root.interval > 60 ? 60*(root.interval-60) : root.interval)
  59. onTriggered: {
  60. pictureArray.push(pictureComponent.createObject(column, { y: -2000 }))
  61. if (pictureArray.length > root.columnCount) {
  62. pictureArray.shift().detonate()
  63. }
  64. }
  65. }
  66. Timer {
  67. id: initialPopulation
  68. property int runCount: 0
  69. interval: 500
  70. running: runCount < root.columnCount
  71. repeat: true
  72. onTriggered: {
  73. runCount = runCount + 1;
  74. feedTimer.triggered()
  75. }
  76. }
  77. }
  78. }
  79. Rectangle {
  80. color: "black"
  81. anchors.fill: parent
  82. Repeater {
  83. model: columnCount
  84. delegate: columnComponent
  85. }
  86. }
  87. }