main.qml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. ScriptAction { script: { picture.destroy(); } }
  37. }
  38. }
  39. }
  40. Component {
  41. id: columnComponent
  42. Item {
  43. id: column
  44. x: width * index
  45. width: parent.width/settings.columnCount
  46. anchors { top: parent.top; bottom: parent.bottom }
  47. property var pictureArray: []
  48. property var physicsWorld: World {
  49. timeStep: 6.0/60.0
  50. }
  51. RectangleBoxBody {
  52. world: physicsWorld
  53. height: 1
  54. anchors {
  55. left: parent.left
  56. right: parent.right
  57. top: parent.bottom
  58. }
  59. friction: 1
  60. density: 1
  61. }
  62. Timer {
  63. id: feedTimer
  64. running: true
  65. repeat: true
  66. interval: 1000*(settings.interval > 60 ? 60*(settings.interval-60) : settings.interval)*(Math.random()+1)
  67. onTriggered: {
  68. pictureArray.push(pictureComponent.createObject(column, { y: -2000 }))
  69. if (pictureArray.length > settings.columnCount) {
  70. pictureArray.shift().detonate()
  71. }
  72. }
  73. }
  74. Connections {
  75. target: root
  76. onPause: feedTimer.running = !feedTimer.running
  77. onNext: feedTimer.triggered()
  78. }
  79. Timer {
  80. id: initialPopulation
  81. property int runCount: 0
  82. interval: 500
  83. running: runCount < settings.columnCount
  84. repeat: true
  85. onTriggered: {
  86. runCount = runCount + 1;
  87. feedTimer.triggered()
  88. }
  89. }
  90. }
  91. }
  92. Rectangle {
  93. focus: true
  94. color: "black"
  95. anchors.fill: parent
  96. Repeater {
  97. model: settings.columnCount
  98. delegate: columnComponent
  99. }
  100. Keys.onLeftPressed: settings.columnCount = Math.max(settings.columnCount-1,1)
  101. Keys.onRightPressed: settings.columnCount++
  102. Keys.onUpPressed: root.pause()
  103. Keys.onDownPressed: root.next()
  104. }
  105. }