main.qml 2.7 KB

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