Following on from my previous post about using MS Excel to generate a Pacman maze in Unity, I was wondering what would happen if you took the data from an old Spectrum tape, wack it through my spreadsheet (with a bit of tweaking I might add ) and then into Unity ?
Awesomeness is the answer. You can take a walk around Antescher here.
Ant Attack is arguably the first true 3D isometric video game. Written by Sandy White in 1983, the game sees you having to rescue your beloved from the city of Antescher. The city itself is inhabited naturally by giant ants.
Before jumping into how this was done and what on earth has it got to do with my remake of Into the Eagles Nest. I would like to say one thing.
The design of the level is brilliant. I have enjoyed just walking around and looking at all the brutalist structures that occupy the city. I am half expecting to stumble across the Colosseo Quadrato
in there.(actually we could do that...)The how and the Why
I started taking my code from the Pacman generator and began turning it into something more substantial. I want to be able to use it, amongst other things with the Village interiors Kit by 3D forge and this proposes a challenge. I won't bore you with the details but there is some scaling involved , a huge array of pieces to choose from and some corner pieces to deal with.
In the Pacman example we used "w" for wall and "d" for dot. The solution I need is going to require a lot more information than that . Whilst I could use a simple key/legend, that key is going to become quite big and complicated very very quickly.
So my mind was wondering about using some bit operators in there ( i.e. 1 = North wall, 2 = East, 4 = South,8=West etc) and through my code I could deal with the problem of corners quite easily(as I have x,y coordinates already). Out of curiosity, I googled how 8 bit games used to store 3D data, and stumbled across Ant Attack.
Now, I am no stranger to the game. I remember this fondly along with its less appreciated sibling Zombie Zombie. What I did not know, was that this game was written in assembly - by hand
Now the data for the city of Anteschter is stored in an array 128 by 128 (food for thought, this took up just 16K of data) and what particular interested me was how this data was stored.
Take a look at the following
63,63,7,7,63,63
We will go for the easy win first. The door way is six blocks wide, and there are six numbers. Here is your medal if you spotted that already. So how do we know what to build along our Y axis ? If you convert 63 into Binary you get the following *
111111
if you convert 51 to Binary you get
111000
so 63,63,51,51,63,63 in binary get us
Its nice and its simple.
* (the original ant attack game only used six bits - before anyone starts throwing their 1's and 0's around their pram)
In the Pacman example we used "w" for wall and "d" for dot. The solution I need is going to require a lot more information than that . Whilst I could use a simple key/legend, that key is going to become quite big and complicated very very quickly.
So my mind was wondering about using some bit operators in there ( i.e. 1 = North wall, 2 = East, 4 = South,8=West etc) and through my code I could deal with the problem of corners quite easily(as I have x,y coordinates already). Out of curiosity, I googled how 8 bit games used to store 3D data, and stumbled across Ant Attack.
Now, I am no stranger to the game. I remember this fondly along with its less appreciated sibling Zombie Zombie. What I did not know, was that this game was written in assembly - by hand
Now the data for the city of Anteschter is stored in an array 128 by 128 (food for thought, this took up just 16K of data) and what particular interested me was how this data was stored.
Take a look at the following
63,63,7,7,63,63
63,63,51,51,63,63
48,48,48,4848,48
63,63,63,,63,63,63
Mean anything ? thought not but that is actually a window frame, a doorway, a short wall and a full wall which all look like this.
What is particular nice about this is the use of the numbers; lets take a look at the doorway.
63,63,51,51,63,63
111111
if you convert 51 to Binary you get
111000
so 63,63,51,51,63,63 in binary get us
Its nice and its simple.
* (the original ant attack game only used six bits - before anyone starts throwing their 1's and 0's around their pram)
Moving onto Ant Attack
Ripping the data from the original Ant Attack has been done by many people and most of the links I could find refer back to a Tyrone C. Unfortunately the web link (whimsy.demon .co .uk) is no longer active. Somewhere along the line someone by the name of Carlos Sorilo wrote a Python script to extract the map data from the original tape. This script is below
#! /usr/bin/python
file = open("ant.sna", "rb")
file.seek( 32795 );
buf=file.read()
print "map=["
for y in range(0,128):
print ("["),
for x in range(0,128):
print (ord(buf[x+y*128])),
print (","),
print "],"
print "];"
There are instructions for running the script here along with code, which is also from Carlos for creating Antescher in OpenSCAD. (if you click on the first link mentioned in this section, you can find the data extracted in the thingiverse model)
Loading the data into Excel looks something likes this (I've used conditional formatting to make it a bit more visible).
Going back to the code I used to create the Pacman level, it is pretty much the same this time around except for, in the original code we were stringing together Instantiate statements. This time, I have written a function to convert the decimal values into binary.
We also last time copied pasted the values generated straight into a class. With 11,000 odd lines now, I have changed it to write to a text file instead.
Now you could just load the original tape data straight into Unity and do the decimal to binary straight there, but what I am after is an editor and to proves that this work;
The text file that my spreadsheet file creates destination is the resource folder within my Unity project. My code in Unity loads the text file from the resource folder and just using regular expressions takes the binary number to build the cubes.
So say I wanted to add my initials to the bottom of the map and make them one cube high ?
All I do, is spell my initials with the value 1 (1 d2b=0000001) where I want my initials to be in the spreadsheet.
Run my code and Kazaam! my initials now appear in the city of Antescher
I can definitely see this workflow as a very quick way to create primitive maps within Unity. My next step with this approach will be utilising assets and attempting to build my Eagles Nest Layer.
Loading the data into Excel looks something likes this (I've used conditional formatting to make it a bit more visible).
Going back to the code I used to create the Pacman level, it is pretty much the same this time around except for, in the original code we were stringing together Instantiate statements. This time, I have written a function to convert the decimal values into binary.
We also last time copied pasted the values generated straight into a class. With 11,000 odd lines now, I have changed it to write to a text file instead.
Now you could just load the original tape data straight into Unity and do the decimal to binary straight there, but what I am after is an editor and to proves that this work;
The text file that my spreadsheet file creates destination is the resource folder within my Unity project. My code in Unity loads the text file from the resource folder and just using regular expressions takes the binary number to build the cubes.
So say I wanted to add my initials to the bottom of the map and make them one cube high ?
All I do, is spell my initials with the value 1 (1 d2b=0000001) where I want my initials to be in the spreadsheet.
Run my code and Kazaam! my initials now appear in the city of Antescher
Conclusion
It's not pretty, but one thing that drives me nuts in Unity is placing primitives. There you are thinking you placed a wall on the ground to only find its actually a 100 foot up in the air.- Typing numbers in a spreadsheet is way easier.
- If you want to extend your wall exactly one cube to the right ? just type in the cell to the right.
- Want to add a door or a window to your wall ? just change the numbers
I can definitely see this workflow as a very quick way to create primitive maps within Unity. My next step with this approach will be utilising assets and attempting to build my Eagles Nest Layer.
Some Notes
- If you do have a go at creating your own Antescher level, there is some 11,000 cube objects that will be created from the original map. I highly recommend creating a parent object
- Rather than run the code at run time, run it [Execute In Edit Mode]
- This drove me nuts, as I use both a mac and a PC. Where I was using /n with Regex to move between the lines of my text file , when I switched to my mac this did not work. However using /r did.
Finally.
If you want to have a look at some other interpretations of Antescher
Comments
Post a Comment