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.. Projectile superclass TimedBlasts <span class="style_symbol">(</span>main system<span class="style_symbol">)</span> Kamehameha <span class="style_symbol">(</span>2d example of TimedBlasts System<span class="style_symbol">)</span> AngryKame <span class="style_symbol">(</span>3d example of TimedBlasts System TimedBlasts attempts to give a system to create various <span class="style_string">"timed blasts"</span> 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. <span class="style_keyword">If</span> two <span class="style_string">"clashable"</span> 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. <span class="style_symbol">*</span>visual example of what this code attempts to achieve in the case of a 3d clashable blast https://www.youtube.com/watch<span class="style_symbol">?</span>v=M7i5Z3C5ZOk <span class="style_symbol">*</span>note clashable and 3d hasn<span class="style_comment">'t been tested/made yet*</span> 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 - <span class="style_string">" "</span> protected string finalSFX - <span class="style_string">" "</span> protected string dustSFX - <span class="style_string">" "</span> 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 = <span class="style_int">50</span> - small offset from caster protected real realDropSpeed = -<span class="style_int">15</span> if there is a drop, reasonable dropspeed, can be changed private real timeSinceLastTrail = <span class="style_int">0</span> - used to create trail private real timeSinceLastPulse = <span class="style_int">0</span> - used to create pulses private real timeSinceLastChannel = <span class="style_int">0</span> - 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 = <span class="style_float">150.</span> speed that a missile will lower if it is a 3d missile protected real destroyExplode = <span class="style_float">1.5</span> 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 <span class="style_symbol">*</span>/ 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 = <span class="style_int">0</span> private real acc = <span class="style_float">1.0</span> protected real dist = <span class="style_int">0</span> private real maxDist = <span class="style_int">0</span> protected real lifespan = <span class="style_int">0</span> protected real dropSpeed = <span class="style_int">0</span> construct<span class="style_symbol">(</span> vec3 pos, real radius, player owner, angle xyAngle, string fxpath <span class="style_symbol">)</span> super<span class="style_symbol">(</span>pos, radius, owner, xyAngle, fxpath<span class="style_symbol">)</span> startpos = pos setXYAngle<span class="style_symbol">(</span>xyAngle<span class="style_symbol">)</span> active = false function setRanged<span class="style_symbol">(</span>real maxDistance<span class="style_symbol">)</span> this.maxDist = maxDistance<span class="style_symbol">*</span>maxDistance ranged = true function setTimed<span class="style_symbol">(</span>real lifespan<span class="style_symbol">)</span> this.lifespan = lifespan timed = true function setSpeed<span class="style_symbol">(</span>real speed<span class="style_symbol">)</span> this.speed = speed //angle.direction<span class="style_symbol">(</span>real distance<span class="style_symbol">)</span> setVel<span class="style_symbol">(</span>vec3<span class="style_symbol">(</span>xyAngle.cos<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">*</span>speed, xyAngle.sin<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">*</span>speed, dropSpeed<span class="style_symbol">)</span><span class="style_symbol">)</span> function setSpeed<span class="style_symbol">(</span>real speed, real drop<span class="style_symbol">)</span> this.speed = speed //angle.direction<span class="style_symbol">(</span>real distance<span class="style_symbol">)</span> setVel<span class="style_symbol">(</span>vec3<span class="style_symbol">(</span>xyAngle.cos<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">*</span>speed, xyAngle.sin<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">*</span>speed, drop<span class="style_symbol">)</span><span class="style_symbol">)</span> function setAcc<span class="style_symbol">(</span>real factor<span class="style_symbol">)</span> this.acc = factor function getSpeed<span class="style_symbol">(</span><span class="style_symbol">)</span> returns real return speed function setXYAngle<span class="style_symbol">(</span>angle xyA<span class="style_symbol">)</span> this.xyAngle = xyA fx.setXYAngle<span class="style_symbol">(</span>xyA<span class="style_symbol">)</span> function setZAngle<span class="style_symbol">(</span>angle zA<span class="style_symbol">)</span> fx.setZAngle<span class="style_symbol">(</span>zA<span class="style_symbol">)</span> override function update<span class="style_symbol">(</span><span class="style_symbol">)</span> vel <span class="style_symbol">*</span>= acc pos += vel fixPos<span class="style_symbol">(</span><span class="style_symbol">)</span> if timed lifespan -= ANIMATION_PERIOD if lifespan <= <span class="style_int">0</span> done = true return if ranged if startpos.distToVecSquared<span class="style_symbol">(</span>pos<span class="style_symbol">)</span> > 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<span class="style_symbol">(</span><span class="style_int">255</span>,<span class="style_int">255</span>,<span class="style_int">255</span>,<span class="style_int">255</span><span class="style_symbol">)</span> protected colorA trailCol = colorA<span class="style_symbol">(</span><span class="style_int">255</span>,<span class="style_int">255</span>,<span class="style_int">255</span>,<span class="style_int">255</span><span class="style_symbol">)</span> protected colorA pulseCol = colorA<span class="style_symbol">(</span><span class="style_int">255</span>,<span class="style_int">255</span>,<span class="style_int">255</span>,<span class="style_int">255</span><span class="style_symbol">)</span> protected real speed protected int channelIndex protected int launchIndex protected real offsetDistance = <span class="style_int">50</span> protected real realDropSpeed = -<span class="style_int">15</span> private real timeSinceLastTrail = <span class="style_int">0</span> private real timeSinceLastPulse = <span class="style_int">0</span> private real timeSinceLastChannel = <span class="style_int">0</span> protected real timeDistance = <span class="style_int">1</span> protected sound throwSound = gg_snd_kamehameha_fire protected real lowerRate = <span class="style_float">150.</span> protected real destroyExplode = <span class="style_float">1.5</span> protected boolean clashing = false protected boolean clashable = false protected boolean clashed = false protected boolean channeling = false protected LinkedList<Fx> trailList = new LinkedList<Fx><span class="style_symbol">(</span><span class="style_symbol">)</span> //Instance Variables private vec3 target protected unit u private timer t = getTimer<span class="style_symbol">(</span><span class="style_symbol">)</span> protected real scale protected angle targetAngle private boolean missileCast = false construct<span class="style_symbol">(</span>unit actor,vec3 pos, player owner, vec3 target, string SFX, real originalScale<span class="style_symbol">)</span> super<span class="style_symbol">(</span>pos.addReals<span class="style_symbol">(</span><span class="style_int">0</span>, <span class="style_int">0</span>, pos.withTerrainZ<span class="style_symbol">(</span><span class="style_symbol">)</span>.z<span class="style_symbol">)</span>, <span class="style_int">0</span>, owner, pos.angleTo2d<span class="style_symbol">(</span>target<span class="style_symbol">)</span>, SFX<span class="style_symbol">)</span> this.targetAngle = pos.angleTo2d<span class="style_symbol">(</span>target<span class="style_symbol">)</span> this.u = actor this.target = target this.u.pause<span class="style_symbol">(</span><span class="style_symbol">)</span> this.scale = originalScale function startMissile<span class="style_symbol">(</span><span class="style_symbol">)</span> this.setSpeed<span class="style_symbol">(</span><span class="style_int">0</span><span class="style_symbol">)</span> this.pos = pos.offset2d<span class="style_symbol">(</span>pos.angleTo2d<span class="style_symbol">(</span>target<span class="style_symbol">)</span>, offsetDistance<span class="style_symbol">)</span> this.pos.z += <span class="style_int">50</span> this.fixPos<span class="style_symbol">(</span><span class="style_symbol">)</span> this.fx.setColor<span class="style_symbol">(</span>missileCol<span class="style_symbol">)</span> this.fx.setScale<span class="style_symbol">(</span>this.scale<span class="style_symbol">)</span> this.t.setData<span class="style_symbol">(</span>this castTo int<span class="style_symbol">)</span> this.t.startPeriodic<span class="style_symbol">(</span><span class="style_float">.1</span>, function callExpandMissile<span class="style_symbol">)</span> //if dust is activated if this.dustOn this.createDust<span class="style_symbol">(</span><span class="style_symbol">)</span> function createDust<span class="style_symbol">(</span><span class="style_symbol">)</span> effect x = AddSpecialEffectTarget<span class="style_symbol">(</span>dustSFX, u, <span class="style_string">"origin"</span><span class="style_symbol">)</span> DestroyEffectBJ<span class="style_symbol">(</span>x<span class="style_symbol">)</span> static function callExpandMissile<span class="style_symbol">(</span><span class="style_symbol">)</span> <span class="style_symbol">(</span>GetExpiredTimer<span class="style_symbol">(</span><span class="style_symbol">)</span>.getData<span class="style_symbol">(</span><span class="style_symbol">)</span> castTo TimedBlasts<span class="style_symbol">)</span>.expandMissile<span class="style_symbol">(</span><span class="style_symbol">)</span> function expandMissile<span class="style_symbol">(</span><span class="style_symbol">)</span> if this.timeSinceLastChannel == <span class="style_int">0</span> this.u.setAnimation<span class="style_symbol">(</span>channelIndex<span class="style_symbol">)</span> if this.timeSinceLastChannel >= <span class="style_symbol">(</span><span class="style_float">.18</span><span class="style_symbol">)</span> this.u.setAnimation<span class="style_symbol">(</span>channelIndex<span class="style_symbol">)</span> this.timeSinceLastChannel -= <span class="style_symbol">(</span><span class="style_float">.17</span><span class="style_symbol">)</span> this.timeSinceLastChannel += ANIMATION_PERIOD this.scale += <span class="style_float">.05</span> this.fx.setScale<span class="style_symbol">(</span>this.scale<span class="style_symbol">)</span> if this.scale >= endScale if this.flightOn this.u.setFlyHeight<span class="style_symbol">(</span><span class="style_int">0</span>, lowerRate<span class="style_symbol">)</span> if this.launchOn this.createLaunchFX<span class="style_symbol">(</span><span class="style_symbol">)</span> if this.dropOn this.dropSpeed = realDropSpeed this.setSpeed<span class="style_symbol">(</span>speed<span class="style_symbol">)</span> this.t.release<span class="style_symbol">(</span><span class="style_symbol">)</span> this.u.setAnimation<span class="style_symbol">(</span>launchIndex<span class="style_symbol">)</span> PlaySoundOnUnitBJ<span class="style_symbol">(</span>this.throwSound, <span class="style_int">70</span>, this.u<span class="style_symbol">)</span> this.missileCast = true if not this.channeling this.u.unpause<span class="style_symbol">(</span><span class="style_symbol">)</span> if this.clashing this.clashable = true //calculate frequency of trail creation function createLaunchFX<span class="style_symbol">(</span><span class="style_symbol">)</span> Fx launch = new Fx<span class="style_symbol">(</span>fx.getPos2<span class="style_symbol">(</span><span class="style_symbol">)</span>,this.targetAngle, kameLaunch<span class="style_symbol">)</span> launch.setScale<span class="style_symbol">(</span>launchSize<span class="style_symbol">)</span> doAfter<span class="style_symbol">(</span><span class="style_float">.5</span>, <span class="style_symbol">(</span><span class="style_symbol">)</span> -> destroy launch<span class="style_symbol">)</span> function createTrail<span class="style_symbol">(</span><span class="style_symbol">)</span> Fx trail = new Fx<span class="style_symbol">(</span>fx.getPos3d<span class="style_symbol">(</span><span class="style_symbol">)</span>, this.targetAngle, trailSFX<span class="style_symbol">)</span> ..setScale<span class="style_symbol">(</span>trailSize<span class="style_symbol">)</span> ..setColor<span class="style_symbol">(</span>trailCol<span class="style_symbol">)</span> if flightOn == false trail.setZ<span class="style_symbol">(</span><span class="style_int">100</span><span class="style_symbol">)</span> // doAfter<span class="style_symbol">(</span>timeDistance, <span class="style_symbol">(</span><span class="style_symbol">)</span> -> trail.hiddenDestroy<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">)</span> this.trailList.add<span class="style_symbol">(</span>trail<span class="style_symbol">)</span> function createPulse<span class="style_symbol">(</span><span class="style_symbol">)</span> Fx pulse = new Fx<span class="style_symbol">(</span>fx.getPos3d<span class="style_symbol">(</span><span class="style_symbol">)</span>, this.targetAngle, pulseSFX<span class="style_symbol">)</span> ..setScale<span class="style_symbol">(</span>pulseSize<span class="style_symbol">)</span> ..setZAngle<span class="style_symbol">(</span>-<span class="style_int">5200</span><span class="style_symbol">)</span> ..setColor<span class="style_symbol">(</span>pulseCol<span class="style_symbol">)</span> if this.flightOn == false pulse.setZ<span class="style_symbol">(</span><span class="style_int">100</span><span class="style_symbol">)</span> // pulse.getDummy<span class="style_symbol">(</span><span class="style_symbol">)</span>.setAnimation<span class="style_symbol">(</span><span class="style_int">0</span><span class="style_symbol">)</span> doAfter<span class="style_symbol">(</span>timeDistance, <span class="style_symbol">(</span><span class="style_symbol">)</span> -> pulse.hiddenDestroy<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">)</span> override function update<span class="style_symbol">(</span><span class="style_symbol">)</span> super.update<span class="style_symbol">(</span><span class="style_symbol">)</span> //should be speed dependent at some level. if pos.toVec2<span class="style_symbol">(</span><span class="style_symbol">)</span>.distToVecSquared<span class="style_symbol">(</span>target.toVec2<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">)</span> < <span class="style_int">120</span><span class="style_symbol">*</span><span class="style_int">120</span> //timeDistance = <span class="style_float">0.15</span> if this.getSpeed<span class="style_symbol">(</span><span class="style_symbol">)</span> > <span class="style_int">0</span> if this.trailOn if this.timeSinceLastTrail > <span class="style_symbol">(</span><span class="style_int">2</span>/speed<span class="style_symbol">)</span> this.createTrail<span class="style_symbol">(</span><span class="style_symbol">)</span> this.timeSinceLastTrail -= <span class="style_symbol">(</span><span class="style_int">2</span>/speed<span class="style_symbol">)</span> this.timeSinceLastTrail += ANIMATION_PERIOD if this.pulseOn if this.timeSinceLastPulse > <span class="style_symbol">(</span><span class="style_int">2</span>/speed<span class="style_symbol">)</span> this.createPulse<span class="style_symbol">(</span><span class="style_symbol">)</span> this.timeSinceLastPulse -= <span class="style_symbol">(</span><span class="style_int">2</span>/speed<span class="style_symbol">)</span> this.timeSinceLastPulse += ANIMATION_PERIOD if not this.clashed if this.clashable Entity e = Entity.getFirst<span class="style_symbol">(</span><span class="style_symbol">)</span> while e <span class="style_symbol">!</span>= null if e<span class="style_symbol">!</span>= this and this.owner <span class="style_symbol">!</span>= e.owner if this.owner.isAllyOf<span class="style_symbol">(</span>e.owner<span class="style_symbol">)</span> TimedBlasts blast2 = e castTo TimedBlasts if blast2.clashable and not blast2.clashed if this.pos.distToVecSquared<span class="style_symbol">(</span>e.pos<span class="style_symbol">)</span> < <span class="style_float">40000.</span> print<span class="style_symbol">(</span>this.pos.distToVecSquared<span class="style_symbol">(</span>e.pos<span class="style_symbol">)</span>.toString<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">)</span> if this.pos.distToVecSquared<span class="style_symbol">(</span>e.pos<span class="style_symbol">)</span> < <span class="style_symbol">(</span><span class="style_int">120</span><span class="style_symbol">*</span><span class="style_int">120</span><span class="style_symbol">)</span> //print<span class="style_symbol">(</span><span class="style_string">"hi6!"</span><span class="style_symbol">)</span> this.onHit<span class="style_symbol">(</span>blast2<span class="style_symbol">)</span> e=e.next if <span class="style_symbol">(</span><span class="style_symbol">(</span>this.u.getPos<span class="style_symbol">(</span><span class="style_symbol">)</span>.distToVecSquared<span class="style_symbol">(</span>target.toVec2<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">)</span> < <span class="style_int">150</span><span class="style_symbol">*</span><span class="style_int">150</span><span class="style_symbol">)</span> or <span class="style_symbol">(</span>pos.toVec2<span class="style_symbol">(</span><span class="style_symbol">)</span>.distToVecSquared<span class="style_symbol">(</span>target.toVec2<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">)</span> < <span class="style_int">64</span><span class="style_symbol">*</span><span class="style_int">64</span><span class="style_symbol">)</span><span class="style_symbol">)</span> and missileCast for unit enemy from ENUM_GROUP..enumUnitsInRange<span class="style_symbol">(</span>pos.toVec2<span class="style_symbol">(</span><span class="style_symbol">)</span>, impactAoe<span class="style_symbol">)</span> if enemy.isEnemy<span class="style_symbol">(</span>owner<span class="style_symbol">)</span> this.u.damageTarget<span class="style_symbol">(</span>enemy, damage<span class="style_symbol">)</span> done = true terminate<span class="style_symbol">(</span><span class="style_symbol">)</span> function onHit<span class="style_symbol">(</span>TimedBlasts blast2<span class="style_symbol">)</span> boolean winner1 = false boolean winner2 = false //print<span class="style_symbol">(</span><span class="style_string">"hi7!"</span><span class="style_symbol">)</span> this.clashed = true blast2.clashed = true blast2.setSpeed<span class="style_symbol">(</span><span class="style_int">0</span><span class="style_symbol">)</span> this.setSpeed<span class="style_symbol">(</span><span class="style_int">0</span><span class="style_symbol">)</span> blast2.active = false this.active = false //this.fx.setScale<span class="style_symbol">(</span>endScale+ <span class="style_int">1</span><span class="style_symbol">)</span> //blast2.fx.setScale<span class="style_symbol">(</span>endScale+ <span class="style_int">1</span><span class="style_symbol">)</span> doPeriodically<span class="style_symbol">(</span><span class="style_float">.25</span>, <span class="style_symbol">(</span>CallbackPeriodic cb<span class="style_symbol">)</span> -> begin Fx effect1 = new Fx<span class="style_symbol">(</span>fx.getPos2<span class="style_symbol">(</span><span class="style_symbol">)</span>,this.targetAngle, iceNova<span class="style_symbol">)</span> ..setScale<span class="style_symbol">(</span><span class="style_float">1.8</span><span class="style_symbol">)</span> ..setZ<span class="style_symbol">(</span><span class="style_int">100</span><span class="style_symbol">)</span> ..setZAngle<span class="style_symbol">(</span>-<span class="style_int">5200</span><span class="style_symbol">)</span> Fx effect2 = new Fx<span class="style_symbol">(</span>blast2.fx.getPos2<span class="style_symbol">(</span><span class="style_symbol">)</span>,this.targetAngle, iceNova<span class="style_symbol">)</span> ..setScale<span class="style_symbol">(</span><span class="style_float">1.8</span><span class="style_symbol">)</span> ..setZ<span class="style_symbol">(</span><span class="style_int">100</span><span class="style_symbol">)</span> ..setZAngle<span class="style_symbol">(</span>-<span class="style_int">5200</span><span class="style_symbol">)</span> Fx effect5 = new Fx<span class="style_symbol">(</span><span class="style_symbol">(</span><span class="style_symbol">(</span>fx.getPos2<span class="style_symbol">(</span><span class="style_symbol">)</span> + blast2.fx.getPos2<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">)</span> <span class="style_symbol">*</span><span class="style_float">.5</span><span class="style_symbol">)</span>.toVec3<span class="style_symbol">(</span><span class="style_symbol">)</span>.addReals<span class="style_symbol">(</span><span class="style_int">0</span>, <span class="style_int">0</span>, <span class="style_int">50</span><span class="style_symbol">)</span>, this.targetAngle, sparklyExplosion<span class="style_symbol">)</span> ..setScale<span class="style_symbol">(</span><span class="style_int">5</span><span class="style_symbol">)</span> doAfter<span class="style_symbol">(</span><span class="style_float">.25</span>, <span class="style_symbol">(</span><span class="style_symbol">)</span> -> begin destroy<span class="style_symbol">(</span>effect1<span class="style_symbol">)</span> destroy<span class="style_symbol">(</span>effect2<span class="style_symbol">)</span> destroy<span class="style_symbol">(</span>effect5<span class="style_symbol">)</span> end<span class="style_symbol">)</span> if this.u.getMana<span class="style_symbol">(</span><span class="style_symbol">)</span> == <span class="style_int">0</span> winner2 = true if blast2.u.getMana<span class="style_symbol">(</span><span class="style_symbol">)</span> == <span class="style_int">0</span> winner1 = true this.u.setMana<span class="style_symbol">(</span>u.getMana<span class="style_symbol">(</span><span class="style_symbol">)</span>-<span class="style_int">1</span><span class="style_symbol">)</span> blast2.u.setMana<span class="style_symbol">(</span>blast2.u.getMana<span class="style_symbol">(</span><span class="style_symbol">)</span>-<span class="style_int">2</span><span class="style_symbol">)</span> if winner1 print<span class="style_symbol">(</span>this.u.getName<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">)</span> blast2.terminate<span class="style_symbol">(</span><span class="style_symbol">)</span> this.target = blast2.u.getPos3<span class="style_symbol">(</span><span class="style_symbol">)</span> this.setSpeed<span class="style_symbol">(</span>this.speed<span class="style_symbol">)</span> this.active = true destroy cb if winner2 and not winner1 print<span class="style_symbol">(</span>blast2.u.getName<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">)</span> terminate<span class="style_symbol">(</span><span class="style_symbol">)</span> blast2.target = this.u.getPos3<span class="style_symbol">(</span><span class="style_symbol">)</span> blast2.setSpeed<span class="style_symbol">(</span>blast2.speed<span class="style_symbol">)</span> blast2.active = true destroy cb end<span class="style_symbol">)</span> ondestroy if this.channeling this.u.unpause<span class="style_symbol">(</span><span class="style_symbol">)</span> Fx final = new Fx<span class="style_symbol">(</span>fx.getPos3d<span class="style_symbol">(</span><span class="style_symbol">)</span>, this.targetAngle, finalSFX<span class="style_symbol">)</span> final.setScale<span class="style_symbol">(</span><span class="style_int">2</span><span class="style_symbol">)</span> doAfter<span class="style_symbol">(</span>destroyExplode, <span class="style_symbol">(</span><span class="style_symbol">)</span> -> final.hiddenDestroy<span class="style_symbol">(</span><span class="style_symbol">)</span><span class="style_symbol">)</span> for i = <span class="style_int">0</span> to <span class="style_symbol">(</span>this.trailList.getSize<span class="style_symbol">(</span><span class="style_symbol">)</span> -<span class="style_int">1</span><span class="style_symbol">)</span> this.trailList.get<span class="style_symbol">(</span>i<span class="style_symbol">)</span>.hiddenDestroy<span class="style_symbol">(</span><span class="style_symbol">)</span> this.done = true package Kamehameha import Constants import TimedBlasts constant real originalScale = <span class="style_float">.2</span> public class Kamehameha extends TimedBlasts construct<span class="style_symbol">(</span>unit actor,vec3 pos, player owner, vec3 target, int level<span class="style_symbol">)</span> super<span class="style_symbol">(</span>actor,pos.addReals<span class="style_symbol">(</span><span class="style_int">0</span>, <span class="style_int">0</span>, <span class="style_int">50</span><span class="style_symbol">)</span>,owner,target,bigKamehamehaBall,originalScale<span class="style_symbol">)</span> //if <span class="style_symbol">(</span>actor.getTypeId<span class="style_symbol">(</span><span class="style_symbol">)</span> == <span class="style_comment">'H001')</span> this.impactAoe = <span class="style_int">500</span> this.damage = <span class="style_int">150</span><span class="style_symbol">*</span>level.toReal<span class="style_symbol">(</span><span class="style_symbol">)</span> + <span class="style_symbol">(</span>GetHeroInt<span class="style_symbol">(</span>actor, true<span class="style_symbol">)</span><span class="style_symbol">*</span><span class="style_int">10</span><span class="style_symbol">)</span> this.trailOn = true this.dustOn = true this.pulseOn = true this.launchOn = true int actorID = actor.getTypeId<span class="style_symbol">(</span><span class="style_symbol">)</span> if actorID == <span class="style_comment">'H000'</span> this.channelIndex = <span class="style_int">11</span> this.launchIndex = <span class="style_int">12</span> this.throwSound = gg_snd_Kamehameha_Voice if actorID == <span class="style_comment">'H005' or actorID == 'H009'</span> this.channelIndex = <span class="style_int">20</span> this.launchIndex = <span class="style_int">18</span> if actorID == <span class="style_comment">'H00A'</span> this.channelIndex = <span class="style_int">5</span> this.launchIndex = <span class="style_int">4</span> if actorID == <span class="style_comment">'H001' or actorID == 'H008'</span> this.channelIndex = <span class="style_int">7</span> this.launchIndex = <span class="style_int">8</span> this.throwSound = gg_snd_GohanKame if actorID == <span class="style_comment">'H00D' or actorID == 'H00E' or actorID == 'H00F'</span> this.channelIndex = <span class="style_int">8</span> this.launchIndex = <span class="style_int">12</span> if actorID == <span class="style_comment">'H007'</span> this.channelIndex = <span class="style_int">9</span> this.launchIndex = <span class="style_int">13</span> if actorID == <span class="style_comment">'H00G'</span> this.channelIndex = <span class="style_int">12</span> this.launchIndex = <span class="style_int">11</span> this.speed = <span class="style_int">32</span> this.endScale = <span class="style_float">.6</span> this.trailSFX = bigKamehamehaBall this.trailSize = <span class="style_float">.3</span> this.pulseSFX = bluePulse this.launchSFX = kameLaunch this.launchSize = <span class="style_int">5</span> this.finalSFX = bigBlueExplosion this.pulseSize = <span class="style_int">1</span> this.trailCol = colorA<span class="style_symbol">(</span><span class="style_int">255</span>,<span class="style_int">255</span>,<span class="style_int">255</span>,<span class="style_int">255</span><span class="style_symbol">)</span> this.clashing = true this.channeling = true startMissile<span class="style_symbol">(</span><span class="style_symbol">)</span> package AngryKame import Constants import TimedBlasts import ClosureTimers constant real originalScale = <span class="style_float">.2</span> public class AngryKame extends TimedBlasts construct<span class="style_symbol">(</span>unit actor,vec3 pos, player owner, vec3 target, int level<span class="style_symbol">)</span> super<span class="style_symbol">(</span>actor,pos.addReals<span class="style_symbol">(</span><span class="style_int">0</span>, <span class="style_int">0</span>, <span class="style_int">700</span><span class="style_symbol">)</span>,owner,target,dummy2,originalScale<span class="style_symbol">)</span> this.impactAoe = <span class="style_int">500</span> actor.setFlyHeight<span class="style_symbol">(</span><span class="style_int">700</span>, <span class="style_float">700.</span><span class="style_symbol">)</span> this.flightOn = true this.dropOn = true this.offsetDistance = <span class="style_int">0</span> this.missileCol = colorA<span class="style_symbol">(</span><span class="style_int">150</span>,<span class="style_int">150</span>,<span class="style_int">0</span>,<span class="style_int">255</span><span class="style_symbol">)</span> this.speed = <span class="style_int">25</span> this.endScale = <span class="style_float">1.5</span> this.dustSFX = dustWave this.damage = <span class="style_int">5000</span><span class="style_symbol">*</span>level.toReal<span class="style_symbol">(</span><span class="style_symbol">)</span> + <span class="style_symbol">(</span>GetHeroInt<span class="style_symbol">(</span>actor, true<span class="style_symbol">)</span><span class="style_symbol">*</span><span class="style_int">20</span><span class="style_symbol">)</span> this.finalSFX = nuclearExplosion this.trailOn = true this.dustOn = true this.pulseOn = true this.launchOn = false this.channelIndex = <span class="style_int">20</span> this.launchIndex = <span class="style_int">10</span> this.trailSFX = pinkBall this.trailSize = <span class="style_float">.6</span> this.launchSFX = kameLaunch this.launchSize = <span class="style_int">5</span> this.trailCol = colorA<span class="style_symbol">(</span><span class="style_int">150</span>,<span class="style_int">150</span>,<span class="style_int">0</span>,<span class="style_int">255</span><span class="style_symbol">)</span> this.lowerRate = <span class="style_float">300.</span> this.realDropSpeed = -<span class="style_int">25</span> this.destroyExplode = <span class="style_int">3</span> this.pulseSFX = windBlue this.pulseSize = <span class="style_float">1.2</span> this.pulseCol = colorA<span class="style_symbol">(</span><span class="style_int">150</span>,<span class="style_int">150</span>,<span class="style_int">0</span>,<span class="style_int">255</span><span class="style_symbol">)</span> effect x = AddSpecialEffectTarget<span class="style_symbol">(</span>kamelightning, u, <span class="style_string">"origin"</span><span class="style_symbol">)</span> doAfter<span class="style_symbol">(</span><span class="style_float">1.5</span>, <span class="style_symbol">(</span><span class="style_symbol">)</span> -> begin doAfter<span class="style_symbol">(</span><span class="style_int">1</span>, <span class="style_symbol">(</span><span class="style_symbol">)</span> -> begin PlaySoundOnUnitBJ<span class="style_symbol">(</span>gg_snd_angrykame, <span class="style_int">70</span>, this.u<span class="style_symbol">)</span> end<span class="style_symbol">)</span> startMissile<span class="style_symbol">(</span><span class="style_symbol">)</span> fx.setFx<span class="style_symbol">(</span>pinkBall<span class="style_symbol">)</span> end<span class="style_symbol">)</span> doAfter<span class="style_symbol">(</span><span class="style_int">12</span>, <span class="style_symbol">(</span><span class="style_symbol">)</span> -> begin DestroyEffectBJ<span class="style_symbol">(</span>x<span class="style_symbol">)</span> end<span class="style_symbol">)</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)