Squaby Demo
import QtQuick 2.0
import QtMultimedia 6.0
import Felgo 4.0
import "../particles"
import "../gameScene"
TowerBase {
id: turbine
entityType: "turbine"
property real lives: level.balancingSettings.turbine.lives
shootDelayInMilliSeconds: level.balancingSettings.turbine.shootDelayInMilliSeconds
cost: level.balancingSettings.turbine.cost
saleRevenue: level.balancingSettings.turbine.saleRevenue
upgradeLevels: level.balancingSettings.turbine.upgradeLevels
__currentUpgradeLevels: { "range": 0, "shootDelay": 0, "repair": 1 }
onEntityDestroyed: {
coolOffTimer.running = false;
}
TurbineSprite {
id: sprite
}
GameSoundEffect {
id: whirlEffect
source: Qt.resolvedUrl("../../assets/snd/turbineRunning.wav")
loops: SoundEffect.Infinite
}
GameSoundEffect {
id: squabyShredderEffect
source: Qt.resolvedUrl("../../assets/snd/turbineShredder.wav")
}
GameSoundEffect {
id: turbineExplodeEffect
source: Qt.resolvedUrl("../../assets/snd/turbineExplode.wav")
}
GameParticle {
id: smokeParticle
fileName: Qt.resolvedUrl("../particles/SmokeParticle.json")
duration: shootDelayInMilliSeconds*0.001
}
GameParticle {
id: puddleParticle
fileName: Qt.resolvedUrl("../particles/DeathParticle.json")
x: -25
z: sprite.z-1
}
GameParticle {
id: splatterParticle
fileName: Qt.resolvedUrl("../particles/SplatterParticle.json")
x: -15
z: sprite.z-1
}
Timer {
id: coolOffTimer
interval: shootDelayInMilliSeconds
repeat: false
running: false
onTriggered: {
console.debug("Turbine: coolOffTimer triggered, switch back to default state, current state:", turbine.state);
turbine.state = "";
}
}
Healthbar {
id:healthbar
absoluteX: -sprite.sprite.width/2
absoluteY: -sprite.sprite.height/2
width: sprite.sprite.width
height: 3
percent: healthComponent.healthInPercent
useSpriteVersion: true
}
HealthComponent {
id: healthComponent
health: lives
onDied: {
console.debug("Turbine: turbine's lives are over, play explode animation");
sprite.explode();
turbineExplodeEffect.play();
var upgradeLevelsCopy = __currentUpgradeLevels;
upgradeLevelsCopy.repair = 0;
__currentUpgradeLevels = upgradeLevelsCopy;
console.debug("Turbine: updated repair level:", __currentUpgradeLevels.repair);
if(hud.selectedTowerId === turbine.entityId) {
console.debug("Turbine: the selectedTowerId equals this tower's, so update the hud");
towerSelected();
}
turbine.state = "exploded";
}
}
onTowerUpgradedWithCustomUpgrade: {
if(upgradeType === "repair") {
console.debug("Turbine: repair upgrade used");
lives = upgradeData.value;
healthComponent.resetHealth();
sprite.repair();
turbine.state = "";
smokeParticle.stop();
puddleParticle.stopLivingParticles()
}
}
onAimingAtTargetChanged: {
console.debug("Turbine: aimingAtTarget changed to:", aimingAtTarget);
if(aimingAtTarget && turbine.state === "") {
whirl();
}
}
onTargetRemoved: {
console.debug("Turbine: onTargetRemoved()");
whirlEffect.stop();
sprite.state = "";
}
function whirl() {
sprite.state = "whirl";
whirlEffect.play();
targetEntity.startWhirlingToTarget(turbine);
}
function whirlingOfSquabySuccessful(squabyId) {
turbine.state = "coolOff";
smokeParticle.start();
splatterParticle.start();
puddleParticle.start();
if(targetEntity && targetEntity.entityId === squabyId) {
console.debug("Turbine: successfully whirled a squaby to death, reduce its health");
squabyShredderEffect.play();
healthComponent.hit(1);
} else {
console.debug("WARNING: unknown behavior! targetEntity is not equal squaby parameter! targetEntity:", targetEntity, ", squabyId:", squabyId)
}
}
states: [
State {
name: ""
StateChangeScript { script: console.debug("Turbine: changed state to default") }
},
State {
name: "coolOff"
StateChangeScript { script: console.debug("Turbine: changed state to coolOff") }
PropertyChanges { target: fireRangeCollider; active: false }
PropertyChanges { target: coolOffTimer; running: true }
},
State {
name: "exploded"
StateChangeScript { script: console.debug("Turbine: changed state to exploded") }
PropertyChanges { target: fireRangeCollider; active: false }
}