Crazy Carousel Game
import Felgo 4.0
import QtQuick 2.0
import "../common"
import "../entities"
SceneBase {
id:gameScene
width: 320
height: 480
BackgroundImage {
anchors.centerIn: gameScene.gameWindowAnchorItem
source: Qt.resolvedUrl("../../assets/CarouselBackground.jpg")
}
BackgroundMusic {
id: backgroundMusic
source: Qt.resolvedUrl("../../assets/sound/Carousel.mp3")
}
property int lanes: 4
property double laneWidth: gameScene.width / gameScene.lanes
property int startLane: 0
property double playerY: 400
property alias logic: logic
property alias ride1: horse
property alias ride2: boat
property alias ride3: bike
property alias ride4: car
property int points: 0
Logic {
id: logic
}
function startNewGame() {
gameScene.points = 0
gameScene.logic.speedUp = 1.0
gameScene.logic.bulletTimeout = 4000
gameScene.logic.coinTimeout = 2000
player.stopMovement()
gameScene.startLane = Math.random() * gameScene.lanes + 1
player.x = (gameScene.startLane * gameScene.laneWidth) - (gameScene.laneWidth / 2)
player.startUpDownMovement()
}
PhysicsWorld {
gravity.y: 0
z: 5
updatesPerSecondForPhysics: 60
velocityIterations: 5
positionIterations: 5
debugDrawVisible: false
}
Text {
text: gameScene.points
color: "#e52222"
y: 36
z: 1
font.pixelSize: 12
font.family: "Arial"
font.weight: Font.Bold
width: gameScene.width
horizontalAlignment: Text.AlignHCenter
}
Player {
id: player
z: 10
x: (gameScene.startLane * gameScene.laneWidth) - (gameScene.laneWidth / 2)
y: gameScene.playerY
}
RideFront {
id: horse
x: -20; y: 397
minY: 397 - (Math.random() * 10 + 5); maxY: 397 + Math.random() * 10 + 5
width: 92.5; height: 128
image.source: Qt.resolvedUrl("../../assets/ride1_f.png")
}
RideBack {
frontRide: horse
image.source: Qt.resolvedUrl("../../assets/ride1_b.png")
}
RideFront {
id: boat
x: 73.5; y: 397
minY: 397 - (Math.random() * 10 + 5); maxY: 397 + Math.random() * 10 + 5
width: 94.5; height: 128
image.source: Qt.resolvedUrl("../../assets/ride2_f.png")
}
RideBack {
frontRide: boat
image.source: Qt.resolvedUrl("../../assets/ride2_b.png")
}
RideFront {
id: bike
x: 167; y: 397
minY: 397 - (Math.random() * 10 + 5); maxY: 397 + Math.random() * 10 + 5
width: 67.5; height: 128
image.source: Qt.resolvedUrl("../../assets/ride3_f.png")
}
RideBack {
frontRide: bike
image.source: Qt.resolvedUrl("../../assets/ride3_b.png")
}
RideFront {
id: car
x: 234.5; y: 397
minY: 397 - (Math.random() * 10 + 5); maxY: 397 + Math.random() * 10 + 5
width: 105.5; height: 128
image.source: Qt.resolvedUrl("../../assets/ride4_f.png")
}
RideBack {
frontRide: car
image.source: Qt.resolvedUrl("../../assets/ride4_b.png")
}
Enemies { id: enemies; y: 61 }
Floor {
z: 100
anchors.bottom: gameScene.gameWindowAnchorItem.bottom
}
MouseArea {
anchors.fill: gameScene.gameWindowAnchorItem
property bool touch: false
property int firstX: 0
onPressed: {
if(touch == false)
firstX = mouseX
touch = true
}
onReleased: {
if(touch == true)
checkSwipe(15)
touch = false
}
onPositionChanged: {
if(touch)
checkSwipe(50)
}
function checkSwipe(minDistance) {
var distance = mouseX - firstX
if(Math.abs(distance) > minDistance) {
if(distance > 0)
player.moveRight()
else
player.moveLeft()
touch = false
}
}