Code for doing Explosions

Playing FortressCraft Evolved, I played with explosives.  I was not particularly happy with how the explosives were handled – and I was on vacation, and I had no internet access, so my creativity got into my brain and I tried writing code that would handle explosions better.

I shoved the code here:  https://github.com/sunnywiz/explosion2d

Here’s the basics of what I did:

  • I did this in 2D instead of 3D because easier to Console.WriteLine()
  • I created a TwoDSpace<T> so I could store an arbitrarily large number of T’s in a 2-D plane
  • I created a function which mapped out, given a center 0,0, what the distances were to each X,Y. 
    • I kept distances as squares, so I didn’t have to do square roots.
    • I did it with an initial max-radius, but the final version in my head would jit-figure out what it needs and save the resulting calculations in a static – it only needs to calculate it once.  Bigger explosion might need to calculate some more.  
  • That function can then call to a lambda, giving it:
    • the X,Y of the point that is being visited by the explosion
    • an array of parent points for the explosion and the ratios by which to weight them
  • The caller then says, “circle visit an explosion starting from here”, and keeps track of the force per X,Y that is being experienced.  The caller is responsible for all the code that says “Ores are hard, but dirt is soft”, for example, or “Diamond cannot be damaged by the explosion”
  • I think its pretty fast. O(r^2), which given its a 2D explosion in 2D, is expected. 

Fun Fun stuff.   I miss the days of mud coding.   You just don’t need to do explosions like these in real-world paid programming.

Tagged with: , , ,
Posted in Code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories
Tags
.net 3d 3d-printing 4k abc15 algorithms ames android anonymous types asp.net audio editing aws backup basecamp beatunes biorhythm bittorrent blender blog boston marathon bpm c# caffeine campfire candycrush car carmax charity chiropractor cities-skylines clog clone codelouisville codepalousa coding coffee collaboration color run ComputerElbow ComputerVision configuration consulting cooking crash course crashplan crestwood cycling dabda dan dapper DataSet ddl diabetes dictation dotnetcore dotnetmud downtown e-cycling elite excel exercise expiration facebook feature-branching firefall flipflops Flow FL Studio focus food forecastle fortresscraft franklinplanner gadgets game-design games git github google docs google maps gopro gps grandpa greenshot hack half marathon headless health heart rate hiren ignew integration testing interop inventory ios ipad itunes javascript jobs karma kdf keyboards keys kittens lamont laptop lavalamp lego life lifehack linq linqtotwitter linux los angeles louisville mandelbulber massage therapy mastery-teaching maths merge metformin Minecraft miniature modeling monitor mud muhammad ali institute music mvc mycartracks netfabb nexus10 node nostalgia nutrition nwipe oldham county grand slam opal openjscad openscad owin pacedj paper mockup pepakura performance photoscan politics pomodoro postgresql powershell premiere prius process product-management project-management qa resharper review rmi roman road 5k RSI rubiks running samsung 700t sandals schedule scooter scribblelive selenium service shapeways sleep slic3r sneakersync snot software software-engineering solidoodle soylent spacegame speaking sql sqlite SSDT SSIS standing state-machine stayfocusd stonehearth sunset tablet teaching team teamcity teamtreehouse terraform testing tfs time timelapse torque touch tracks trs80 Tuple tutor twitter ubuntu unit testing utilities video video editing visual studio vscode vsvim warp stabilizer windows 8 windows home server wordpress wpf xml
Archives
%d bloggers like this: