CarChallenge 3D Demo
import QtQuick 2.0
import Felgo 3.0
import Qt3D.Core 2.0 as Qt3D
import "hud"
GameWindow {
id: window
screenWidth: 960
screenHeight: 640
color: "black"
activeScene: scene
EntityManager {
id: entityManager
entityContainer: level
}
property alias rootEntity: scene3D.rootEntity
property alias itemEditor: ingameMenu.itemEditor
property alias player: level.player_red
property alias fullscreen2DModeEnabled: ingameSettings.fullscreen2DModeEnabled
Item {
id: ingameSettings
property bool physicsDebugVisible: false
property bool fullscreen2DModeEnabled: false
property real cameraDistanceHorizontal: -120
property real cameraDistanceVertical: -40
EditableComponent {
editableType: "CamType"
properties: {
"Camera": {
"cameraDistanceHorizontal": {"min": -500, "max": -10},
"cameraDistanceVertical": {"min": -500, "max": -10},
"physicsDebugVisible": {},
"fullscreen2DModeEnabled": {},
}
}
}
}
TargetCamTransformHelper {
id: cameraTransformHelper
player: window.player
cameraDistanceHorizontal: ingameSettings.cameraDistanceHorizontal
cameraDistanceVertical: ingameSettings.cameraDistanceVertical
}
Scene3D {
id: scene3D
anchors.fill: parent
visible: !fullscreen2DModeEnabled
cameraFarPlane: -2000
skyboxCameraRotationAngle: 270
skyboxCameraRotationAxis: Qt.vector3d(1,0,0)
skyboxBaseName: Qt.resolvedUrl("../assets/3d/cubemaps/mountains/mountains")
skyboxExtension: ".bmp"
cameraViewCenter: Qt.vector3d( -player.x , -player.y , 0)
cameraPosition: Qt.vector3d( cameraTransformHelper.targetX, cameraTransformHelper.targetY, cameraTransformHelper.targetZ)
cameraUpVector: Qt.vector3d(0,0,-1)
isControlledCamera: false
}
Scene {
id: scene
width: 640
height: 640
opacity: 0.5
z: 1
sceneAlignmentX: fullscreen2DModeEnabled ? "center" : "left"
sceneAlignmentY: fullscreen2DModeEnabled ? "center" : "top"
Level {
id: level
scale: fullscreen2DModeEnabled ? 1 : 0.4
transformOrigin: Item.TopLeft
}
focus: true
Keys.forwardTo: [level.player_red.controller, level.player_blue.controller]
Keys.onPressed: {
if(event.key === Qt.Key_Minus) {
scene3D.positionZ -= 10
} else if(event.key === Qt.Key_Plus) {
scene3D.positionZ += 10
} else if(event.key === Qt.Key_PageDown) {
ingameSettings.cameraDistanceVertical += 10
} else if(event.key === Qt.Key_PageUp) {
ingameSettings.cameraDistanceVertical -= 10
}
}
}
Scene {
id: hud
z: 3
MouseArea {
anchors.fill: hud.gameWindowAnchorItem
onWheel: {
var yDelta = wheel.angleDelta.y
cameraTransformHelper.cameraDistanceHorizontal += yDelta*0.1
}
onClicked: {
if(system.desktopPlatform)
return
player.handleInputAction("fire")
}
}
JoystickControllerHUD {
visible: ingameMenu.state === "game"
anchors.bottom: parent.bottom
joystickRadius: hud.dp(90)
source: "../assets/img/joystick_background.png"
thumbSource: "../assets/img/joystick_thumb.png"
property variant playerTwoxisController: level.player_red.getComponent("TwoAxisController")
onControllerXPositionChanged: playerTwoxisController.xAxis = controllerXPosition;
onControllerYPositionChanged: playerTwoxisController.yAxis = controllerYPosition;
}
IngameMenu {
id: ingameMenu
anchors.fill: hud.gameWindowAnchorItem
miniMapOn: scene.z === 1
onMiniMapOnChanged: {
if(miniMapOn)
scene.z = 1
else
scene.z = -1
}
}