Squaby Demo
import QtQuick 2.0
import QtMultimedia 6.0
import Felgo 4.0
import "../particles"
TowerBase {
id: tesla
entityType: "tesla"
property real teslaAreaDamagePerSecond: level.balancingSettings.tesla.teslaAreaDamagePerSecond
property bool running: false
onRunningChanged: {
if(running) {
shootTimer.running = true;
shootEffect.play();
if(currentParticles < maximumParticles) {
currentParticles++
teslaParticle.start();
}
} else {
shootEffect.stop();
if(teslaParticle.running) {
currentParticles--
teslaParticle.stop();
}
shootTimer.running = false;
}
}
shootDelayInMilliSeconds: level.balancingSettings.tesla.shootDelayInMilliSeconds
cost: level.balancingSettings.tesla.cost
saleRevenue: level.balancingSettings.tesla.saleRevenue
upgradeLevels: level.balancingSettings.tesla.upgradeLevels
__currentUpgradeLevels: { "range": 0, "damagePerSecond": 0 }
onEntityDestroyed: {
shootTimer.running = false;
}
TeslaSprite {
id: sprite
}
GameSoundEffect {
id: shootEffect
source: Qt.resolvedUrl("../../assets/snd/teslafire.wav")
loops: SoundEffect.Infinite
}
GameParticle {
id: teslaParticle
fileName: Qt.resolvedUrl("../particles/tesla.json")
y: 0
x: 15
}
Timer {
id: shootTimer
interval: 100
repeat: true
triggeredOnStart: true
onTriggered: {
shoot();
}
onRunningChanged: {
console.debug("Tesla: running changed to", running)
if(running) {
__lastShoot = new Date()
}
}
}
onAimingAtTargetChanged: {
console.debug("aimingAtTarget of tesla changed to:", aimingAtTarget);
if(aimingAtTarget && !shootTimer.running) {
running = true
}
}
onTargetRemoved: {
running = false
}
onTowerUpgradedWithCustomUpgrade: {
if(upgradeType === "damagePerSecond") {
teslaAreaDamagePerSecond = upgradeData.value;
}
}
onTowerUpgraded: {
if(upgradeType === "damagePerSecond") {
teslaParticle.finishColor = "#ca8f00"
}
else if(upgradeType === "range") {
teslaParticle.speed = teslaParticle.speed*2
}
}
property date __lastShoot
function shoot() {
if(!targetEntity) {
shootTimer.running = false;
return;
}
var now = new Date;
var dt = now-__lastShoot;
__lastShoot = now;
var damage = teslaAreaDamagePerSecond*dt*0.001;
targetEntity.hitByValue(entityId, entityType, damage);