ChickenOutbreak2 Demo
import QtQuick 2.0
import Felgo 4.0
import "entities"
import "scripts/levelLogic.js" as LevelLogic
Item {
id: level
width: scene.width
state: "stopped"
property alias movementAnimation: levelMovementAnimation
property real gridSize: scene.gridSize
property int roostColumns: width/gridSize
property real lastY: 0
property real currentRow: 0
property alias player: player
property real levelMovementSpeedMinimum: 20
property real levelMovementSpeedMaximum: getLevelMovementSpeedMaximum()
function getLevelMovementSpeedMaximum() {
switch(difficulty) {
case 0: return diff0MaxSpeed
case 1: return diff1MaxSpeed
case 2: return diff2MaxSpeed
case 3: return diff3MaxSpeed
case 4: return diff4MaxSpeed
case 5: return diff5MaxSpeed
case 6: return diff6MaxSpeed
}
}
onLevelMovementSpeedMaximumChanged: console.debug("levelMovementSpeedMaximum changed to " + levelMovementSpeedMaximum)
property real currentLevelMovementSpeed
property int levelMovementDurationTillMaximum: 15
property real platformCreationProbability: getPlatformCreationProbability()
function getPlatformCreationProbability() {
switch(difficulty) {
case 0: return diff0PlatformCreation
case 1: return diff1PlatformCreation
case 2: return diff2PlatformCreation
case 3: return diff3PlatformCreation
case 4: return diff4PlatformCreation
case 5: return diff5PlatformCreation
case 6: return diff6PlatformCreation
}
}
onPlatformCreationProbabilityChanged: console.debug("platformCreationProbability changed to " + platformCreationProbability)
property real platformRotationProbability: getPlatformRotationProbability()
function getPlatformRotationProbability(){
switch(difficulty) {
case 0: return diff0PlatformRot
case 1: return diff1PlatformRot
case 2: return diff2PlatformRot
case 3: return diff3PlatformRot
case 4: return diff4PlatformRot
case 5: return diff5PlatformRot
case 6: return diff6PlatformRot
}
}
onPlatformRotationProbabilityChanged: console.debug("platformRotationProbability changed to " + platformRotationProbability)
property int gravity: getGravity()
function getGravity(){
switch(difficulty) {
case 0: return diff0Gravity
case 1: return diff1Gravity
case 2: return diff2Gravity
case 3: return diff3Gravity
case 4: return diff4Gravity
case 5: return diff5Gravity
case 6: return diff6Gravity
}
}
onGravityChanged: console.debug("gravity changed to " + gravity)
property real wheelCreationProbability: 0.007
property real minimumWheelHeightDifference: 100
property int lastWheelY: 0
property real coinCreationPropability: 0.4
property real badCoinCreationPropability: 0.15
property real trippleCoinCreationPropability: 0.2
property real parachuteCreationPropability: 0.013
property real doublePointsCreationPropability: 0.05
property real windowCreationProbability: 0.10
property real minimumWindowHeightDifference: 300
property bool noDeath: false
property bool noFont: false
property bool noManualGC: true
property bool useScheduling: false
property bool background: true
onUseSchedulingChanged: {
if(useScheduling) {
vplayScheduler.schedulingMethod = VPlayScheduler.Accumulated
} else {
vplayScheduler.schedulingMethod = VPlayScheduler.None
}
}
onBackgroundChanged: {
levelBackground.visible = background
levelBackground.running = levelMovementAnimation.running
}
EditableComponent {
editableType: "chickenData"
properties: {
"Level" : {
"levelMovementSpeedMinimum": {"min": 0, "max": 1000, "label": "Min"},
"levelMovementSpeedMaximum": {"min": 0, "max": 1000, "label": "Max"},
"levelMovementDurationTillMaximum": {"min": 0, "max": 200, "label": "Speedup"},
"noDeath": {"min": 0, "max": 1, "label": "No Death"},
"platformCreationProbability": {"min": 0, "max": 1.0, "stepsize": 0.01, "label": "Platforms"},
"coinCreationPropability": {"min": 0, "max": 1.0, "stepsize": 0.01, "label": "Coins"},
"windowCreationProbability": {"min": 0, "max": 1.0, "stepsize": 0.01, "label": "Window"},
"wheelCreationProbability": {"min": 0, "max": 1.0, "stepsize": 0.01, "label": "Wheel"},
},
"Performance": {
"noFont": {"min": 0, "max": 1, "label": "No Font"},
"noManualGC": {"min": 0, "max": 1, "label": "No GC"},
"useScheduling": {"min": 0, "max": 1, "label": "Scheduling"},
"background": {"min": 0, "max": 1, "label": "Background"},
}
}
}
property int rowCount: 15
property int currentScore: 0
property int bonusScoreForCoin: 50
property int doublePointsDuration: 10
property real rightValue: 250
property real leftValue: -rightValue
property real henLinearDamping : 5.0
property real henFriction : 0.2
property real parachuteGravityScale : 0.10
property real accelerometerOffset : 0.25
property real accelerometerMultiplier : 0.5
property int lastWindowY: 0
property int difficulty : 0
onDifficultyChanged: {
if(difficulty != 0) {
newLevelMessage.newLevelReached()
}
}
property bool balancingMode : itemEditor.visible
property real __yOffsetForWindow: scene.fullWindowAnchorItem.y
signal gameLost
property int diff0MaxSpeed: 110
property real diff0PlatformRot: 0
property real diff0PlatformCreation: 0.09
property real diff0Gravity: 60
property int diff1MaxSpeed: 125
property real diff1PlatformRot: 0.2
property real diff1PlatformCreation: 0.09
property int diff1Points: 1000
property real diff1Gravity: 60
property int diff2MaxSpeed: 140
property real diff2PlatformRot: 0.3
property real diff2PlatformCreation: 0.09
property int diff2Points: 2000
property real diff2Gravity: 60
property int diff3MaxSpeed: 160
property real diff3PlatformRot: 0.45
property real diff3PlatformCreation: 0.08
property int diff3Points: 3000
property real diff3Gravity: 60
property int diff4MaxSpeed: 180
property real diff4PlatformRot: 0.6
property real diff4PlatformCreation: 0.06
property int diff4Points: 4000
property real diff4Gravity: 65
property int diff5MaxSpeed: 200
property real diff5PlatformRot: 1
property real diff5PlatformCreation: 0.05
property int diff5Points: 5000
property real diff5Gravity: 70
property int diff6MaxSpeed: 230
property real diff6PlatformRot: 1
property real diff6PlatformCreation: 0.04
property int diff6Points: 6000
property real diff6Gravity: 75
property real scoreFromItemEditor: 0
EditableComponent {
editableType: "Level"
properties: {
"Collectibles": {
"coinCreationPropability": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Coin"},
"badCoinCreationPropability": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Bad Coin"},
"trippleCoinCreationPropability": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Tripple Coin"},
"parachuteCreationPropability": {"min": 0, "max": 0.5, "stepsize": 0.001, "label": "Parachute"},
"doublePointsCreationPropability": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Double Points"}
},
"Terrain": {
"wheelCreationProbability": {"min": 0, "max": 0.5, "stepsize": 0.001, "label": "Wheel creation"},
"windowCreationProbability": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Window creation"},
"minimumWindowHeightDifference": {"min": 0, "max": 500, "stepsize": 1, "label": "Min window height diff"},
"minimumWheelHeightDifference": {"min": 0, "max": 500, "stepsize": 1, "label": "Min wheel height diff"}
},
"Speed": {
"levelMovementSpeedMinimum": {"min": 0, "max": 100, "stepsize": 1, "label": "Minimum level speed"},
"levelMovementDurationTillMaximum": {"min": 1, "max": 60, "stepsize": 1, "label": "Level acceleration duration"}
},
"Difficulty 0": {
"diff0MaxSpeed": {"min": 0, "max": 500, "stepsize": 1, "label": "Maximum level speed"},
"diff0PlatformRot": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform rotation"},
"diff0PlatformCreation": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform creation"},
"diff0Gravity": {"min": 30, "max": 150, "stepsize": 1, "label": "Gravity"}
},
"Difficulty 1": {
"diff1MaxSpeed": {"min": 0, "max": 500, "stepsize": 1, "label": "Maximum level speed"},
"diff1PlatformRot": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform rotation"},
"diff1PlatformCreation": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform creation"},
"diff1Points": {"min": 0, "max": 300000, "stepsize": 100, "label": "Points needed"},
"diff1Gravity": {"min": 30, "max": 150, "stepsize": 1, "label": "Gravity"}
},
"Difficulty 2": {
"diff2MaxSpeed": {"min": 0, "max": 500, "stepsize": 1, "label": "Maximum level speed"},
"diff2PlatformRot": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform rotation"},
"diff2PlatformCreation": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform creation"},
"diff2Points": {"min": 0, "max": 300000, "stepsize": 100, "label": "Points needed"},
"diff2Gravity": {"min": 30, "max": 150, "stepsize": 1, "label": "Gravity"}
},
"Difficulty 3": {
"diff3MaxSpeed": {"min": 0, "max": 500, "stepsize": 1, "label": "Maximum level speed"},
"diff3PlatformRot": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform rotation"},
"diff3PlatformCreation": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform creation"},
"diff3Points": {"min": 0, "max": 300000, "stepsize": 100, "label": "Points needed"}
},
"Difficulty 4": {
"diff4MaxSpeed": {"min": 0, "max": 500, "stepsize": 1, "label": "Maximum level speed"},
"diff4PlatformRot": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform rotation"},
"diff4PlatformCreation": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform creation"},
"diff4Points": {"min": 0, "max": 300000, "stepsize": 100, "label": "Points needed"},
"diff4Gravity": {"min": 30, "max": 150, "stepsize": 1, "label": "Gravity"}
},
"Difficulty 5": {
"diff5MaxSpeed": {"min": 0, "max": 500, "stepsize": 1, "label": "Maximum level speed"},
"diff5PlatformRot": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform rotation"},
"diff5PlatformCreation": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform creation"},
"diff5Points": {"min": 0, "max": 300000, "stepsize": 100, "label": "Points needed"},
"diff5Gravity": {"min": 30, "max": 150, "stepsize": 1, "label": "Gravity"}
},
"Difficulty 6": {
"diff6MaxSpeed": {"min": 0, "max": 500, "stepsize": 1, "label": "Maximum level speed"},
"diff6PlatformRot": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform rotation"},
"diff6PlatformCreation": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Platform creation"},
"diff6Points": {"min": 0, "max": 300000, "stepsize": 100, "label": "Points needed"},
"diff6Gravity": {"min": 30, "max": 150, "stepsize": 1, "label": "Gravity"}
}
}
}
EditableComponent {
editableType: "Player"
properties: {
"General": {
"bonusScoreForCoin": {"min": 100, "max": 1000, "stepsize": 1, "label": "Coin Score"},
"doublePointsDuration": {"min": 1, "max": 30, "stepsize": 1, "label": "Double Points duration"},
"rightValue": {"min": 50, "max": 500, "stepsize": 5, "label": "Velocity multiplier"},
"henLinearDamping": {"min": 0.0, "max": 25.0, "stepsize": 0.1, "label": "Linear damping"},
"henFriction": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Friction"},
"parachuteGravityScale": {"min": 0, "max": 1, "stepsize": 0.01, "label": "Parachute gravity scale"},
"scoreFromItemEditor": {"min": 0, "max": 300000, "stepsize": 1000, "label": "Add Test Score"}
},
"Accelerometer Settings": {
"accelerometerOffset": {"min": 0, "max": 0.3, "stepsize": 0.001, "label": "Offset"},
"accelerometerMultiplier": {"min": 0, "max": 1, "stepsize": 0.05, "label": "Multiplier"}
}
}
}
Component.onCompleted: {
preCreateEntityPool();
}
function preCreateEntityPool() {
entityManager.createPooledEntitiesFromUrl(Qt.resolvedUrl("entities/Roost.qml"), 30);
entityManager.createPooledEntitiesFromUrl(Qt.resolvedUrl("entities/Wheel.qml"), 5);
entityManager.createPooledEntitiesFromUrl(Qt.resolvedUrl("entities/HenhouseWindow.qml"), 5);
entityManager.createPooledEntitiesFromUrl(Qt.resolvedUrl("entities/Coin.qml"), 10);
entityManager.createPooledEntitiesFromUrl(Qt.resolvedUrl("entities/TrippleCoin.qml"), 5);
entityManager.createPooledEntitiesFromUrl(Qt.resolvedUrl("entities/BadCoin.qml"), 5);
entityManager.createPooledEntitiesFromUrl(Qt.resolvedUrl("entities/Parachute.qml"), 1);
entityManager.createPooledEntitiesFromUrl(Qt.resolvedUrl("entities/DoublePoints.qml"), 1);
}
function stopGame() {
levelMovementAnimation.stop();
entityManager.removeAllEntities();
state = "stopped"
}
function startGame() {
console.debug("Level: startGame()");
levelBackground.resetBackgrounds()
currentRow = 0;
lastY = 0;
level.y = 0;
player.start()
player.x = scene.width/2;
player.y = 2*gridSize;
player.score = 0;
player.bonusScore = 0;
player.beams = 0;
player.collectedBadGrains = 0
player.collectedGrains = 0
player.parachutes = 0;
difficulty = 0
player.bonusTextScore = 0;
player.parachute = false;
player.blockCollisions = 0;
player.doublePointsTime = 0;
player.collider.body.linearVelocity.x = 0
player.controller.xAxis = 0;
player.teleportGlowParticle.stop()
lastWindowY = 0;
lastWheelY = 0;
for(var i=5; i<rowCount; i++) {
LevelLogic.createRandomRowForRowNumber(i);
}
levelMovementAnimation.velocity = -levelMovementSpeedMinimum;
levelMovementAnimation.start();
state = "running"
}
Image {
id: overlay
source: Qt.resolvedUrl("../assets/blackbg.png")
width: scene.gameWindowAnchorItem.width
height: scene.gameWindowAnchorItem.height*1.5
opacity: 0
x: scene.gameWindowAnchorItem.x
y: scene.gameWindowAnchorItem.y
}
Player {
id: player
x: scene.width/2
y: gridSize/2
z: 5
onTotalScoreChanged: {
if(player.totalScore<diff1Points) {
return
} else if(player.totalScore>diff6Points && difficulty === 5) {
difficulty = 6
} else if(player.totalScore>diff5Points && difficulty === 4) {
difficulty = 5
} else if(player.totalScore>diff4Points && difficulty === 3) {
difficulty = 4
} else if(player.totalScore>diff3Points && difficulty === 2) {
difficulty = 3
} else if(player.totalScore>diff2Points && difficulty === 1) {
difficulty = 2
} else if(player.totalScore>diff1Points && difficulty === 0) {
difficulty = 1
}
}
onDeathAnimationFinished: {
stopGame()
window.state = "gameOver"
}
}
Roost {
id: lowerBlock
entityId: "playerInitialBlock"
x: scene.width/2
y: 3.5*gridSize
preventFromRemovalFromEntityManager: true
}
BorderRegion {
width: scene.gameWindowAnchorItem.width*2
anchors.horizontalCenter: parent.horizontalCenter
variationType: "topRegion"
height: 20
property real defaultOffsety: __yOffsetForWindow + height + 120
y: - defaultOffsety-level.y
onPlayerCollision: {
console.debug("PLAYER COLLIDED WITH topRegion, level.y:", level.y, ", player.y:", player.y)
if(!noDeath)
gameLost();
else
player.y = player.y+scene.height/2
}
}
BorderRegion {
width: scene.gameWindowAnchorItem.width*2
anchors.horizontalCenter: parent.horizontalCenter
height: 20
y: scene.gameWindowAnchorItem.height-level.y
variationType: "bottomRegion"
onPlayerCollision: {
console.debug("PLAYER COLLIDED WITH BorderRegion, level.y:", level.y, ", player.y:", player.y)
if(!noDeath)
gameLost();
else
player.y = player.y-scene.height
}
}
BorderRegion {
x: scene.gameWindowAnchorItem.x-80-width
height: scene.gameWindowAnchorItem.height*2
width: 20
y: -level.y-defaultOffsety
property real defaultOffsety: height/4
variationType: "bottomRegion"
onPlayerCollision: {
gameLost();
}
}
BorderRegion {
x: scene.gameWindowAnchorItem.x+scene.gameWindowAnchorItem.width+80+width
height: scene.gameWindowAnchorItem.height*2
width: 20
y: -level.y-defaultOffsety
property real defaultOffsety: height/4
variationType: "bottomRegion"
onPlayerCollision: {
gameLost();
}
}
MovementAnimation {
id: levelMovementAnimation
property: "y"
velocity: 0-levelMovementSpeedMinimum
acceleration:0 -(levelMovementSpeedMaximum-levelMovementSpeedMinimum) / levelMovementDurationTillMaximum
target: level
minVelocity: 0-levelMovementSpeedMaximum
onVelocityChanged: {
levelBackground.movementVelocity = Qt.point(0, levelMovementAnimation.velocity)
}
}
onYChanged: {
var dy = y - lastY;
if(-dy > gridSize) {
var amountNewRows = (-dy/gridSize).toFixed();
console.debug(amountNewRows, "new rows are getting created...")
for(var i=0; i<amountNewRows; i++) {
currentRow++;
LevelLogic.createRandomRowForRowNumber(currentRow+rowCount);
lastY -= gridSize
}
}
currentScore = -(level.y/40).toFixed()
if(currentScore > player.score+4 && !noFont) {
player.score = currentScore
}
if(!noManualGC)
gc()
}
function pauseGame() {
if(state !== "running") return
console.debug("pauseGame()")
levelMovementAnimation.stop()
player.stop()
state = "paused"
}
function resumeGame() {
if(state !== "paused" && state !== "teleporting") return
console.debug("resumeGame()")
levelMovementAnimation.start()
player.start()
state = "running"
}
function toggleTeleport() {
console.debug("toggleTeleport with state " + state)
if(state === "running") {
player.beams++
pauseGame()
state = "teleporting"
} else if(state === "teleporting") {
resumeGame()
}
}
function saveIt() {
pauseGame()
state = "teleporting"
player.saveIt()
player.teleportGlowParticle.start()
}
onStateChanged: console.debug("state changed to " + state)
states: [
State {
name: "running"
PropertyChanges { target: overlay; opacity: 0; y: scene.gameWindowAnchorItem.y-level.y -__yOffsetForWindow}
},
State {
name: "stopped"
PropertyChanges { target: overlay; opacity: 0; y: scene.gameWindowAnchorItem.y-level.y -__yOffsetForWindow}
},
State {
name: "paused"
PropertyChanges { target: overlay; opacity: 1; y: scene.gameWindowAnchorItem.y-level.y -__yOffsetForWindow}
},
State {
name: "teleporting"
PropertyChanges { target: overlay; opacity: 1; y: scene.gameWindowAnchorItem.y-level.y -__yOffsetForWindow}
}
]
transitions: [
Transition {
NumberAnimation {property: "opacity"; easing.type: Easing.InOutQuad}