Squaby Demo
import QtQuick 2.0
import QtMultimedia 6.0
import Felgo 4.0
import "../particles"
TowerBase {
id: flamethrower
entityType: "flamethrower"
property real flameAreaDamagePerSecond: level.balancingSettings.flamethrower.flameAreaDamagePerSecond
property bool running: false
onRunningChanged: {
if(running) {
shootTimer.running = true;
shootEffect.play();
if (__currentUpgradeLevels.damagePerSecond > 0) {
if(currentParticles < maximumParticles) {
currentParticles++
fireParticle2.start();
}
}
if(currentParticles < maximumParticles) {
currentParticles++
fireParticle1.start();
}
} else {
shootEffect.stop();
if (__currentUpgradeLevels.damagePerSecond > 0) {
if(fireParticle2.running) {
currentParticles--
fireParticle2.stop();
}
}
if(fireParticle1.running) {
currentParticles--
fireParticle1.stop();
}
shootTimer.running = false;
}
}
shootDelayInMilliSeconds: level.balancingSettings.flamethrower.shootDelayInMilliSeconds
cost: level.balancingSettings.flamethrower.cost
saleRevenue: level.balancingSettings.flamethrower.saleRevenue
upgradeLevels: level.balancingSettings.flamethrower.upgradeLevels
__currentUpgradeLevels: { "range": 0, "damagePerSecond": 0 }
onEntityDestroyed: {
shootTimer.running = false;
}
FlamethrowerSprite {
id: sprite
}
GameSoundEffect {
id: shootEffect
source: Qt.resolvedUrl("../../assets/snd/flamethrowerFire01.wav")
loops: SoundEffect.Infinite
}
GameParticle {
id: fireParticle1
fileName: Qt.resolvedUrl("../particles/FireParticle.json")
y: 0
x: 15
}
GameParticle {
id: fireParticle2
fileName: Qt.resolvedUrl("../particles/FireParticle.json")
y: -5
x: 15
}
Timer {
id: shootTimer
interval: 300
repeat: true
triggeredOnStart: true
onTriggered: {
shoot();
}
onRunningChanged: {
console.debug("Flamethrower: running changed to", running)
if(running) {
__lastShoot = new Date()
}
}
}
onAimingAtTargetChanged: aimingAtTarget => {
console.debug("aimingAtTarget of flamethrower changed to:", aimingAtTarget);
if(aimingAtTarget && !shootTimer.running) {
running = true
}
}
onTargetRemoved: {
running = false
}
onTowerUpgradedWithCustomUpgrade: (upgradeType, upgradeData) => {
if(upgradeType === "damagePerSecond") {
flameAreaDamagePerSecond = upgradeData.value;
}
}
onTowerUpgraded: {
if(upgradeType === "damagePerSecond") {
if(fireParticle1.running) {
currentParticles--
}
fireParticle1.maxParticles = fireParticle1.maxParticles/2
fireParticle1.stop()
fireParticle2.maxParticles = fireParticle2.maxParticles/2
fireParticle2.stop()
fireParticle1.y = 5;
if(running && currentParticles < maximumParticles) {
currentParticles++
fireParticle1.start();
fireParticle2.start();
}
}
else if(upgradeType === "range") {
fireParticle1.startColor = "#ffffff"
fireParticle1.startColorAlpha = 0.7
fireParticle1.textureFileName = Qt.resolvedUrl("../particles/particleNapalm.png");
fireParticle2.startColor = "#ffffff"
fireParticle2.startColorAlpha = 0.7
fireParticle2.textureFileName = Qt.resolvedUrl("../particles/particleNapalm.png");
}
}
property date __lastShoot
function shoot() {
if(!targetEntity) {
shootTimer.running = false;
return;
}
var now = new Date;
var dt = now-__lastShoot;
__lastShoot = now;
var damage = flameAreaDamagePerSecond*dt*0.001;
targetEntity.hitByValue(entityId, entityType, damage);