( I’ll give it a better name when I think of one. )
I’ve been playing several xcom games recently and its made me want to create my own such project. I’ve never made this kind of game before so it could be a fun challenge!
Let’s jump right into it.
First, the world. I want it to be procedural.
It bothers me how every game of UFO defense, with exception to unique playthroughs like the Antarctic challenge, almost always begins with a base in the US. This happens because the US provides the best funding and as such it’s objectively the best place to defend.
Every country is important, of course, but you obviously want to prioritize helping the ones that give you the most money first. This is especially true on harder difficulties!
I want to eliminate this minor source of repetition by scrambling the world map.
Instead of going for the same map strategy each playthrough, the player will be forced to analyze each playthrough as a unique situation and formulate new strategies as needed.
This may not sound like a big deal at first, but what if there’s no big country that provides a ton of funding? You’ll have to spread yourself thin defending a bunch of small countries!
I’m also hoping this extra step of randomization, and the many others I’ll be adding later, will help maintain that underdog vibe the xcom games possess. Theirs only so much I can do to keep a player on-edge after their millionth playthrough, but I can nevertheless try.
In the name of progress, I’ll keep things simple. Their will only be two terrain types: land and water. Eventually, though, I’ll add, forests, deserts, cities, and all sorts of other terrains.
In the distant future, their will even be alien landscapes as they begin to terraform Earth.
Here is an animation of the world being built.

Also, here is what the heightmap looks like. Dark areas are low, bright areas are high.

Long story short: I create two different sets of big noise and mix them together. Then I create two sets of small noise and mix those. I then mix these two mixes’ of noise with a circle. This gives the central island shape. Then I do a bit of erosion to scuff the results edges up a little.
It’s not what I wanted, at all, but after a couple of hours of fiddling with the map generator I decided enough time has been wasted and just implemented something I know looks good.
The result I actually wanted was something more Earth-like. I wanted a handful of gigantic continents and some nearby small islands. The result I kept getting, though, was either too stringy or too blobby. I also didn’t want the landmasses touching the map edges.

This is what things look like when it’s all said and done. Tiny islands are turned into water, tiny lakes are turned into land, and the edges are smoothed with a small gaussian blur.

What’s next? There’s a million things I could potentially do, but I want something playable as soon as possible. That means its time to place the location of your first base!
However, upon second thought, I realized that adding the ability to place a base would be a decent amount of work. It would require a new menu, interface elements, user mouse input, a base object, and probably some other bothersome stuff. The location doesn’t matter right now since there’s no countries to protect, so I’m going to be lazy and just randomly place it.
Poof. There’s a base now.

I’m using a random seed, by the way, so the map will be changing between screenshots.
Anyway, let’s click on the base. That will bring us to the hideous base management menu.

Looks pretty strange, huh? It’s almost as if I was inspired by something.

I’ll add some nicer ascii graphics at some point. I’m going to add a radar building next.

The radar has been created, but it’s useless. It’s just a generic building object. I’d like to make it functional, but there’s no aliens for it to detect, so the next step is pretty obvious.
I’m going to return to the world map and add some alien ships moving around. For now, their only purpose is to be detected by the radar. The aliens generate random waypoints and then they path to those waypoints. Upon reaching it, they’ll get a new waypoint. Rinse and repeat.

Here we go. The alien ships that enter the radars detection range while aimlessly moving around turn red to indicate they’ve been detected. I also draw a line because it looks cool.
The next thing I’m going to add is scrambling fighters to take the alien ships down. I could easily implement a half assed development version of this to save time, but I’m having fun.

Fighters are automatically launched whenever a threat enters radar range. In the future, the player will have to manually decide when to launch. I’m not going to bother adding a combat system yet, so for now the interceptors always destroy the alien ship once they’re in range.
To prevent the map from being filed with interceptors, I only ever allow one to be active at a time. They must return to base after a successful kill before being launched for a new hunt.
I think an example gif was supposed to go here but I seem to have misplaced it.
Instead of yeeting the aliens from existence when they’re shot down, I’m going to have them crash. This won’t serve any purpose right now, but eventually the player will be able to send their soldiers to investigate the crash site and salvage it for critically important alien supplies.

The orange aliens have been shot down. I also gave them circular icons because saucers.
What’s next? Everything you do in these games is to protect your bottom line, so I guess I’ll start working on the monetary front of things. It’s time to add some countries and their funds.
First, I need to split the map into quadrants. Each country needs to be relatively spaced out, and while I could use distance calculations, collision detections and other overly complicated sounding non-sense to achieve this, I’m just going to use a binary space partition.
What’s that you ask? It splits a space into a bunch of rectangles, basically.

I’m going to place a faction (country) at the center of each rectangle next.

Then I’m going to erase any rectangles that have mostly water beneath them.

In order to exist, a country needs to have at-least 100 land pixels within its rectangle.
This removed most of the sillier countries where their only claim to fame is a single pixel of land on some random corner. I also spaced the countries out so they’re nicer on the eyes.
I’m going to remove any countries whose center most coordinate isn’t land next.

This is good enough for now. I was planning to do a floodfill to generate country borders, but after hours of work it still looks awful. It’s also slow enough to be annoying. I’ll report back at a future date when I either improve the floodfill or discover a better way to create borders.


I’ve returned to the ugly rectangles, but this time they’re actually proper countries. I’ve given them colors, and to finally get back on topic, they also possess a random funds variable.
Speaking of funds, the aliens can now attack countries.
They still wander around randomly, but every time they reach a waypoint they’ll land and do some damage to the below country. This process takes 6,000 frames. If they’re intercepted before the timer is up, then the country is spared. Else, they’ll reduce their funding a little.
Countries repair themselves over time, so a few attacks aren’t the end of the world. Their current funding might be reduced but it will slowly tick back upwards towards the old value.
To add even more oomph to the importance of protecting countries, they will cease to exist upon reaching zero funds. This puts the player in a situation with real consequence. If they routinely fail to protect a country then it will permanently collapse and that money is gone.
I’ve also added a new human ship: the bomber. It will automatically go after any landed alien saucers and destroy them. Currently, this is the only means of preventing landed ships from damaging a countries funds. Eventually, though, you’ll be able to send a lander full of troops.
The idea behind the bombers is that their will sometimes be too many downed aliens for you to deal with. It’s better to just bomb them into oblivion than ignore them, as crashed saucers will eventually be rescued by a recovery ship and resume doing fun apocalyptic alien stuff.
In addition, both interceptors and bombers are only able to attack alien ships that are within radar range. This is a step towards making base placement matter. More importantly, it’s a reason for the player to eventually have multiple bases so they can cover more countries.
Finally, alien detection chance via the radar has become chance based. If discovered aliens leave the detection radius then they have a chance to become undetected, too. Interceptors and bombers will automatically disengage if the target vanishes from radar.
Phew. That was a mouthful. Here is everything I just talked about in one big animation.

I dramatically increased the amount of aliens and unlocked how many ships the humans can launch. This makes it easier to get a feel for the simulation without having to wait all day.
I’m sorry if this last update was a bit confusing. I went on a coding spree and forgot to make incremental blog updates, so I had to jam everything into a big wall of text and sped up gif.
This post has gotten so long in the tooth that the wordpress editor is imploding with lag due to all the text blocks. Ill see you in the next post where I’ll begin adding player interaction.