Warning, /education/gcompris/external/qml-box2d/examples/demolition/demolition.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.0
0002 import Box2D 2.0
0003 import "../shared"
0004 
0005 Image {
0006     id: screen;
0007     width: 640; height: 360
0008     source: "images/background.png"
0009     Image {
0010         id: skyline
0011         anchors {
0012             bottom: parent.bottom
0013             left: parent.left
0014             right: parent.right
0015         }
0016 
0017         source: "images/skyline.png"
0018     }
0019 
0020     // A wheel that will be created dynamically
0021     Component {
0022         id: wheelComponent
0023         Image {
0024             id: wheel
0025 
0026             smooth: true
0027             source: "images/wheel.png"
0028 
0029             CircleBody {
0030                 id: wheelBody
0031 
0032                 world: physicsWorld
0033                 target: wheel
0034                 bodyType: Body.Dynamic
0035 
0036                 density: 6
0037                 friction: 1.0
0038                 restitution: 0.6
0039 
0040                 radius: wheel.width / 2
0041             }
0042 
0043             MouseArea {
0044                 anchors.fill: parent
0045                 onReleased: timer.running = false
0046                 onPressed: {
0047                     if(wheel.x < (physicsRoot.width / 2)) {
0048                         timer.clockwise = true
0049                     }
0050                     else {
0051                         timer.clockwise = false
0052                     }
0053 
0054                     timer.running = true
0055                 }
0056 
0057                 Timer {
0058                     id: timer
0059                     property bool clockwise
0060                     interval: 100
0061                     repeat: true
0062                     onTriggered: {
0063                         if(clockwise) {
0064                             wheelBody.applyTorque(-3000)
0065                         }
0066                         else {
0067                             wheelBody.applyTorque(3000)
0068                         }
0069                     }
0070                 }
0071             }
0072         }
0073     }
0074 
0075     Text {
0076         anchors {
0077             top: parent.top; topMargin: 20
0078             left: parent.left; leftMargin: 25
0079         }
0080 
0081         text: "Press and hold to create a wheel.\nPress and hold on top of the wheel to apply torque."
0082         color: "white"
0083         font.pixelSize: 12
0084     }
0085 
0086     Flickable {
0087         anchors.fill: parent
0088 
0089         // Try to double the contentWidth..
0090         contentWidth: physicsRoot.width // * 2
0091         contentHeight: physicsRoot.height
0092 
0093         World { id: physicsWorld }
0094 
0095         Item {
0096             id: physicsRoot
0097             width: screen.width
0098             height: screen.height
0099 
0100             MouseArea {
0101                 anchors.fill: parent
0102                 onPressAndHold: {
0103                     var wheel = wheelComponent.createObject(physicsRoot)
0104                     wheel.x = mouse.x - wheel.width / 2
0105                     wheel.y = mouse.y - wheel.height / 2
0106                 }
0107             }
0108 
0109             Building {
0110                 id: victim
0111                 anchors {
0112                     bottom: ground.top
0113                 }
0114                 x: 100
0115                 floors: 6
0116                 stairways: 3
0117             }
0118 
0119             Building {
0120                 anchors {
0121                     bottom: ground.top
0122                 }
0123                 x: 400
0124                 floors: 6
0125                 stairways: 3
0126             }
0127 
0128             Wall {
0129                 id: ceiling
0130                 height: 20
0131                 anchors {
0132                     top: parent.top
0133                     left: parent.left
0134                     right: parent.right
0135                 }
0136             }
0137 
0138             Wall {
0139                 id: leftWall
0140                 width: 20
0141                 anchors {
0142                     top: parent.top
0143                     bottom: parent.bottom
0144                     left: parent.left
0145                 }
0146             }
0147 
0148             Wall {
0149                 id: rightWall
0150                 width: 20
0151                 anchors {
0152                     top: parent.top
0153                     bottom: parent.bottom
0154                     right: parent.right
0155                 }
0156             }
0157 
0158             Wall {
0159                 id: ground
0160                 height: 20
0161                 anchors {
0162                     left: parent.left
0163                     right: parent.right
0164                     bottom: parent.bottom
0165                 }
0166             }
0167 
0168             Wall {
0169                 id: exitWall
0170                 width: 85
0171                 height: 20
0172                 anchors {
0173                     top: ceiling.bottom
0174                     right: rightWall.left
0175                 }
0176             }
0177         }
0178 
0179         DebugDraw {
0180             id: debugDraw
0181             anchors.fill: physicsRoot
0182             world: world
0183             opacity: 0.75
0184             visible: false
0185         }
0186     }
0187 
0188 
0189     Image {
0190         anchors {
0191             top: parent.top; topMargin: 10
0192             right: parent.right; rightMargin: 20
0193         }
0194 
0195         fillMode: Image.PreserveAspectFit
0196         source: "images/plate.png"
0197         smooth: true
0198         Behavior on scale {
0199             PropertyAnimation { easing.type: Easing.OutCubic; duration: 100; }
0200         }
0201         MouseArea {
0202             anchors.fill: parent
0203             scale: 1.4
0204             onClicked: Qt.quit()
0205             onPressed: parent.scale = 0.9
0206             onReleased: parent.scale = 1.0
0207         }
0208     }
0209 }