123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- import QtQuick 2.5
- import Box2D 2.0
- import Qt.labs.settings 1.0
- import "../effects"
- Item {
- id: root
- signal togglePause
- signal toggleChaos
- signal next
- property var pictureDelegate: Qt.createComponent("HorizontalArtDelegate.qml")
- property var effectDelegate: Qt.createComponent("../VisualEffect.qml")
- anchors.fill: parent
- Settings {
- id: physicsSettings
- category: "Physics"
- property int itemTravel: 0
- property real pace: 1
- property bool globalWorld: false
- // Very computationally heavy: 40% vs 20% for 0.1 vs 0
- property real restitution: 0
- }
- QtObject {
- id: d
- property real pace: physicsSettings.pace/60.0
- property int itemCount: 0
- property int itemTravel: physicsSettings.itemTravel
- property int primedColumns: 0
- property int columnCount: generalSettings.columnCount
- property bool running: primedColumns >= columnCount
- property bool globalWorld: physicsSettings.globalWorld
- property string effect: generalSettings.effect
- function reset() {
- itemCount = 0
- primedColumns = 0
- }
- onColumnCountChanged: reset()
- }
- World {
- id: world
- timeStep: d.pace
- running: d.globalWorld && d.running
- property var limbo: World {
- timeStep: world.timeStep
- running: world.running
- }
- }
- Component {
- id: columnComponent
- Item {
- id: column
- property int stackHeight: 0
- property bool full: false
- property int xOffset: width * index
- onStackHeightChanged: {
- if (!column.full && (stackHeight > root.height)) {
- d.primedColumns += 1
- column.full = true
- }
- }
- function considerImage() {
- if (stackHeight < (1.3 + 1/d.columnCount)*root.height) {
- addImage()
- }
- }
- function addImage() {
- var image = pictureDelegate.createObject(column, { x: -1000, y: -1000 })
- if (d.effect !== "" && Effects.validate(d.effect)) {
- image.effect = effectDelegate.createObject(column, { target: image, effect: d.effect })
- }
- image.beyondThePale.connect(removeImage)
- image.world = d.globalWorld ? world : isolatedWorld
- image.x = xOffset
- stackHeight += (image.height + d.itemTravel)
- image.y = floor.y - stackHeight
- pictureArray.push(image)
- d.itemCount++
- }
- function removeImage(image) {
- if (image.effect) {
- image.effect.destroy()
- }
- stackHeight -= (image.height + d.itemTravel)
- image.destroy()
- d.itemCount--
- }
- function shiftImageToLimbo() {
- if (pictureArray.length > 0) {
- var image = pictureArray.shift()
- image.world = image.world.limbo
- addImage()
- }
- }
- width: parent.width/d.columnCount
- anchors { top: parent.top; bottom: parent.bottom }
- property var pictureArray: []
- property bool fixedRotation: true
- World {
- id: isolatedWorld
- timeStep: d.pace
- running: !d.globalWorld && d.running
- property var limbo: World {
- timeStep: isolatedWorld.timeStep
- running: isolatedWorld.running
- }
- }
- RectangleBoxBody {
- id: floor
- world: isolatedWorld
- height: 0
- width: parent.width
- x: xOffset
- anchors {
- top: parent.bottom
- }
- friction: 1
- }
- Timer {
- id: pumpTimer
- interval: Math.random()*500 + 500
- repeat: true
- running: true
- onTriggered: considerImage()
- }
- Timer {
- id: deathTimer
- running: d.running
- repeat: true
- interval: 1000*(generalSettings.interval > 60 ? 60*(generalSettings.interval-60) : generalSettings.interval)*(Math.random()+1)
- onTriggered: shiftImageToLimbo()
- }
- Connections {
- target: root
- onTogglePause: deathTimer.running = !deathTimer.running
- onNext: deathTimer.triggered()
- onToggleChaos: fixedRotation = !fixedRotation
- }
- Timer {
- id: settleTimer
- running: false
- interval: 200
- onTriggered: deathTimer.triggered()
- }
- }
- }
- // floor
- RectangleBoxBody {
- id: globalFloor
- world: world
- height: 0
- anchors {
- left: parent.left
- right: parent.right
- top: parent.bottom
- }
- friction: 1
- }
- DebugDraw {
- id: debugDraw
- enabled: false
- z: 1
- world: world
- anchors.fill: parent
- opacity: 0.75
- visible: enabled
- }
- Repeater {
- model: d.columnCount
- delegate: columnComponent
- }
- // TODO: The boot (Monty Python foot) of death to be applied to the stacks
- RectangleBoxBody {
- id: rect
- enabled: false
- visible: false
- friction: 1.0
- density: 1000
- color: "red"
- width: 50; height: 50
- bullet: true
- SequentialAnimation {
- id: murderAnimation
- //loops: Animation.Infinite
- //running: true
- ScriptAction { script: { root.togglePause() } }
- ScriptAction { script: { rect.world = worldArray.pop() } }
- PropertyAction { target: rect; property: "x"; value: -rect.width }
- PropertyAction { target: rect; property: "y"; value: root.height }
- ParallelAnimation {
- NumberAnimation { target: rect; property: "x"; to: 2560; duration: 1000 }
- NumberAnimation { target: rect; property: "y"; to: 0; duration: 1000 }
- }
- }
- }
- Rectangle {
- visible: generalSettings.viewItemCount
- z: 1
- color: "black"
- anchors { right: parent.right; top: parent.top }
- width: itemCountLabel.width
- height: itemCountLabel.height
- Text {
- id: itemCountLabel
- font.pixelSize: 100
- text: d.itemCount
- color: "white"
- }
- }
- Keys.onUpPressed: root.togglePause()
- Keys.onDownPressed: root.toggleChaos() //root.next()
- Component.onCompleted: {
- pictureDelegate.status !== Component.Ready && console.log('Component failed with:' + pictureDelegate.errorString())
- effectDelegate.status !== Component.Ready && console.log('Component failed with:' + effectDelegate.errorString())
- }
- }
|