Squaby Demo
import QtQuick 2.0
import QtMultimedia 6.0
import Felgo 4.0
import "../particles"
TowerBase {
id: taser
entityType: "taser"
property real taserAreaDamagePerSecond: level.balancingSettings.taser.taserAreaDamagePerSecond
property bool running: false
shootDelayInMilliSeconds: level.balancingSettings.taser.shootDelayInMilliSeconds
cost: level.balancingSettings.taser.cost
saleRevenue: level.balancingSettings.taser.saleRevenue
upgradeLevels: level.balancingSettings.taser.upgradeLevels
__currentUpgradeLevels: { "range": 0, "damagePerSecond": 0 }
onEntityDestroyed: {
shootTimer.running = false;
}
TaserSprite {
id: sprite
}
GameSoundEffect {
id: shootEffect
source: Qt.resolvedUrl("../../assets/snd/taserfire.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: 100
repeat: true
triggeredOnStart: true
onTriggered: {
shoot();
}
onRunningChanged: {
console.debug("taser: running changed to", running)
if(running) {
__lastShoot = new Date()
}
}
}
onAimingAtTargetChanged: {
console.debug("aimingAtTarget of taser changed to:", aimingAtTarget);
if(aimingAtTarget && !shootTimer.running) {
shootTimer.running = true;
shootEffect.play();
if (__currentUpgradeLevels.damagePerSecond > 0) {
fireParticle2.start();
}
fireParticle1.start();
running = true
}
}
onTargetRemoved: {
shootEffect.stop();
if (__currentUpgradeLevels.damagePerSecond > 0) {
fireParticle2.stop();
}
fireParticle1.stop();
running = false
shootTimer.running = false;
}
onTowerUpgradedWithCustomUpgrade: {
if(upgradeType === "damagePerSecond") {
taserAreaDamagePerSecond = upgradeData.value;
}
}
onTowerUpgraded: {
if(upgradeType === "damagePerSecond") {
fireParticle1.y = 5;
if(running)
fireParticle2.start();
}
else if(upgradeType === "range") {
fireParticle1.startColor = "#ffffff"
fireParticle1.textureFileName = Qt.resolvedUrl("../particles/particleNapalm.png");
fireParticle2.startColor = "#ffffff"
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 = taserAreaDamagePerSecond*dt*0.001;
targetEntity.hitByValue(entityId, entityType, damage);