public void OnCreate(Dictionary <string, PICTURES> sprites, THINGS thing, Dictionary <string, AudioClip> sounds) { player = GameObject.FindGameObjectWithTag("Player"); this.thing = thing; actor = GetComponent <Actor>(); health = actor.Health; //sets the health of the actor transform.rotation = Quaternion.Euler(0, 360f - (thing.angle - 90), 0); gameObject.name = actor.Name; target = player.transform;//this can change if the thing gets hurt by something other than the player rb = GetComponent <Rigidbody>(); tag = "Monster"; //place the actor on the ceiling if it has the SPAWNCEILING flag set if (actor.SPAWNCEILING) { RaycastHit hit; if (Physics.Raycast(new Vector3(transform.position.x, -1000, transform.position.z), Vector3.up, out hit)) { transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z); } } if (actor.SOLID)//if the actor isnt solid, it shouldnt have a collider { BoxCollider collider = gameObject.AddComponent <BoxCollider>(); collider.size = new Vector3(actor.Radius * 2, actor.Height, actor.Radius * 2); collider.center = new Vector3(0, actor.Height / 2f, 0); } //if its a monster essentially if (rb) { rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ; rb.mass = actor.Mass; } sprObj = new GameObject("sprite"); sprObj.transform.parent = transform; sprObj.transform.position = transform.position; this.mesh = createPlane(); MeshFilter mf = sprObj.AddComponent <MeshFilter>(); mr = sprObj.AddComponent <MeshRenderer>(); mr.material = new Material(Shader.Find("Custom/DoomShaderTransparent")); mf.mesh = this.mesh; Light lightObj = new GameObject("lightObj").AddComponent <Light>(); lightObj.transform.parent = transform; lightObj.gameObject.transform.localPosition = Vector3.zero; AddSounds(sounds); stateController = new StateController(actor, sprites, audioSource, sprObj, lightObj); stateController.UpdateMaterial(mr.material, 1); }
//TODO: SOUNDS public void OnCreate(Dictionary <string, PICTURES> sprites, THINGS thing, Dictionary <string, AudioClip> snds) { player = GameObject.FindGameObjectWithTag("Player"); this.thing = thing; actor = GetComponent <Actor>(); sounds = snds; transform.rotation = Quaternion.Euler(0, thing.angle, 0); gameObject.name = actor.Name; audioSource = gameObject.AddComponent <AudioSource>(); BoxCollider coll = gameObject.AddComponent <BoxCollider>(); coll.isTrigger = true; coll.size = new Vector3(40, 20, 40); Light lightObj = new GameObject("lightObj").AddComponent <Light>(); lightObj.transform.parent = transform; lightObj.transform.localPosition = new Vector3(0f, 5f, 0f); lightObj.intensity = 20f; lightObj.range = 20f; lightObj.cullingMask = (1 << 9); lightObj.cullingMask = ~lightObj.cullingMask; lightObj.enabled = false; sprObj = new GameObject("sprite"); sprObj.transform.parent = transform; sprObj.transform.position = transform.position; sprObj.layer = 9; this.mesh = createPlane(); MeshFilter mf = sprObj.AddComponent <MeshFilter>(); mr = sprObj.AddComponent <MeshRenderer>(); mr.material = new Material(Shader.Find("Custom/DoomShaderTransparent")); mf.mesh = this.mesh; stateController = new StateController(actor, sprites, audioSource, sprObj, lightObj); stateController.UpdateMaterial(mr.material, 1); }
void ReadMAPEntries() { for (int i = 0; i < newWad.directory.Count - 1; i++) { if (newWad.directory[i + 1].name.Contains("THINGS") && newWad.directory[i].size == 0) { DoomMap newMap = new DoomMap(); DrctEntry dirEntry = newWad.directory[i]; newMap.name = dirEntry.name; //THINGS lump if (newWad.directory[i + 1].name.Contains("THINGS")) { byte[] thingBytes = new byte[newWad.directory[i + 1].size]; wadOpener.Position = newWad.directory[i + 1].filepos; wadOpener.Read(thingBytes, 0, thingBytes.Length); for (int j = 0; j < newWad.directory[i + 1].size; j += 10) { THINGS newThing = new THINGS(); newThing.xPos = BitConverter.ToInt16(thingBytes, j + 0); newThing.yPos = BitConverter.ToInt16(thingBytes, j + 2); newThing.angle = BitConverter.ToInt16(thingBytes, j + 4); newThing.thingType = BitConverter.ToInt16(thingBytes, j + 6); newThing.thingOptions = BitConverter.ToInt16(thingBytes, j + 8); newMap.things.Add(newThing); } } //LINEDEEFS lump if (newWad.directory[i + 2].name.Contains("LINEDEFS")) { byte[] lineDefBytes = new byte[newWad.directory[i + 2].size]; wadOpener.Position = newWad.directory[i + 2].filepos; wadOpener.Read(lineDefBytes, 0, lineDefBytes.Length); for (int j = 0; j < newWad.directory[i + 2].size; j += 14) { LINEDEFS newLineDef = new LINEDEFS(); newLineDef.firstVertIndex = BitConverter.ToInt16(lineDefBytes, j + 0); newLineDef.lastVertIndex = BitConverter.ToInt16(lineDefBytes, j + 2); newLineDef.flags = BitConverter.ToInt16(lineDefBytes, j + 4); newLineDef.types = BitConverter.ToInt16(lineDefBytes, j + 6); newLineDef.tag = BitConverter.ToInt16(lineDefBytes, j + 8); newLineDef.side1Index = BitConverter.ToInt16(lineDefBytes, j + 10); newLineDef.side2Index = BitConverter.ToInt16(lineDefBytes, j + 12); newMap.linedefs.Add(newLineDef); } } //SIDEDEFS lump if (newWad.directory[i + 3].name.Contains("SIDEDEFS")) { byte[] sideDefBytes = new byte[newWad.directory[i + 3].size]; wadOpener.Position = newWad.directory[i + 3].filepos; wadOpener.Read(sideDefBytes, 0, sideDefBytes.Length); for (int j = 0; j < newWad.directory[i + 3].size; j += 30) { SIDEDEFS newSideDef = new SIDEDEFS(); newSideDef.xOfs = BitConverter.ToInt16(sideDefBytes, j + 0); newSideDef.yOfs = BitConverter.ToInt16(sideDefBytes, j + 2); newSideDef.upTex = new String(System.Text.Encoding.ASCII.GetChars(sideDefBytes, j + 4, 8)).ToUpper(); newSideDef.lowTex = new String(System.Text.Encoding.ASCII.GetChars(sideDefBytes, j + 12, 8)).ToUpper(); newSideDef.midTex = new String(System.Text.Encoding.ASCII.GetChars(sideDefBytes, j + 20, 8)).ToUpper(); newSideDef.secNum = BitConverter.ToInt16(sideDefBytes, j + 28); newSideDef.upTex = newSideDef.upTex.Replace("\0", ""); newSideDef.lowTex = newSideDef.lowTex.Replace("\0", ""); newSideDef.midTex = newSideDef.midTex.Replace("\0", ""); newMap.sidedefs.Add(newSideDef); } } //VERTEXES lump if (newWad.directory[i + 4].name.Contains("VERTEXES")) { byte[] vertexBytes = new byte[newWad.directory[i + 4].size]; wadOpener.Position = newWad.directory[i + 4].filepos; wadOpener.Read(vertexBytes, 0, vertexBytes.Length); for (int j = 0; j < newWad.directory[i + 4].size; j += 4) { Vector3 newVertex = new Vector3(0, 0, 0); newVertex.x = BitConverter.ToInt16(vertexBytes, j + 0); newVertex.z = BitConverter.ToInt16(vertexBytes, j + 2); newMap.vertexes.Add(newVertex); } } //SECTORS lump if (newWad.directory[i + 8].name.Contains("SECTORS")) { byte[] secBytes = new byte[newWad.directory[i + 8].size]; wadOpener.Position = newWad.directory[i + 8].filepos; wadOpener.Read(secBytes, 0, secBytes.Length); for (int j = 0; j < newWad.directory[i + 8].size; j += 26) { SECTORS newSec = new SECTORS(); newSec.floorHeight = BitConverter.ToInt16(secBytes, j + 0); newSec.ceilingHeight = BitConverter.ToInt16(secBytes, j + 2); newSec.floorFlat = new String(System.Text.Encoding.ASCII.GetChars(secBytes, j + 4, 8)); newSec.ceilingFlat = new String(System.Text.Encoding.ASCII.GetChars(secBytes, j + 12, 8)); newSec.lightLevel = BitConverter.ToInt16(secBytes, j + 20); newSec.specialSec = BitConverter.ToInt16(secBytes, j + 22); newSec.sectorTag = BitConverter.ToInt16(secBytes, j + 24); newSec.floorFlat = newSec.floorFlat.Replace("\0", ""); newSec.ceilingFlat = newSec.ceilingFlat.Replace("\0", ""); newMap.sectors.Add(newSec); } } //BLOCKMAPS lump if (newWad.directory[i + 10].name.Contains("BLOCKMAP")) { byte[] blockBytes = new byte[newWad.directory[i + 10].size]; wadOpener.Position = newWad.directory[i + 10].filepos; wadOpener.Read(blockBytes, 0, blockBytes.Length); BLOCKMAP newBlockmap = new BLOCKMAP(); newBlockmap.xcoord = BitConverter.ToInt16(blockBytes, 0); newBlockmap.ycoord = BitConverter.ToInt16(blockBytes, 2); newBlockmap.numColumns = BitConverter.ToInt16(blockBytes, 4); newBlockmap.numRows = BitConverter.ToInt16(blockBytes, 6); int N = newBlockmap.numColumns * newBlockmap.numRows; //Offsets for (int j = 8; j < (8 + (2 * (N - 1))); j += 2) // (8 + (2 * (N - 1))) IS DEFINITELY RIGHT { newBlockmap.Offsets.Add(BitConverter.ToUInt16(blockBytes, j) * 2); //multiply this times 2 so its right } foreach (int offset in newBlockmap.Offsets) { int line = 0; int blockOffset = offset; // List<int> newBlock = new List<int>(); Block blk = new Block(); do { line = BitConverter.ToUInt16(blockBytes, blockOffset + 2); //newBlock.Add(line); if (line == 0xFFFF) { continue; } blk.lines.Add(newMap.linedefs[line]); blockOffset += 2; } while (line != 0xFFFF); newBlockmap.blocks.Add(blk); } newMap.blockmap = newBlockmap; } newWad.maps.Add(newMap); //Store the map in newWad } } }