R.U.B.E. Editor - Side Scroller
import Felgo 4.0
import QtQuick 2.0
GameWindow {
id: gameWindow
activeScene: scene
screenWidth: 960
screenHeight: 640
Component.onCompleted: {
physicsWorld.running = true
loadLevel()
}
onKeyPressedGlobally: event => {
var camMoveSpeed = 10
if (event.modifiers & Qt.KeypadModifier) {
if (event.key === Qt.Key_4){
level.x += camMoveSpeed
}
if (event.key === Qt.Key_6){
level.x -= camMoveSpeed
}
if (event.key === Qt.Key_8){
level.y += camMoveSpeed
}
if (event.key === Qt.Key_2){
level.y -= camMoveSpeed
}
if (event.key === Qt.Key_Plus){
level.scale /= 0.9
}
if (event.key === Qt.Key_Minus){
level.scale *= 0.9
}
}
}
Scene {
id: scene
width: 480
height: 320
property alias mouseArea: mouseArea
property alias level: level
EntityManager {
id: entityManager
entityContainer: level
}
Item {
id: level
PhysicsWorld {
id: physicsWorld
running: false
z: 10
updatesPerSecondForPhysics: 60
velocityIterations: 5
positionIterations: 5
debugDrawVisible: false
}
}
RubeParser {
id: parser
entitiesFolder: Qt.resolvedUrl("entities/")
}
MouseArea {
id: mouseArea
anchors.fill: scene.gameWindowAnchorItem
}
Row {
spacing: 4
GameButton {
text: "Reload Rube Level"
onClicked: {
console.debug("start loading level")
parser.clearLevel()
loadLevel()
}
}
GameButton {
text: "Unload Rube Level"
onClicked: {
console.debug("start un-loading level")
parser.clearLevel()
}
}
GameButton {
text: "Zoom In"
onClicked: {
level.scale /= 0.9
}
}
GameButton {
text: "Zoom Out"
onClicked: {
level.scale *= 0.9
}
}
}
}
function loadLevel() {
parser.setupLevelFromJSON(Qt.resolvedUrl("../assets/sidescroller.json"), physicsWorld, level)
level.y = scene.height / 2