Warning, /education/gcompris/external/qml-box2d/examples/prismatic/prismatic.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 Item {
0006     id: screen
0007     width: 800
0008     height: 600
0009     focus: true
0010 
0011     // A heavy ball that will be created dynamically with the timer below
0012     Component {
0013         id: heavyBall
0014         Rectangle {
0015             id: rectangle
0016             radius: width / 2
0017             width: 80
0018             height: 80
0019             smooth: true
0020             color: "black"
0021 
0022             CircleBody {
0023                 target: rectangle
0024                 world: physicsWorld
0025                 bodyType: Body.Dynamic
0026                 radius: 40
0027                 density: 5
0028                 friction: 0.3
0029                 restitution: 0.2
0030             }
0031         }
0032     }
0033 
0034     // Timer that keeps creating heavy balls that crash down on the building
0035     Timer {
0036         running: true
0037         repeat: true
0038         interval: 1000
0039         onTriggered: {
0040             var ball = heavyBall.createObject(screen)
0041             ball.x =  Math.random() * screen.width
0042             ball.y = -100
0043         }
0044     }
0045 
0046     // BOX2D WORLD
0047     World { id: physicsWorld; }
0048 
0049     PhysicsItem {
0050         id: ground
0051         height: 20
0052         anchors { left: parent.left; right: parent.right; top: parent.bottom }
0053         fixtures: Box {
0054             height: ground.height
0055             width: ground.width
0056         }
0057     }
0058 
0059 
0060     Square {
0061         id: square
0062         x: 100
0063         y: 200
0064         rotation: 0
0065         width: 200
0066         height: 80
0067 
0068         MouseArea {
0069             anchors.fill: parent
0070             onClicked: {
0071                 prismatic.motorSpeed *= -1
0072             }
0073         }
0074     }
0075 
0076     PhysicsItem {
0077         id: middle
0078         anchors.centerIn: parent
0079     }
0080 
0081     PrismaticJoint {
0082         id: prismatic
0083         lowerTranslation: -250
0084         upperTranslation: 250
0085         enableLimit: true
0086         maxMotorForce: 3000
0087         motorSpeed: -100
0088         enableMotor: true
0089         bodyB: square.body
0090         bodyA: middle.body
0091         localAxisA: Qt.point(100, 40)
0092     }
0093 
0094     // Debug
0095     DebugDraw {
0096         id: debugDraw
0097         world: physicsWorld
0098         opacity: 0.75
0099         visible: false
0100     }
0101 }