Platformer with Level Editor
import QtQuick 2.0
import Felgo 3.0
Opponent {
id: opponentJumper
variationType: "walker"
property int direction: -1
property int speed: 70
image.source: alive ? "../../assets/opponent/opponent_walker.png"
: "../../assets/opponent/opponent_walker_dead.png"
image.mirror: collider.linearVelocity.x < 0 ? false : true
colliderComponent: collider
onAliveChanged: {
if(!alive) {
leftAbyssChecker.contacts = 0
rightAbyssChecker.contacts = 0
}
}
onMovedToPool: {
leftAbyssChecker.contacts = 0
rightAbyssChecker.contacts = 0
}
PolygonCollider {
id: collider
vertices: [
Qt.point(1, 15),
Qt.point(31, 15),
Qt.point(31, 30),
Qt.point(26, 31),
Qt.point(6, 31),
Qt.point(1, 30)
]
bodyType: Body.Dynamic
active: inLevelEditingMode || !alive ? false : true
categories: Box.Category3
collidesWith: Box.Category1 | Box.Category2 | Box.Category5
linearVelocity: Qt.point(direction * speed, 0)
onLinearVelocityChanged: {
if(linearVelocity.x === 0)
direction *= -1
linearVelocity.x = direction * speed
}
}
BoxCollider {
id: leftAbyssChecker
active: collider.active
width: 5
height: 5
anchors.top: parent.bottom
anchors.left: parent.left
categories: Box.Category4
collidesWith: Box.Category5
collisionTestingOnlyMode: true
property int contacts: 0
fixture.onBeginContact: contacts++
fixture.onEndContact: if(contacts > 0) contacts--
onContactsChanged: if(contacts == 0) direction *= -1
}
BoxCollider {
id: rightAbyssChecker
active: collider.active
width: 5
height: 5
anchors.top: parent.bottom
anchors.right: parent.right
categories: Box.Category4
collidesWith: Box.Category5
collisionTestingOnlyMode: true
property int contacts: 0
fixture.onBeginContact: contacts++
fixture.onEndContact: if(contacts > 0) contacts--
onContactsChanged: if(contacts == 0) direction *= -1
}
EditableComponent {
editableType: "Balance"
defaultGroup: "OpponentWalker"
targetEditor: gameScene.itemEditor
properties: {
"speed": {"min": 0, "max": 300, "stepSize": 5, "label": "Speed"}
}
}
onSpeedChanged: {
collider.linearVelocity.x = direction * speed
}
function reset() {
reset_super()
direction = -1