Last active
July 19, 2019 11:40
-
-
Save howardjones/b4e4139c8f154797c1c58358138e9d34 to your computer and use it in GitHub Desktop.
A Unity 5 script to load a ZX Spectrum snapshot file of Sandy White's Ant Attack 3D, extract the map, and create it in the current scene. The ANTATTAK resource is a SNA file imported into Unity. 'floor' is a GameObject for each 1x1x1 cube, textured with a stone texture. The loader creates clones of this.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class MapLoader : MonoBehaviour | |
{ | |
public GameObject floor; | |
bool IsBitSet (byte b, int pos) | |
{ | |
return (b & (1 << pos)) != 0; | |
} | |
// Use this for initialization | |
void Start () | |
{ | |
TextAsset mapdata = Resources.Load ("ANTATTAK") as TextAsset; | |
byte[] map = mapdata.bytes; | |
for (int x=0; x<128; x++) { | |
for (int z=0; z<128; z++) { | |
int n = 32795 + x * 128 + z; | |
if (map [n] > 0) { | |
for (int m=0; m<6; m++) { | |
if (IsBitSet (map [n], m)) { | |
float xx = ((float)x - 64.0f); | |
float zz = ((float)z - 64.0f); | |
float yy = (float)m; | |
Instantiate (floor, new Vector3 (xx, yy, zz), Quaternion.identity); | |
} | |
} | |
} | |
} | |
} | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment