Platformer with Level Editor
import QtQuick 2.0
import Felgo 3.0
Opponent {
id: opponentJumper
variationType: "jumper"
property int direction: -1
property int verticalJumpForce: 510
property int horizontalJumpForce: 40
image.source: alive ? "../../assets/opponent/opponent_jumper.png"
: "../../assets/opponent/opponent_jumper_dead.png"
colliderComponent: collider
onAliveChanged: {
if(!alive) {
jumpTimer.stop()
}
}
PolygonCollider {
id: collider
vertices: [
Qt.point(1, 1),
Qt.point(31, 1),
Qt.point(31, 30),
Qt.point(23, 31),
Qt.point(9, 31),
Qt.point(1, 30)
]
bodyType: Body.Dynamic
active: inLevelEditingMode || !alive ? false : true
categories: Box.Category3
collidesWith: Box.Category1 | Box.Category2 | Box.Category5
friction: 1
}
BoxCollider {
id: bottomSensor
width: 30
height: 3
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.bottom
bodyType: Body.Dynamic
active: collider.active
categories: Box.Category4
collidesWith: Box.Category5
collisionTestingOnlyMode: true
fixture.onContactChanged: {
var otherEntity = other.getBody().target
if(collider.linearVelocity.y === 0 && !jumpTimer.running)
jumpTimer.start()
}
}
Timer {
id: jumpTimer
interval: 300
onTriggered: {
collider.applyLinearImpulse(Qt.point(direction * horizontalJumpForce, -verticalJumpForce))
direction *= -1
}
}
EditableComponent {
editableType: "Balance"
defaultGroup: "OpponentJumper"
targetEditor: gameScene.itemEditor
properties: {
"horizontalJumpForce": {"min": 0, "max": 200, "stepSize": 10, "label": "Horizontal Jump"},
"verticalJumpForce": {"min": 0, "max": 800, "stepSize": 10, "label": "Vertical Jump"}
}
}
function reset() {
alive = false
reset_super()
direction = -1
if(jumpTimer.running)
jumpTimer.stop()