Crazy Carousel Game
import QtQuick 2.0
import Felgo 4.0
QtObject {
id: logic
property double speedUp: 1.0
property int minBulletTimeout: 1000
property int minCoinTimeout: 2000
property int bulletTimeout: 4000
property int coinTimeout: 2000
function increasePoints() {
gameScene.points++
}
function gameOver() {
gameWindow.state = "gameover"
}
property Timer bulletTimer: Timer {
id: bulletTimer
interval : Math.random() * logic.bulletTimeout + logic.minBulletTimeout
running: gameScene.visible
onTriggered: {
var randomLane = Math.floor(Math.random() * 4 + 1)
var enemyWidth = gameScene.laneWidth * 0.74
var laneOffset = gameScene.width * 0.13
var xPosition = Math.round(laneOffset + (randomLane * enemyWidth) - (enemyWidth / 2))
var xGoal = randomLane * gameScene.laneWidth - (gameScene.laneWidth / 2)
var newEntityProperties = {
x: xPosition,
y: 95,
z: 12,
goalX: xGoal,
startX: xPosition,
startY: 95,
speed: 3000 / (1 + logic.speedUp / 8 * 1.5)
}
entityManager.createEntityFromUrlWithProperties(
Qt.resolvedUrl("Bullet.qml"),
newEntityProperties)
interval = Math.random() * logic.bulletTimeout + logic.minBulletTimeout
bulletTimer.restart()
}
}
property Timer coinTimer: Timer {
id: coinTimer
interval : Math.random() * logic.coinTimeout + logic.minCoinTimeout
running: gameScene.visible
onTriggered: {
var randomLane = Math.floor(Math.random() * 3 + 1)
var enemyWidth = gameScene.laneWidth * 0.74
var laneOffset = gameScene.width * 0.13
var xPosition = Math.round(laneOffset + (randomLane * enemyWidth))
var xGoal = randomLane * gameScene.laneWidth
var newEntityProperties = {
x: xPosition ,
y: 75,
z: 12,
goalX: xGoal,
startX: xPosition,
startY: 75,
speed: 3000 / (1 + logic.speedUp / 8 * 2)
}
entityManager.createEntityFromUrlWithProperties(
Qt.resolvedUrl("Coin.qml"),
newEntityProperties)
interval = Math.random() * logic.coinTimeout + logic.minCoinTimeout
coinTimer.restart()
}
}
property Timer speedUpTimer: Timer {
id: speedUpTimer
interval: 15000
running: gameScene.visible
onTriggered: {
logic.speedUp += 0.7
bulletTimer.stop()
logic.bulletTimeout -= 300
bulletTimer.interval = Math.random() * logic.bulletTimeout +
logic.minBulletTimeout
bulletTimer.restart()
coinTimer.stop()
logic.coinTimeout -= 100
coinTimer.interval = Math.random() * logic.coinTimeout +
logic.minCoinTimeout
coinTimer.restart()
if(logic.speedUp < 8)
speedUpTimer.restart()