Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

R.U.B.E. Editor - Side Scroller

 import QtQuick 2.0
 import Felgo 4.0

 RubeBody {
   id: penguin
   entityType: "penguin"

   // force applied to the body, drives the penguin forward (always) and up (when touched)
   force: Qt.point(60, isMouseDown ? -300 : 0)

   // torque to achieve the target rotation = deltaRotation * factor
   // this is like a proportional controller (see PID controller)
   torque: (targetRotation - rotation) * 60

   // target rotation depends on the vertical velocity
   property real targetRotation: linearVelocity.y / 6

   // current touch state
   property bool isMouseDown: false

   onXChanged: {
     // move "camera" of scene so that the penguin is 1/3 from the left screen border
     scene.level.x = -x + scene.width / 3

     // test until endless scrolling is enabled
     if (x > 3200){
       reset()
     }
   }

   onInitialized: {
     reset()
   }

   onBeginContact: (other, contactNormal) => {
     var entityType = other.getBody().target.entityType;
     if (entityType === "saw"){
       reset()
     }
   }

   Connections {
     target: scene.mouseArea
     function onPressed() {
       penguin.isMouseDown = true
     }
     function onReleased() {
       penguin.isMouseDown = false
     }
   }

   // resets pengiun position to start-position
   function reset(){
     var resetPos = Qt.point(0, 0);

     // only one startPos can exist
     var startPosEntities = entityManager.getEntityArrayByType("startPos")
     if (startPosEntities.length > 0 && startPosEntities[0]) {
       resetPos = Qt.point(startPosEntities[0].x, startPosEntities[0].y)
     }

     x = resetPos.x
     y = resetPos.y
     linearVelocity = Qt.point(0,0)

     rotation = 0
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded