Crazy Carousel Game
import QtQuick 2.0
import Felgo 4.0
EntityBase {
id: player
entityType: "player"
width: 65
height: 96
property bool isMoving: false
property string nextMove: ""
property QtObject frontRide: null
MultiResolutionImage {
id: image
width: parent.width
height: parent.height
x: -width / 2
y: -height / 2
source: Qt.resolvedUrl("../../assets/player.png")
}
BoxCollider {
id: boxCollider
width: 25
height: 50
anchors.centerIn: image
collisionTestingOnlyMode: true
}
MovementAnimation {
id: switchMovement
target: player
property: "x"
}
MovementAnimation {
id: jumpMovement
target: player
property: "y"
minPropertyValue: 0
maxPropertyValue: gameScene.playerY
onLimitReached: {
isMoving = false
image.source = Qt.resolvedUrl("../../assets/player.png")
if(nextMove !== "") {
if(nextMove === "right")
moveRight()
else
moveLeft()
}
else {
jumpMovement.stop()
startUpDownMovement()
}
}
}
function moveLeft() {
if(player.x - gameScene.laneWidth < 0)
return
if(!isMoving) {
var distance = gameScene.laneWidth
var multiplier = 1 + (logic.speedUp / 8 * 3)
switchMovement.velocity = -distance * 4.5 * multiplier
switchMovement.minPropertyValue = player.x - distance
switchMovement.maxPropertyValue = gameScene.width
isMoving = true
nextMove=""
upDownMovement.stop()
switchMovement.start()
jump()
}
else {
nextMove = "left"
}
}
function moveRight() {
if(player.x + gameScene.laneWidth > gameScene.width)
return
if(!isMoving) {
var distance = gameScene.laneWidth
var multiplier = 1 + (logic.speedUp / 8 * 3)
switchMovement.velocity = distance * 4.5 * multiplier
switchMovement.minPropertyValue = 0
switchMovement.maxPropertyValue = player.x + distance
isMoving = true
nextMove = ""
upDownMovement.stop()
switchMovement.start()
jump()
}
else {
nextMove = "right"
}
}
function jump() {
if(player.y >= gameScene.playerY)
player.y = gameScene.playerY
var multiplier1 = 0.8 + (logic.speedUp / 8 * 1.0)
var multiplier2 = 1 + (logic.speedUp / 8 * 4)
jumpMovement.velocity = -500 * multiplier1
jumpMovement.acceleration = 2000 * multiplier2
jumpMovement.start()
jumpSound.stop()
jumpSound.play()
image.source = Qt.resolvedUrl("../../assets/player_jump.png")
}
function stopMovement() {
jumpMovement.stop()
switchMovement.stop()
upDownMovement.stop()
isMoving = false
nextMove = ""
}
GameSoundEffect {
id: jumpSound
source: Qt.resolvedUrl("../../assets/sound/Jump.wav")
}
MovementAnimation {
id: upDownMovement
target: player
property: "y"
onLimitReached: {
upDownMovement.velocity = frontRide.velocity
}
}
function startUpDownMovement() {
var laneNr = 0
for(var i = 1; i <= gameScene.lanes; i++) {
var minX = (i - 1) * gameScene.laneWidth
var maxX = i * gameScene.laneWidth
var playerOnRide = player.x < maxX && player.x > minX
if(playerOnRide) {
laneNr = i
break
}
}
switch(laneNr) {
case 1: player.frontRide = gameScene.ride1; break
case 2: player.frontRide = gameScene.ride2; break
case 3: player.frontRide = gameScene.ride3; break
case 4: player.frontRide = gameScene.ride4; break
default: player.frontRide = null
}
if(player.frontRide === null)
player.y = gameScene.playerY
else {
player.y = player.frontRide.y + 3
upDownMovement.stop()
upDownMovement.velocity = frontRide.velocity
upDownMovement.maxPropertyValue = frontRide.maxY + 3
upDownMovement.minPropertyValue = frontRide.minY + 3
upDownMovement.start()