15 Mar 2018

Balls of War

A simulation with a little AI and a lot of bullets.

History

A long, long time ago I was trying to kill some time and simultaneously convince my little brother that programming was cool and fun. Well, I can’t remember exactly why he sat still for me to code this project up, but I think he did. I started with some circles on screen that could shoot at eachother. Each circle could shoot within a 15 degree arc and hopefully hit their target. That’s all they could do. After a certain number of hits, a circle would be eliminated. There were only two teams at the time: red and blue. We ran the simulation over and over rooting for whichever team looked like it was doing the best.

The first version of the code I whipped up was written in “DarkBASIC”, which is a procedural language similar to BASIC that was provided along with an IDE by TheGameCreators way back in the day (at least it feels like a life time ago). DarkBASIC is the formative experience that got me into programming and directed my interests toward 2D and 3D programming. I’ve written about it more in another blog post.


Video

This is a video of the most recent version of what I titled “Balls of War”. I timestamped it to start at 54 seconds because I definitely didn’t put too much effort into recording this back when I did.


Evolution of Balls of War

Like many of my projects, the scope of this one grew much faster than I could keep up with. I kept inventing new stats for my units, which required new systems and so much code refactoring that the Ship of Theseus comes to mind. Eventually, I added a team editor with a “state-of-the-art” interface for picking stats and pitting different teams (up to 8) against eachother.

Unit Stats

  • Health - How much damage the unit can take befor it is eliminated
  • Vitality - How fast the unit regenerates health over time
  • Strength - How much damage bullets shot by this unit inflict on other units that get hit
  • Agility - How fast the unit moves away from the nearest bullet (so they dodge some bullets)
  • Speed - How many shots the unit fires per some unit of time (5 seconds, I think)
  • Spread - The number of degrees of the arc in which the unit’s bullets are randomly fired
  • Multishot - The number of bullets a unit shoots at a time (evenly spaced across firing arc)
  • Weapon Type - Which type of bullet the unit fires

Weapon Types

  • Normal - Bullets fire in a straight line and disappear after hitting a target ( or leaving the field)
  • Orbital - Bullets track the target at which they were originally aimed and whirlpool inward on them
  • Gravitational - Bullets continuously evaluate the nearest target and are attracted toward that target
  • Fractal - Bullets travel a short distance and then split in two and then continue to do this (very OP)
  • Piercing - Similar to normal bullets but they keep going after hitting their first target

My favorite type by far is the gravitational one. I initially had them gravitate toward all available targets, but that ended up being computationally heavy and didn’t look as good as choose-the-nearest.


Code

The code for this project is available on my github (here). This project is old. I made it in high school and I have since improved my programming abilities quite a bit. All things considered, it’s pretty impressive though.