Jelajahi Sumber

Fix a slew of oversights

Change-Id: I16a33a445ca592623ea9635a95a43ed90365c169
Donald Carr 9 tahun lalu
induk
melakukan
747b443b6f
2 mengubah file dengan 32 tambahan dan 19 penghapusan
  1. 5 7
      ArtDelegate.qml
  2. 27 12
      Gravity.qml

+ 5 - 7
ArtDelegate.qml

@@ -5,7 +5,11 @@ import Qt.labs.settings 1.0
 ImageBoxBody {
     id: picture
 
-    function detonate() { settings.animateDeath ? destroyAnimation.start() : picture.destroy() }
+    function detonate() {
+        picture.world = bullshitWorld
+    }
+
+    onYChanged: y <= floor.y || picture.destroy()
 
     density: 0.01
     friction: 1.0
@@ -14,10 +18,4 @@ ImageBoxBody {
     bodyType: Body.Dynamic
 
     source: "file://" + imageModel.randomPicture()
-
-    SequentialAnimation {
-        id: destroyAnimation
-        NumberAnimation { target: picture; property: "height"; to: 0; duration: 1000 }
-        ScriptAction { script: { picture.destroy(); } }
-    }
 }

+ 27 - 12
Gravity.qml

@@ -20,6 +20,11 @@ Item {
         property int itemCount: 0
     }
 
+    World {
+        id: bullshitWorld
+        timeStep: d.pace
+    }
+
     World {
         // Global world at odds with relative positions!
         id: commonWorld
@@ -67,12 +72,21 @@ Item {
                 repeat: true
                 interval: 1000*(settings.interval > 60 ? 60*(settings.interval-60) : settings.interval)*(Math.random()+1)
                 onTriggered: {
-                    d.itemCount++
-                    pictureArray.push(pictureDelegate.createObject(column, { y: -2000 }))
-                    if (pictureArray.length > settings.columnCount) {
+                    if (pictureArray.length > 0) {
                         pictureArray.shift().detonate()
                         d.itemCount--
                     }
+
+                    var colHeight = 0
+                    pictureArray.forEach(function (picture) { colHeight += picture.height; })
+
+                    do {
+                        var item = pictureDelegate.createObject(column)
+                        item.y = -colHeight - item.height
+                        d.itemCount++
+                        pictureArray.push(item)
+                        colHeight += item.height
+                    } while (colHeight < root.height)
                 }
             }
 
@@ -84,22 +98,19 @@ Item {
             }
 
             Timer {
-                id: initialPopulation
-
-                property int runCount: 0
+                id: settleTimer
+                running: false
                 interval: 500
-                running: runCount < settings.columnCount
-                repeat: true
-                onTriggered: {
-                    runCount = runCount + 1;
-                    feedTimer.triggered()
-                }
+                onTriggered: feedTimer.triggered()
             }
+
+            Component.onCompleted: settleTimer.start()
         }
     }
 
     // floor
     RectangleBoxBody {
+        id: floor
         world: commonWorld
         height: 1
         anchors {
@@ -116,6 +127,10 @@ Item {
         delegate: columnComponent
     }
 
+    Connections {
+        target: settings
+        onColumnCountChanged: d.itemCount = 0
+    }
 
     // TODO: The boot (Monty Python foot) of death to be applied to the stacks
     RectangleBoxBody {