Skip to content
Home
Post Code
Jass (Warcraft III)
Wurst
GUI (Warcraft III)
Galaxy (StarCraft II)
GUI (StarCraft II)
C++
Java
Delphi
Text
Search Code
Compare Code
Uploads
Draw
Create New Drawing
View Drawings
Graph
Log in
<pre class="jasscode"><span class="style_symbol">/</span>* <span class="style_int">4</span> Packages included<span class="style_symbol">.</span><span class="style_symbol">.</span> Projectile superclass TimedBlasts (main system) Kamehameha (2d example <span class="style_keyword">of</span> TimedBlasts System) AngryKame (3d example <span class="style_keyword">of</span> TimedBlasts System TimedBlasts attempts <span class="style_keyword">to</span> give a system <span class="style_keyword">to</span> create various <span class="style_string">"timed blasts"</span> that can be customized <span class="style_keyword">to</span> create tons <span class="style_keyword">of</span> different spells that follow the general layout User begins channeling animation<span class="style_symbol">,</span> creating the projectile <span class="style_keyword">near</span> them<span class="style_symbol">.</span><span class="style_symbol">.</span> after a certain size <span class="style_keyword">is</span> reached<span class="style_symbol">,</span> the projectile <span class="style_keyword">is</span> launched <span class="style_keyword">to</span> the target point inflicting damage<span class="style_symbol">.</span> <span class="style_keyword">If</span> two <span class="style_string">"clashable"</span> blasts hit each other<span class="style_symbol">,</span> the two casters will be <span class="style_keyword">in</span> a struggle <span class="style_keyword">until</span> one runs out <span class="style_keyword">of</span> mana<span class="style_symbol">,</span> <span class="style_keyword">and</span> the winning blast will change target <span class="style_keyword">to</span> its opposing caster <span class="style_keyword">unit</span><span class="style_symbol">.</span> *visual example <span class="style_keyword">of</span> what this code attempts <span class="style_keyword">to</span> achieve <span class="style_keyword">in</span> the <span class="style_keyword">case</span> <span class="style_keyword">of</span> a 3d clashable blast https:<span class="style_comment">//www.youtube.com/watch?v=M7i5Z3C5ZOk</span> *note clashable <span class="style_keyword">and</span> 3d hasn<span class="style_string">'t been tested/made yet*</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> protected real impactAoe - size of aoe for damage to be done</span> <span class="style_string"> protected real damage - damage to be done</span> <span class="style_string"> protected real endScale - final scale of the blast before launching</span> <span class="style_string"> protected boolean trailOn - creates a trail following the blast as it flies to the target</span> <span class="style_string"> protected boolean dustOn - creates a dust effect around the caster as he fires</span> <span class="style_string"> protected boolean pulseOn - makes the missile pulsate as it flies to the targeted area</span> <span class="style_string"> protected boolean launchOn - creates a launch effect as the missile is launched</span> <span class="style_string"> protected boolean dropOn - if the missile is fired from an aerial position, the missile is lowered to the targetted area</span> <span class="style_string"> protected boolean flightOn - if the missile will be fired from an aerial position</span> <span class="style_string"> protected string trailSFX - specify what SFX will be used for the trail</span> <span class="style_string"> protected string pulseSFX - specify what SFX will be used for the pulse</span> <span class="style_string"> protected string launchSFX - " "</span> <span class="style_string"> protected string finalSFX - " "</span> <span class="style_string"> protected string dustSFX - " "</span> <span class="style_string"> protected real trailSize - size of trail created</span> <span class="style_string"> protected real pulseSize - size of pulses</span> <span class="style_string"> protected real launchSize - size of launch</span> <span class="style_string"> protected colorA missileCol - color of missile</span> <span class="style_string"> protected colorA trailCol = color of trail</span> <span class="style_string"> protected colorA pulseCol = color of pulse</span> <span class="style_string"> protected real speed - speed of missile during travel</span> <span class="style_string"> protected int channelIndex - animation index to channel</span> <span class="style_string"> protected int launchIndex - animation index to launch</span> <span class="style_string"> protected real offsetDistance = 50 - small offset from caster</span> <span class="style_string"> protected real realDropSpeed = -15 if there is a drop, reasonable dropspeed, can be changed</span> <span class="style_string"> private real timeSinceLastTrail = 0 - used to create trail</span> <span class="style_string"> private real timeSinceLastPulse = 0 - used to create pulses</span> <span class="style_string"> private real timeSinceLastChannel = 0 - uses to create channel</span> <span class="style_string"> protected real timeDistance - how long trails and pulses should last, depends on speed, and missile sizes, should be configured to each spell accordingly</span> <span class="style_string"> protected sound throwSound = generic missile size</span> <span class="style_string"> protected real lowerRate = 150. speed that a missile will lower if it is a 3d missile</span> <span class="style_string"> protected real destroyExplode = 1.5 how long the destruction sfx will be played</span> <span class="style_string"> protected boolean clashing - setting if the missile is ready to clash</span> <span class="style_string"> protected boolean clashable - saves true value for clashable until channeling is complete</span> <span class="style_string"> protected boolean clashed - if a missile has clashed, prevents further clashs</span> <span class="style_string"> protected boolean channeling = if a missile is still channeling, it cannot clash yet</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string">*/</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string">package Projectile</span> <span class="style_string">import public Entity</span> <span class="style_string"></span> <span class="style_string">public class Projectile extends FxEntity</span> <span class="style_string"> // Angles</span> <span class="style_string"> protected angle xyAngle</span> <span class="style_string"> private vec3 startpos</span> <span class="style_string"></span> <span class="style_string"> private boolean timed = false</span> <span class="style_string"> private boolean ranged = false</span> <span class="style_string"></span> <span class="style_string"> // Moving Speed</span> <span class="style_string"> private real speed = 0</span> <span class="style_string"> private real acc = 1.0</span> <span class="style_string"> protected real dist = 0</span> <span class="style_string"> private real maxDist = 0</span> <span class="style_string"> protected real lifespan = 0</span> <span class="style_string"> protected real dropSpeed = 0</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> construct( vec3 pos, real radius, player owner, angle xyAngle, string fxpath )</span> <span class="style_string"> super(pos, radius, owner, xyAngle, fxpath)</span> <span class="style_string"> startpos = pos</span> <span class="style_string"> setXYAngle(xyAngle)</span> <span class="style_string"> active = false</span> <span class="style_string"></span> <span class="style_string"> function setRanged(real maxDistance)</span> <span class="style_string"> this.maxDist = maxDistance*maxDistance</span> <span class="style_string"> ranged = true</span> <span class="style_string"></span> <span class="style_string"> function setTimed(real lifespan)</span> <span class="style_string"> this.lifespan = lifespan</span> <span class="style_string"> timed = true</span> <span class="style_string"></span> <span class="style_string"> function setSpeed(real speed)</span> <span class="style_string"> this.speed = speed</span> <span class="style_string"> //angle.direction(real distance)</span> <span class="style_string"> setVel(vec3(xyAngle.cos()*speed, xyAngle.sin()*speed, dropSpeed))</span> <span class="style_string"></span> <span class="style_string"> function setSpeed(real speed, real drop)</span> <span class="style_string"> this.speed = speed</span> <span class="style_string"> //angle.direction(real distance)</span> <span class="style_string"> setVel(vec3(xyAngle.cos()*speed, xyAngle.sin()*speed, drop))</span> <span class="style_string"></span> <span class="style_string"> function setAcc(real factor)</span> <span class="style_string"> this.acc = factor</span> <span class="style_string"></span> <span class="style_string"> function getSpeed() returns real</span> <span class="style_string"> return speed</span> <span class="style_string"></span> <span class="style_string"> function setXYAngle(angle xyA)</span> <span class="style_string"> this.xyAngle = xyA</span> <span class="style_string"> fx.setXYAngle(xyA)</span> <span class="style_string"></span> <span class="style_string"> function setZAngle(angle zA)</span> <span class="style_string"> fx.setZAngle(zA)</span> <span class="style_string"></span> <span class="style_string"> override function update()</span> <span class="style_string"> vel *= acc</span> <span class="style_string"> pos += vel</span> <span class="style_string"> fixPos()</span> <span class="style_string"> if timed</span> <span class="style_string"> lifespan -= ANIMATION_PERIOD</span> <span class="style_string"> if lifespan <= 0</span> <span class="style_string"> done = true</span> <span class="style_string"> return</span> <span class="style_string"> if ranged</span> <span class="style_string"> if startpos.distToVecSquared(pos) > maxDist</span> <span class="style_string"> done = true</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string">package TimedBlasts</span> <span class="style_string">import Projectile</span> <span class="style_string">import LinkedListModule</span> <span class="style_string">import Fx</span> <span class="style_string">import Constants</span> <span class="style_string">import ClosureTimers</span> <span class="style_string">import Terrain</span> <span class="style_string">import LinkedList</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> public class TimedBlasts extends Projectile</span> <span class="style_string"> use LinkedListModule</span> <span class="style_string"> //Editable values</span> <span class="style_string"> protected real impactAoe</span> <span class="style_string"> protected real damage</span> <span class="style_string"> protected real endScale</span> <span class="style_string"> protected boolean trailOn = false</span> <span class="style_string"> protected boolean dustOn = false</span> <span class="style_string"> protected boolean pulseOn = false</span> <span class="style_string"> protected boolean launchOn = false</span> <span class="style_string"> protected boolean dropOn = false</span> <span class="style_string"> protected boolean flightOn = true</span> <span class="style_string"> protected string trailSFX</span> <span class="style_string"> protected string pulseSFX</span> <span class="style_string"> protected string launchSFX</span> <span class="style_string"> protected string finalSFX</span> <span class="style_string"> protected string dustSFX = dustWave</span> <span class="style_string"> protected real trailSize</span> <span class="style_string"> protected real pulseSize</span> <span class="style_string"> protected real launchSize</span> <span class="style_string"> protected colorA missileCol = colorA(255,255,255,255)</span> <span class="style_string"> protected colorA trailCol = colorA(255,255,255,255)</span> <span class="style_string"> protected colorA pulseCol = colorA(255,255,255,255)</span> <span class="style_string"> protected real speed</span> <span class="style_string"> protected int channelIndex</span> <span class="style_string"> protected int launchIndex</span> <span class="style_string"> protected real offsetDistance = 50</span> <span class="style_string"> protected real realDropSpeed = -15</span> <span class="style_string"> private real timeSinceLastTrail = 0</span> <span class="style_string"> private real timeSinceLastPulse = 0</span> <span class="style_string"> private real timeSinceLastChannel = 0</span> <span class="style_string"> protected real timeDistance = 1</span> <span class="style_string"> protected sound throwSound = gg_snd_kamehameha_fire</span> <span class="style_string"> protected real lowerRate = 150.</span> <span class="style_string"> protected real destroyExplode = 1.5</span> <span class="style_string"> protected boolean clashing = false</span> <span class="style_string"> protected boolean clashable = false</span> <span class="style_string"> protected boolean clashed = false</span> <span class="style_string"> protected boolean channeling = false</span> <span class="style_string"> protected LinkedList<Fx> trailList = new LinkedList<Fx>()</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> //Instance Variables</span> <span class="style_string"> private vec3 target</span> <span class="style_string"> protected unit u</span> <span class="style_string"> private timer t = getTimer()</span> <span class="style_string"> protected real scale</span> <span class="style_string"> protected angle targetAngle</span> <span class="style_string"> private boolean missileCast = false</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> construct(unit actor,vec3 pos, player owner, vec3 target, string SFX, real originalScale)</span> <span class="style_string"> super(pos.addReals(0, 0, pos.withTerrainZ().z), 0, owner, pos.angleTo2d(target), SFX)</span> <span class="style_string"> this.targetAngle = pos.angleTo2d(target)</span> <span class="style_string"> this.u = actor</span> <span class="style_string"> this.target = target</span> <span class="style_string"> this.u.pause()</span> <span class="style_string"> this.scale = originalScale</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> function startMissile()</span> <span class="style_string"> this.setSpeed(0)</span> <span class="style_string"> this.pos = pos.offset2d(pos.angleTo2d(target), offsetDistance)</span> <span class="style_string"> this.pos.z += 50</span> <span class="style_string"> this.fixPos()</span> <span class="style_string"> this.fx.setColor(missileCol)</span> <span class="style_string"> this.fx.setScale(this.scale)</span> <span class="style_string"></span> <span class="style_string"> this.t.setData(this castTo int)</span> <span class="style_string"> this.t.startPeriodic(.1, function callExpandMissile)</span> <span class="style_string"></span> <span class="style_string"> //if dust is activated</span> <span class="style_string"> if this.dustOn</span> <span class="style_string"> this.createDust()</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> function createDust()</span> <span class="style_string"> effect x = AddSpecialEffectTarget(dustSFX, u, "origin")</span> <span class="style_string"> DestroyEffectBJ(x)</span> <span class="style_string"></span> <span class="style_string"> static function callExpandMissile()</span> <span class="style_string"> (GetExpiredTimer().getData() castTo TimedBlasts).expandMissile()</span> <span class="style_string"></span> <span class="style_string"> function expandMissile()</span> <span class="style_string"> if this.timeSinceLastChannel == 0</span> <span class="style_string"> this.u.setAnimation(channelIndex)</span> <span class="style_string"> if this.timeSinceLastChannel >= (.18)</span> <span class="style_string"> this.u.setAnimation(channelIndex)</span> <span class="style_string"> this.timeSinceLastChannel -= (.17)</span> <span class="style_string"> this.timeSinceLastChannel += ANIMATION_PERIOD</span> <span class="style_string"></span> <span class="style_string"> this.scale += .05</span> <span class="style_string"> this.fx.setScale(this.scale)</span> <span class="style_string"> if this.scale >= endScale</span> <span class="style_string"> if this.flightOn</span> <span class="style_string"> this.u.setFlyHeight(0, lowerRate)</span> <span class="style_string"> if this.launchOn</span> <span class="style_string"> this.createLaunchFX()</span> <span class="style_string"> if this.dropOn</span> <span class="style_string"> this.dropSpeed = realDropSpeed</span> <span class="style_string"></span> <span class="style_string"> this.setSpeed(speed)</span> <span class="style_string"></span> <span class="style_string"> this.t.release()</span> <span class="style_string"> this.u.setAnimation(launchIndex)</span> <span class="style_string"> PlaySoundOnUnitBJ(this.throwSound, 70, this.u)</span> <span class="style_string"> this.missileCast = true</span> <span class="style_string"> if not this.channeling</span> <span class="style_string"> this.u.unpause()</span> <span class="style_string"> if this.clashing</span> <span class="style_string"> this.clashable = true</span> <span class="style_string"></span> <span class="style_string"> //calculate frequency of trail creation</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> function createLaunchFX()</span> <span class="style_string"> Fx launch = new Fx(fx.getPos2(),this.targetAngle, kameLaunch)</span> <span class="style_string"> launch.setScale(launchSize)</span> <span class="style_string"> doAfter(.5, () -> destroy launch)</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> function createTrail()</span> <span class="style_string"> Fx trail = new Fx(fx.getPos3d(), this.targetAngle, trailSFX)</span> <span class="style_string"> ..setScale(trailSize)</span> <span class="style_string"> ..setColor(trailCol)</span> <span class="style_string"> if flightOn == false</span> <span class="style_string"> trail.setZ(100)</span> <span class="style_string"> // doAfter(timeDistance, () -> trail.hiddenDestroy())</span> <span class="style_string"> this.trailList.add(trail)</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> function createPulse()</span> <span class="style_string"> Fx pulse = new Fx(fx.getPos3d(), this.targetAngle, pulseSFX)</span> <span class="style_string"> ..setScale(pulseSize)</span> <span class="style_string"> ..setZAngle(-5200)</span> <span class="style_string"> ..setColor(pulseCol)</span> <span class="style_string"> if this.flightOn == false</span> <span class="style_string"> pulse.setZ(100)</span> <span class="style_string"> // pulse.getDummy().setAnimation(0)</span> <span class="style_string"> doAfter(timeDistance, () -> pulse.hiddenDestroy())</span> <span class="style_string"></span> <span class="style_string"> override function update()</span> <span class="style_string"> super.update()</span> <span class="style_string"></span> <span class="style_string">//should be speed dependent at some level.</span> <span class="style_string"> if pos.toVec2().distToVecSquared(target.toVec2()) < 120*120</span> <span class="style_string"> //timeDistance = 0.15</span> <span class="style_string"> if this.getSpeed() > 0</span> <span class="style_string"> if this.trailOn</span> <span class="style_string"> if this.timeSinceLastTrail > (2/speed)</span> <span class="style_string"> this.createTrail()</span> <span class="style_string"> this.timeSinceLastTrail -= (2/speed)</span> <span class="style_string"> this.timeSinceLastTrail += ANIMATION_PERIOD</span> <span class="style_string"> if this.pulseOn</span> <span class="style_string"> if this.timeSinceLastPulse > (2/speed)</span> <span class="style_string"> this.createPulse()</span> <span class="style_string"> this.timeSinceLastPulse -= (2/speed)</span> <span class="style_string"> this.timeSinceLastPulse += ANIMATION_PERIOD</span> <span class="style_string"> if not this.clashed</span> <span class="style_string"> if this.clashable</span> <span class="style_string"> Entity e = Entity.getFirst()</span> <span class="style_string"> while e != null</span> <span class="style_string"> if e!= this and this.owner != e.owner</span> <span class="style_string"> if this.owner.isAllyOf(e.owner)</span> <span class="style_string"> TimedBlasts blast2 = e castTo TimedBlasts</span> <span class="style_string"> if blast2.clashable and not blast2.clashed</span> <span class="style_string"> if this.pos.distToVecSquared(e.pos) < 40000.</span> <span class="style_string"> print(this.pos.distToVecSquared(e.pos).toString())</span> <span class="style_string"> if this.pos.distToVecSquared(e.pos) < (120*120)</span> <span class="style_string"> //print("hi6!")</span> <span class="style_string"> this.onHit(blast2)</span> <span class="style_string"> e=e.next</span> <span class="style_string"></span> <span class="style_string"> if ((this.u.getPos().distToVecSquared(target.toVec2()) < 150*150) or (pos.toVec2().distToVecSquared(target.toVec2()) < 64*64)) and missileCast</span> <span class="style_string"> for unit enemy from ENUM_GROUP..enumUnitsInRange(pos.toVec2(), impactAoe)</span> <span class="style_string"> if enemy.isEnemy(owner)</span> <span class="style_string"> this.u.damageTarget(enemy, damage)</span> <span class="style_string"> done = true</span> <span class="style_string"> terminate()</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> function onHit(TimedBlasts blast2)</span> <span class="style_string"> boolean winner1 = false</span> <span class="style_string"> boolean winner2 = false</span> <span class="style_string"> //print("hi7!")</span> <span class="style_string"> this.clashed = true</span> <span class="style_string"> blast2.clashed = true</span> <span class="style_string"> blast2.setSpeed(0)</span> <span class="style_string"> this.setSpeed(0)</span> <span class="style_string"> blast2.active = false</span> <span class="style_string"> this.active = false</span> <span class="style_string"> //this.fx.setScale(endScale+ 1)</span> <span class="style_string"> //blast2.fx.setScale(endScale+ 1)</span> <span class="style_string"> doPeriodically(.25, (CallbackPeriodic cb) -> begin</span> <span class="style_string"> Fx effect1 = new Fx(fx.getPos2(),this.targetAngle, iceNova)</span> <span class="style_string"> ..setScale(1.8)</span> <span class="style_string"> ..setZ(100)</span> <span class="style_string"> ..setZAngle(-5200)</span> <span class="style_string"> Fx effect2 = new Fx(blast2.fx.getPos2(),this.targetAngle, iceNova)</span> <span class="style_string"> ..setScale(1.8)</span> <span class="style_string"> ..setZ(100)</span> <span class="style_string"> ..setZAngle(-5200)</span> <span class="style_string"> Fx effect5 = new Fx(((fx.getPos2() + blast2.fx.getPos2()) *.5).toVec3().addReals(0, 0, 50), this.targetAngle, sparklyExplosion)</span> <span class="style_string"> ..setScale(5)</span> <span class="style_string"> doAfter(.25, () -> begin</span> <span class="style_string"> destroy(effect1)</span> <span class="style_string"> destroy(effect2)</span> <span class="style_string"> destroy(effect5)</span> <span class="style_string"> end)</span> <span class="style_string"></span> <span class="style_string"> if this.u.getMana() == 0</span> <span class="style_string"> winner2 = true</span> <span class="style_string"> if blast2.u.getMana() == 0</span> <span class="style_string"> winner1 = true</span> <span class="style_string"> this.u.setMana(u.getMana()-1)</span> <span class="style_string"> blast2.u.setMana(blast2.u.getMana()-2)</span> <span class="style_string"> if winner1</span> <span class="style_string"> print(this.u.getName())</span> <span class="style_string"> blast2.terminate()</span> <span class="style_string"> this.target = blast2.u.getPos3()</span> <span class="style_string"> this.setSpeed(this.speed)</span> <span class="style_string"> this.active = true</span> <span class="style_string"> destroy cb</span> <span class="style_string"> if winner2 and not winner1</span> <span class="style_string"> print(blast2.u.getName())</span> <span class="style_string"> terminate()</span> <span class="style_string"> blast2.target = this.u.getPos3()</span> <span class="style_string"> blast2.setSpeed(blast2.speed)</span> <span class="style_string"> blast2.active = true</span> <span class="style_string"> destroy cb</span> <span class="style_string"> end)</span> <span class="style_string"></span> <span class="style_string"> ondestroy</span> <span class="style_string"> if this.channeling</span> <span class="style_string"> this.u.unpause()</span> <span class="style_string"> Fx final = new Fx(fx.getPos3d(), this.targetAngle, finalSFX)</span> <span class="style_string"> final.setScale(2)</span> <span class="style_string"> doAfter(destroyExplode, () -> final.hiddenDestroy())</span> <span class="style_string"> for i = 0 to (this.trailList.getSize() -1)</span> <span class="style_string"> this.trailList.get(i).hiddenDestroy()</span> <span class="style_string"> this.done = true</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string">package Kamehameha</span> <span class="style_string">import Constants</span> <span class="style_string">import TimedBlasts</span> <span class="style_string"></span> <span class="style_string">constant real originalScale = .2</span> <span class="style_string">public class Kamehameha extends TimedBlasts</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string"> construct(unit actor,vec3 pos, player owner, vec3 target, int level)</span> <span class="style_string"> super(actor,pos.addReals(0, 0, 50),owner,target,bigKamehamehaBall,originalScale)</span> <span class="style_string"></span> <span class="style_string"> //if (actor.getTypeId() == '</span>H001<span class="style_string">')</span> <span class="style_string"> this.impactAoe = 500</span> <span class="style_string"> this.damage = 150*level.toReal() + (GetHeroInt(actor, true)*10)</span> <span class="style_string"> this.trailOn = true</span> <span class="style_string"> this.dustOn = true</span> <span class="style_string"> this.pulseOn = true</span> <span class="style_string"> this.launchOn = true</span> <span class="style_string"> int actorID = actor.getTypeId()</span> <span class="style_string"> if actorID == '</span>H000<span class="style_string">'</span> <span class="style_string"> this.channelIndex = 11</span> <span class="style_string"> this.launchIndex = 12</span> <span class="style_string"> this.throwSound = gg_snd_Kamehameha_Voice</span> <span class="style_string"> if actorID == '</span>H005<span class="style_string">' or actorID == '</span>H009<span class="style_string">'</span> <span class="style_string"> this.channelIndex = 20</span> <span class="style_string"> this.launchIndex = 18</span> <span class="style_string"> if actorID == '</span>H00A<span class="style_string">'</span> <span class="style_string"> this.channelIndex = 5</span> <span class="style_string"> this.launchIndex = 4</span> <span class="style_string"> if actorID == '</span>H001<span class="style_string">' or actorID == '</span>H008<span class="style_string">'</span> <span class="style_string"> this.channelIndex = 7</span> <span class="style_string"> this.launchIndex = 8</span> <span class="style_string"> this.throwSound = gg_snd_GohanKame</span> <span class="style_string"> if actorID == '</span>H00D<span class="style_string">' or actorID == '</span>H00E<span class="style_string">' or actorID == '</span>H00F<span class="style_string">'</span> <span class="style_string"> this.channelIndex = 8</span> <span class="style_string"> this.launchIndex = 12</span> <span class="style_string"> if actorID == '</span>H007<span class="style_string">'</span> <span class="style_string"> this.channelIndex = 9</span> <span class="style_string"> this.launchIndex = 13</span> <span class="style_string"> if actorID == '</span>H00G<span class="style_string">'</span> <span class="style_string"> this.channelIndex = 12</span> <span class="style_string"> this.launchIndex = 11</span> <span class="style_string"> this.speed = 32</span> <span class="style_string"> this.endScale = .6</span> <span class="style_string"> this.trailSFX = bigKamehamehaBall</span> <span class="style_string"> this.trailSize = .3</span> <span class="style_string"> this.pulseSFX = bluePulse</span> <span class="style_string"> this.launchSFX = kameLaunch</span> <span class="style_string"> this.launchSize = 5</span> <span class="style_string"> this.finalSFX = bigBlueExplosion</span> <span class="style_string"> this.pulseSize = 1</span> <span class="style_string"> this.trailCol = colorA(255,255,255,255)</span> <span class="style_string"> this.clashing = true</span> <span class="style_string"> this.channeling = true</span> <span class="style_string"> startMissile()</span> <span class="style_string"></span> <span class="style_string"></span> <span class="style_string">package AngryKame</span> <span class="style_string">import Constants</span> <span class="style_string">import TimedBlasts</span> <span class="style_string">import ClosureTimers</span> <span class="style_string"></span> <span class="style_string">constant real originalScale = .2</span> <span class="style_string">public class AngryKame extends TimedBlasts</span> <span class="style_string"></span> <span class="style_string"> construct(unit actor,vec3 pos, player owner, vec3 target, int level)</span> <span class="style_string"> super(actor,pos.addReals(0, 0, 700),owner,target,dummy2,originalScale)</span> <span class="style_string"> this.impactAoe = 500</span> <span class="style_string"> actor.setFlyHeight(700, 700.)</span> <span class="style_string"> this.flightOn = true</span> <span class="style_string"> this.dropOn = true</span> <span class="style_string"> this.offsetDistance = 0</span> <span class="style_string"> this.missileCol = colorA(150,150,0,255)</span> <span class="style_string"> this.speed = 25</span> <span class="style_string"> this.endScale = 1.5</span> <span class="style_string"> this.dustSFX = dustWave</span> <span class="style_string"> this.damage = 5000*level.toReal() + (GetHeroInt(actor, true)*20)</span> <span class="style_string"> this.finalSFX = nuclearExplosion</span> <span class="style_string"> this.trailOn = true</span> <span class="style_string"> this.dustOn = true</span> <span class="style_string"> this.pulseOn = true</span> <span class="style_string"> this.launchOn = false</span> <span class="style_string"> this.channelIndex = 20</span> <span class="style_string"> this.launchIndex = 10</span> <span class="style_string"> this.trailSFX = pinkBall</span> <span class="style_string"> this.trailSize = .6</span> <span class="style_string"> this.launchSFX = kameLaunch</span> <span class="style_string"> this.launchSize = 5</span> <span class="style_string"> this.trailCol = colorA(150,150,0,255)</span> <span class="style_string"> this.lowerRate = 300.</span> <span class="style_string"> this.realDropSpeed = -25</span> <span class="style_string"> this.destroyExplode = 3</span> <span class="style_string"> this.pulseSFX = windBlue</span> <span class="style_string"> this.pulseSize = 1.2</span> <span class="style_string"> this.pulseCol = colorA(150,150,0,255)</span> <span class="style_string"> effect x = AddSpecialEffectTarget(kamelightning, u, "origin")</span> <span class="style_string"> doAfter(1.5, () -> begin</span> <span class="style_string"> doAfter(1, () -> begin</span> <span class="style_string"> PlaySoundOnUnitBJ(gg_snd_angrykame, 70, this.u)</span> <span class="style_string"> end)</span> <span class="style_string"> startMissile()</span> <span class="style_string"> fx.setFx(pinkBall)</span> <span class="style_string"> end)</span> <span class="style_string"> doAfter(12, () -> begin</span> <span class="style_string"> DestroyEffectBJ(x)</span> <span class="style_string"> end)</span> <span class="style_string"></span> <span class="style_string"></span> </pre>
select language
jass
java
> delphi
C++
php
GSL
galaxy
visualBasic
wurst
Text
Markdown
select style
default
bbcode - default
Jasscraft
> jasscraft html
visual
lightweight
lightweightNr
goto line:
Compare with:
text copy window
edit this code
post new code
/* 4 Packages included.. Projectile superclass TimedBlasts (main system) Kamehameha (2d example of TimedBlasts System) AngryKame (3d example of TimedBlasts System TimedBlasts attempts to give a system to create various "timed blasts" that can be customized to create tons of different spells that follow the general layout User begins channeling animation, creating the projectile near them.. after a certain size is reached, the projectile is launched to the target point inflicting damage. If two "clashable" blasts hit each other, the two casters will be in a struggle until one runs out of mana, and the winning blast will change target to its opposing caster unit. *visual example of what this code attempts to achieve in the case of a 3d clashable blast https://www.youtube.com/watch?v=M7i5Z3C5ZOk *note clashable and 3d hasn't been tested/made yet* protected real impactAoe - size of aoe for damage to be done protected real damage - damage to be done protected real endScale - final scale of the blast before launching protected boolean trailOn - creates a trail following the blast as it flies to the target protected boolean dustOn - creates a dust effect around the caster as he fires protected boolean pulseOn - makes the missile pulsate as it flies to the targeted area protected boolean launchOn - creates a launch effect as the missile is launched protected boolean dropOn - if the missile is fired from an aerial position, the missile is lowered to the targetted area protected boolean flightOn - if the missile will be fired from an aerial position protected string trailSFX - specify what SFX will be used for the trail protected string pulseSFX - specify what SFX will be used for the pulse protected string launchSFX - " " protected string finalSFX - " " protected string dustSFX - " " protected real trailSize - size of trail created protected real pulseSize - size of pulses protected real launchSize - size of launch protected colorA missileCol - color of missile protected colorA trailCol = color of trail protected colorA pulseCol = color of pulse protected real speed - speed of missile during travel protected int channelIndex - animation index to channel protected int launchIndex - animation index to launch protected real offsetDistance = 50 - small offset from caster protected real realDropSpeed = -15 if there is a drop, reasonable dropspeed, can be changed private real timeSinceLastTrail = 0 - used to create trail private real timeSinceLastPulse = 0 - used to create pulses private real timeSinceLastChannel = 0 - uses to create channel protected real timeDistance - how long trails and pulses should last, depends on speed, and missile sizes, should be configured to each spell accordingly protected sound throwSound = generic missile size protected real lowerRate = 150. speed that a missile will lower if it is a 3d missile protected real destroyExplode = 1.5 how long the destruction sfx will be played protected boolean clashing - setting if the missile is ready to clash protected boolean clashable - saves true value for clashable until channeling is complete protected boolean clashed - if a missile has clashed, prevents further clashs protected boolean channeling = if a missile is still channeling, it cannot clash yet */ package Projectile import public Entity public class Projectile extends FxEntity // Angles protected angle xyAngle private vec3 startpos private boolean timed = false private boolean ranged = false // Moving Speed private real speed = 0 private real acc = 1.0 protected real dist = 0 private real maxDist = 0 protected real lifespan = 0 protected real dropSpeed = 0 construct( vec3 pos, real radius, player owner, angle xyAngle, string fxpath ) super(pos, radius, owner, xyAngle, fxpath) startpos = pos setXYAngle(xyAngle) active = false function setRanged(real maxDistance) this.maxDist = maxDistance*maxDistance ranged = true function setTimed(real lifespan) this.lifespan = lifespan timed = true function setSpeed(real speed) this.speed = speed //angle.direction(real distance) setVel(vec3(xyAngle.cos()*speed, xyAngle.sin()*speed, dropSpeed)) function setSpeed(real speed, real drop) this.speed = speed //angle.direction(real distance) setVel(vec3(xyAngle.cos()*speed, xyAngle.sin()*speed, drop)) function setAcc(real factor) this.acc = factor function getSpeed() returns real return speed function setXYAngle(angle xyA) this.xyAngle = xyA fx.setXYAngle(xyA) function setZAngle(angle zA) fx.setZAngle(zA) override function update() vel *= acc pos += vel fixPos() if timed lifespan -= ANIMATION_PERIOD if lifespan <= 0 done = true return if ranged if startpos.distToVecSquared(pos) > maxDist done = true package TimedBlasts import Projectile import LinkedListModule import Fx import Constants import ClosureTimers import Terrain import LinkedList public class TimedBlasts extends Projectile use LinkedListModule //Editable values protected real impactAoe protected real damage protected real endScale protected boolean trailOn = false protected boolean dustOn = false protected boolean pulseOn = false protected boolean launchOn = false protected boolean dropOn = false protected boolean flightOn = true protected string trailSFX protected string pulseSFX protected string launchSFX protected string finalSFX protected string dustSFX = dustWave protected real trailSize protected real pulseSize protected real launchSize protected colorA missileCol = colorA(255,255,255,255) protected colorA trailCol = colorA(255,255,255,255) protected colorA pulseCol = colorA(255,255,255,255) protected real speed protected int channelIndex protected int launchIndex protected real offsetDistance = 50 protected real realDropSpeed = -15 private real timeSinceLastTrail = 0 private real timeSinceLastPulse = 0 private real timeSinceLastChannel = 0 protected real timeDistance = 1 protected sound throwSound = gg_snd_kamehameha_fire protected real lowerRate = 150. protected real destroyExplode = 1.5 protected boolean clashing = false protected boolean clashable = false protected boolean clashed = false protected boolean channeling = false protected LinkedList<Fx> trailList = new LinkedList<Fx>() //Instance Variables private vec3 target protected unit u private timer t = getTimer() protected real scale protected angle targetAngle private boolean missileCast = false construct(unit actor,vec3 pos, player owner, vec3 target, string SFX, real originalScale) super(pos.addReals(0, 0, pos.withTerrainZ().z), 0, owner, pos.angleTo2d(target), SFX) this.targetAngle = pos.angleTo2d(target) this.u = actor this.target = target this.u.pause() this.scale = originalScale function startMissile() this.setSpeed(0) this.pos = pos.offset2d(pos.angleTo2d(target), offsetDistance) this.pos.z += 50 this.fixPos() this.fx.setColor(missileCol) this.fx.setScale(this.scale) this.t.setData(this castTo int) this.t.startPeriodic(.1, function callExpandMissile) //if dust is activated if this.dustOn this.createDust() function createDust() effect x = AddSpecialEffectTarget(dustSFX, u, "origin") DestroyEffectBJ(x) static function callExpandMissile() (GetExpiredTimer().getData() castTo TimedBlasts).expandMissile() function expandMissile() if this.timeSinceLastChannel == 0 this.u.setAnimation(channelIndex) if this.timeSinceLastChannel >= (.18) this.u.setAnimation(channelIndex) this.timeSinceLastChannel -= (.17) this.timeSinceLastChannel += ANIMATION_PERIOD this.scale += .05 this.fx.setScale(this.scale) if this.scale >= endScale if this.flightOn this.u.setFlyHeight(0, lowerRate) if this.launchOn this.createLaunchFX() if this.dropOn this.dropSpeed = realDropSpeed this.setSpeed(speed) this.t.release() this.u.setAnimation(launchIndex) PlaySoundOnUnitBJ(this.throwSound, 70, this.u) this.missileCast = true if not this.channeling this.u.unpause() if this.clashing this.clashable = true //calculate frequency of trail creation function createLaunchFX() Fx launch = new Fx(fx.getPos2(),this.targetAngle, kameLaunch) launch.setScale(launchSize) doAfter(.5, () -> destroy launch) function createTrail() Fx trail = new Fx(fx.getPos3d(), this.targetAngle, trailSFX) ..setScale(trailSize) ..setColor(trailCol) if flightOn == false trail.setZ(100) // doAfter(timeDistance, () -> trail.hiddenDestroy()) this.trailList.add(trail) function createPulse() Fx pulse = new Fx(fx.getPos3d(), this.targetAngle, pulseSFX) ..setScale(pulseSize) ..setZAngle(-5200) ..setColor(pulseCol) if this.flightOn == false pulse.setZ(100) // pulse.getDummy().setAnimation(0) doAfter(timeDistance, () -> pulse.hiddenDestroy()) override function update() super.update() //should be speed dependent at some level. if pos.toVec2().distToVecSquared(target.toVec2()) < 120*120 //timeDistance = 0.15 if this.getSpeed() > 0 if this.trailOn if this.timeSinceLastTrail > (2/speed) this.createTrail() this.timeSinceLastTrail -= (2/speed) this.timeSinceLastTrail += ANIMATION_PERIOD if this.pulseOn if this.timeSinceLastPulse > (2/speed) this.createPulse() this.timeSinceLastPulse -= (2/speed) this.timeSinceLastPulse += ANIMATION_PERIOD if not this.clashed if this.clashable Entity e = Entity.getFirst() while e != null if e!= this and this.owner != e.owner if this.owner.isAllyOf(e.owner) TimedBlasts blast2 = e castTo TimedBlasts if blast2.clashable and not blast2.clashed if this.pos.distToVecSquared(e.pos) < 40000. print(this.pos.distToVecSquared(e.pos).toString()) if this.pos.distToVecSquared(e.pos) < (120*120) //print("hi6!") this.onHit(blast2) e=e.next if ((this.u.getPos().distToVecSquared(target.toVec2()) < 150*150) or (pos.toVec2().distToVecSquared(target.toVec2()) < 64*64)) and missileCast for unit enemy from ENUM_GROUP..enumUnitsInRange(pos.toVec2(), impactAoe) if enemy.isEnemy(owner) this.u.damageTarget(enemy, damage) done = true terminate() function onHit(TimedBlasts blast2) boolean winner1 = false boolean winner2 = false //print("hi7!") this.clashed = true blast2.clashed = true blast2.setSpeed(0) this.setSpeed(0) blast2.active = false this.active = false //this.fx.setScale(endScale+ 1) //blast2.fx.setScale(endScale+ 1) doPeriodically(.25, (CallbackPeriodic cb) -> begin Fx effect1 = new Fx(fx.getPos2(),this.targetAngle, iceNova) ..setScale(1.8) ..setZ(100) ..setZAngle(-5200) Fx effect2 = new Fx(blast2.fx.getPos2(),this.targetAngle, iceNova) ..setScale(1.8) ..setZ(100) ..setZAngle(-5200) Fx effect5 = new Fx(((fx.getPos2() + blast2.fx.getPos2()) *.5).toVec3().addReals(0, 0, 50), this.targetAngle, sparklyExplosion) ..setScale(5) doAfter(.25, () -> begin destroy(effect1) destroy(effect2) destroy(effect5) end) if this.u.getMana() == 0 winner2 = true if blast2.u.getMana() == 0 winner1 = true this.u.setMana(u.getMana()-1) blast2.u.setMana(blast2.u.getMana()-2) if winner1 print(this.u.getName()) blast2.terminate() this.target = blast2.u.getPos3() this.setSpeed(this.speed) this.active = true destroy cb if winner2 and not winner1 print(blast2.u.getName()) terminate() blast2.target = this.u.getPos3() blast2.setSpeed(blast2.speed) blast2.active = true destroy cb end) ondestroy if this.channeling this.u.unpause() Fx final = new Fx(fx.getPos3d(), this.targetAngle, finalSFX) final.setScale(2) doAfter(destroyExplode, () -> final.hiddenDestroy()) for i = 0 to (this.trailList.getSize() -1) this.trailList.get(i).hiddenDestroy() this.done = true package Kamehameha import Constants import TimedBlasts constant real originalScale = .2 public class Kamehameha extends TimedBlasts construct(unit actor,vec3 pos, player owner, vec3 target, int level) super(actor,pos.addReals(0, 0, 50),owner,target,bigKamehamehaBall,originalScale) //if (actor.getTypeId() == 'H001') this.impactAoe = 500 this.damage = 150*level.toReal() + (GetHeroInt(actor, true)*10) this.trailOn = true this.dustOn = true this.pulseOn = true this.launchOn = true int actorID = actor.getTypeId() if actorID == 'H000' this.channelIndex = 11 this.launchIndex = 12 this.throwSound = gg_snd_Kamehameha_Voice if actorID == 'H005' or actorID == 'H009' this.channelIndex = 20 this.launchIndex = 18 if actorID == 'H00A' this.channelIndex = 5 this.launchIndex = 4 if actorID == 'H001' or actorID == 'H008' this.channelIndex = 7 this.launchIndex = 8 this.throwSound = gg_snd_GohanKame if actorID == 'H00D' or actorID == 'H00E' or actorID == 'H00F' this.channelIndex = 8 this.launchIndex = 12 if actorID == 'H007' this.channelIndex = 9 this.launchIndex = 13 if actorID == 'H00G' this.channelIndex = 12 this.launchIndex = 11 this.speed = 32 this.endScale = .6 this.trailSFX = bigKamehamehaBall this.trailSize = .3 this.pulseSFX = bluePulse this.launchSFX = kameLaunch this.launchSize = 5 this.finalSFX = bigBlueExplosion this.pulseSize = 1 this.trailCol = colorA(255,255,255,255) this.clashing = true this.channeling = true startMissile() package AngryKame import Constants import TimedBlasts import ClosureTimers constant real originalScale = .2 public class AngryKame extends TimedBlasts construct(unit actor,vec3 pos, player owner, vec3 target, int level) super(actor,pos.addReals(0, 0, 700),owner,target,dummy2,originalScale) this.impactAoe = 500 actor.setFlyHeight(700, 700.) this.flightOn = true this.dropOn = true this.offsetDistance = 0 this.missileCol = colorA(150,150,0,255) this.speed = 25 this.endScale = 1.5 this.dustSFX = dustWave this.damage = 5000*level.toReal() + (GetHeroInt(actor, true)*20) this.finalSFX = nuclearExplosion this.trailOn = true this.dustOn = true this.pulseOn = true this.launchOn = false this.channelIndex = 20 this.launchIndex = 10 this.trailSFX = pinkBall this.trailSize = .6 this.launchSFX = kameLaunch this.launchSize = 5 this.trailCol = colorA(150,150,0,255) this.lowerRate = 300. this.realDropSpeed = -25 this.destroyExplode = 3 this.pulseSFX = windBlue this.pulseSize = 1.2 this.pulseCol = colorA(150,150,0,255) effect x = AddSpecialEffectTarget(kamelightning, u, "origin") doAfter(1.5, () -> begin doAfter(1, () -> begin PlaySoundOnUnitBJ(gg_snd_angrykame, 70, this.u) end) startMissile() fx.setFx(pinkBall) end) doAfter(12, () -> begin DestroyEffectBJ(x) end)