R.U.B.E. Editor - Side Scroller
import QtQuick 2.0
import Felgo 4.0
RubeBody {
id: penguin
entityType: "penguin"
force: Qt.point(60, isMouseDown ? -300 : 0)
torque: (targetRotation - rotation) * 60
property real targetRotation: linearVelocity.y / 6
property bool isMouseDown: false
onXChanged: {
scene.level.x = -x + scene.width / 3
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
}
}
function reset(){
var resetPos = Qt.point(0, 0);
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