V-Play has a new name, say hi to Felgo!Learn More

Demolition.qml Example File

examples/physics/box2d-examples/qml/demolition/Demolition.qml
 import QtQuick 2.0
 import Felgo 3.0

 GameWindow {
   id: screen

   Image {
     anchors.fill: parent
     source: "images/background.png"
   }

   activeScene: scene

   // A wheel that will be created dynamically
   Component {
     id: wheelComponent

     EntityBase {
       id: wheel

       width: circleCollider.radius * 2
       height: width

       CircleCollider {
         id: circleCollider
         sleepingAllowed: true
         radius: 30
         density: 0.006
         friction: 1.0
         restitution: 0.6

         // torque gets set to positive or negative, depending on if clicked on the left or right side of the world when touching the wheel
       }

       Image {
         id: circleRect

         anchors.fill: parent
         smooth: true

         source: "images/wheel.png"
       }

       MouseArea {
         anchors.fill: circleRect
         onPressed: {
           console.debug("wheel.x when pressed:", wheel.x)

           // if wheel is on the left side of the world, twist it in the other direction
           var impulseStrength = 3000*32 //kg*pixels^2/second
           var impulse = impulseStrength * (wheel.x + wheel.width / 2 < world.width / 2 ? 1 : -1)
           circleCollider.body.applyAngularImpulse(impulse)
         }
       }
     }
   }

   Scene {
     id: scene

     Image {

       id: skyline
       anchors {
         bottom: parent.bottom
         left: parent.left
         right: parent.right
       }

       source: "images/skyline.png"
     }

     EntityManager {
       id: entityManager
       entityContainer: scene
     }

     PhysicsWorld {
       id: world
       width: scene.width
       height: scene.height

       gravity.x: 0
       gravity.y: 9.81

       updatesPerSecondForPhysics: 60

       debugDrawVisible: true
     }

     MouseArea {
       anchors.fill: parent
       onPressAndHold: {
         entityManager.createEntityFromComponentWithProperties(wheelComponent, {x: mouse.x, y: mouse.y})
       }
     }

     Building {
       id: victim

       anchors {
         bottom: ground.top
       }
       x: 100
       floors: 6
       stairways: 3
     }

     Building {
       anchors {
         bottom: ground.top
       }
       x: 400
       floors: 6
       stairways: 3
     }

     Wall {
       id: ceiling

       height: 20
       anchors {
         top: parent.top
         left: parent.left
         right: parent.right
       }
     }

     Wall {
       id: leftWall
       width: 20
       anchors {
         top: parent.top
         bottom: parent.bottom
         left: parent.left
       }
     }

     Wall {
       id: rightWall
       width: 20
       anchors {
         top: parent.top
         bottom: parent.bottom
         right: parent.right
       }
     }

     Wall {
       id: ground

       height: 20
       anchors {
         left: parent.left
         right: parent.right
         bottom: parent.bottom
       }

       //rotation: -1
     }

     Text {
       anchors {
         top: scene.gameWindowAnchorItem.top; topMargin: 20
         left: scene.gameWindowAnchorItem.left; leftMargin: 25
       }

       text: "Press and hold to create a wheel.\nPress and hold on top of the wheel to apply torque into the other half of the scene.\nClick on a box to apply a torque on it."
       color: "white"
       font.pixelSize: 12
     }

   } // end of Scene

   Image {
     anchors {
       top: parent.top; topMargin: 10
       right: parent.right; rightMargin: 20
     }

     fillMode: Image.PreserveAspectFit

     source: "images/plate.png"
     smooth: true

     MouseArea {
       anchors.fill: parent

       scale: 1.4

       Behavior on scale {
         PropertyAnimation { duration: 100 }
       }

       onClicked: Qt.quit()

       onPressed: parent.scale = 0.9
       onReleased: parent.scale = 1.0
     }
   }
 }

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support