ChickenOutbreak2 Demo
var newRoostCenterPos = Qt.point(0,0)
var newWheelCenterPos = Qt.point(0,0)
var randomValue
var coinCenterPos = Qt.point(0,0)
var coinPositionModifier = 0.7*scene.gridSize
var gridSizeHalf = scene.gridSize/2
var newWindowTopleftPos = Qt.point(0,0)
var newWindowCenterPos = Qt.point(0,0)
var roostUrl = Qt.resolvedUrl("../entities/Roost.qml")
var wheelUrl = Qt.resolvedUrl("../entities/Wheel.qml")
var coinUrl = Qt.resolvedUrl("../entities/Coin.qml")
var doublePointsUrl = Qt.resolvedUrl("../entities/DoublePoints.qml")
var parachuteUrl = Qt.resolvedUrl("../entities/Parachute.qml")
var trippleCoinUrl = Qt.resolvedUrl("../entities/TrippleCoin.qml")
var badCoinUrl = Qt.resolvedUrl("../entities/BadCoin.qml")
var coinTypeUrl
var windowUrl = Qt.resolvedUrl("../entities/HenhouseWindow.qml")
var newElementProperties = {}
function createRandomRowForRowNumber(rowNumber) {
for(var i=0; i<roostColumns; i++) {
randomValue = Math.random()
if(randomValue < wheelCreationProbability ) {
newWheelCenterPos.x = i*gridSize + 43
newWheelCenterPos.y = rowNumber*gridSize + 43
if(newWheelCenterPos.y-lastWheelY < minimumWheelHeightDifference) {
console.debug("difference between last Window and current to create one too small!")
continue;
}
if(physicsWorld.bodyAt(newWheelCenterPos)) {
console.debug("no Wheel can be created because there is something already");
continue;
}
newElementProperties.x = newWheelCenterPos.x
newElementProperties.y = newWheelCenterPos.y
entityManager.createEntityFromUrlWithProperties(wheelUrl,newElementProperties)
lastWheelY = newWheelCenterPos.y;
}
randomValue = Math.random()
if(randomValue < platformCreationProbability ) {
newRoostCenterPos.x = i*gridSize + gridSizeHalf
newRoostCenterPos.y = rowNumber*gridSize + gridSizeHalf
if(physicsWorld.bodyAt(newRoostCenterPos)) {
console.debug("no Roost can be created because there is something already");
continue;
}
newElementProperties.x = newRoostCenterPos.x
newElementProperties.y = newRoostCenterPos.y
newElementProperties.rotation = Math.random() < platformRotationProbability ? (Math.floor(Math.random() * 70) -34) : 0
entityManager.createEntityFromUrlWithProperties(roostUrl,newElementProperties)
randomValue = Math.random()
if(randomValue < coinCreationPropability) {
coinCenterPos.x = newRoostCenterPos.x
coinCenterPos.y = newRoostCenterPos.y-scene.gridSize
if(physicsWorld.bodyAt(coinCenterPos)) {
console.debug("there is a block above the to create block, don't create a coin here!")
continue;
}
randomValue = Math.random()
if(randomValue < doublePointsCreationPropability) {
newElementProperties.x = coinCenterPos.x
newElementProperties.y = coinCenterPos.y+0.6*scene.gridSize
coinTypeUrl = doublePointsUrl
}
else if(Math.random() < parachuteCreationPropability) {
newElementProperties.x = coinCenterPos.x
newElementProperties.y = coinCenterPos.y+0.6*scene.gridSize
coinTypeUrl = parachuteUrl
}
else if(Math.random() < trippleCoinCreationPropability) {
newElementProperties.x = coinCenterPos.x-6
newElementProperties.y = coinCenterPos.y+0.5*scene.gridSize
coinTypeUrl = trippleCoinUrl
} else if(Math.random() < badCoinCreationPropability) {
newElementProperties.x = coinCenterPos.x
newElementProperties.y = coinCenterPos.y+0.6*scene.gridSize
coinTypeUrl = badCoinUrl
} else {
newElementProperties.x = coinCenterPos.x
newElementProperties.y = coinCenterPos.y+0.65*scene.gridSize
coinTypeUrl = coinUrl
}
entityManager.createEntityFromUrlWithProperties(coinTypeUrl,newElementProperties)
}
newElementProperties.rotation = 0
} else if(i < roostColumns-1 && randomValue < windowCreationProbability ) {
newWindowTopleftPos.x = i*gridSize
newWindowTopleftPos.y = rowNumber*gridSize
newWindowCenterPos.x = i*gridSize+32
newWindowCenterPos.y = rowNumber*gridSize+30
if(newWindowTopleftPos.y-lastWindowY < minimumWindowHeightDifference) {
console.debug("difference between last Window and current to create one too small!")
continue;
}
if(physicsWorld.bodyAt(newWindowTopleftPos) || physicsWorld.bodyAt(newWindowCenterPos)) {
console.debug("body at position x:", newWindowTopleftPos.x, ", y:", newWindowTopleftPos.y, physicsWorld.bodyAt(newWindowTopleftPos))
console.debug("there is a window at the position where to create a window, so no creation is done");
continue;
}
newElementProperties.x = newWindowCenterPos.x
newElementProperties.y = newWindowCenterPos.y
entityManager.createEntityFromUrlWithProperties(windowUrl,newElementProperties)
lastWindowY = newWindowTopleftPos.y;
i++
}