ID:171378
 
Okay people i need to know can someone give me the EASIEST code for round explosions?(like the ones in MJ when a pet dies or in SG2)Ive been stuck on this for a while. Someone plz help?
Reinhartstar wrote:
Okay people i need to know can someone give me the EASIEST code for round explosions?(like the ones in MJ when a pet dies or in SG2)Ive been stuck on this for a while. Someone plz help?

Easiest code:
proc/CreateRoundEffect(atom/center, radius, effecttype)
var/rsq = radius * (radius+1)
for(var/turf/T in range(radius, center))
var/dx = T.x - center.x
var/dy = T.y - center.y
if(dx*dx + dy*dy <= rsq)
new effecttype(T)

If you want to do more with those turfs than just a visual effect, consult AbyssDragon.BasicMath.

[edit]
To explain better what's going on here, I'll add some details. A circle would be defined by (x-h)2&nbsp;+&nbsp;(y-k)2&nbsp;<=&nbsp;r2, where (h,k) are the coordinates of the center and r is the radius. That's where the var rsq comes in: r squared. However, if you stick with strictly r2, you'll find that only the very tips reach exactly that far, but just a little to the right or left you'll be outside that range, like this:
   #
#####
#####
#######
#####
#####
#

That doesn't look very round. The solution is to use a fudge factor, and treat r as if it's larger than it is. So instead of, in this example, r=3, we'll pretend it's 3.5. (r+0.5)2&nbsp;=&nbsp;r2&nbsp;+&nbsp;r&nbsp;+&nbsp;0.25. We don't have to worry about the 0.25, since dx and dy are always whole numbers. So, for our purposes a fudged rsq of (r+0.5)2 is equivalent to r2&nbsp;+&nbsp;r, or r(r+1). Using this in place of r2 gives the circle a more rounded appearance.

Lummox JR