コード例 #1
0
ファイル: DoomGraphic.cs プロジェクト: Petethegoat/DoomUnity
    public static Texture2D BuildPatch(string name, WadFile wad, bool ignoreCache = false)
    {
        if (!wad.Contains(name.ToUpper()))
        {
            return(null);
        }

        if (patchCache == null)
        {
            patchCache = new Dictionary <string, Texture2D>();
        }

        if (!ignoreCache)
        {
            if (patchCache.ContainsKey(name))
            {
                return(patchCache[name]);
            }
        }

        Texture2D output = new DoomGraphic(wad.GetLump(name.ToUpper())).ToRenderMap();

        if (!ignoreCache)
        {
            patchCache.Add(name, output);
        }

        return(output);
    }
コード例 #2
0
    public void BuildMap(WadFile wad, string mapname)
    {
        this.wad     = wad;
        textureTable = new TextureTable(wad.GetLump("TEXTURE1"));
        if (wad.Contains("TEXTURE2"))
        {
            textureTable.Add(wad.GetLump("TEXTURE2"));
        }
        paletteLookup  = new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture();
        colormapLookup = new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture();
        doomMaterial   = new Material(Shader.Find("Doom/Texture"));
        doomMaterial.SetTexture("_Palette", paletteLookup);
        doomMaterial.SetTexture("_Colormap", colormapLookup);

        skyMaterial = new Material(Shader.Find("Doom/Sky"));
        skyMaterial.SetTexture("_Palette", paletteLookup);
        skyMaterial.SetTexture("_RenderMap", GetTexture("SKY1"));


        map         = new MapData(wad, mapname);
        levelObject = new GameObject(mapname);

        unclaimedThings = new List <int>();
        for (int i = 0; i < map.things.Count; i++)
        {
            unclaimedThings.Add(i);
        }
        thingSectors = new Dictionary <int, Sector>();

        for (int i = 0; i < map.linedefs.Count; i++)
        {
            //Debug.Log(i);
            BuildLine(i);
        }


        for (int i = 0; i < map.sectors.Count; i++)
        {
            //Debug.Log(i);
            BuildSector(i);
        }

        // BuildSector(24);

        levelObject.transform.localScale = new Vector3(SCALE, SCALE * 1.2f, SCALE);

        GameObject player      = new GameObject("Player");
        int        playerIndex = 0;

        for (int i = 0; i < map.things.Count; i++)
        {
            if (map.things[i].type == 1)
            {
                playerIndex = i;
                break;
            }
        }
    }
コード例 #3
0
ファイル: GameSetup.cs プロジェクト: raynler/DoomUnity
 public void WarpMap(string mapname)
 {
     playerInventory.FullReset();
     mapname = mapname.ToUpper();
     if (wad.Contains(mapname))
     {
         HUD.Message("Warping to map: " + mapname);
         BuildMap(mapname);
     }
     else
     {
         HUD.Message("Couldn't find map " + mapname);
     }
 }
コード例 #4
0
ファイル: DoomMapBuilder.cs プロジェクト: MSylvia/DoomUnity
 DoomTexture GetInfo(string name, bool tryUpper = true)
 {
     if (textureTable.Contains(name))
     {
         return(textureTable.Get(name.ToUpper()));
     }
     else
     {
         if (wad.Contains(name))
         {
             DataType type = wad.DetectType(name);
             if (type == DataType.DoomFlat)
             {
                 return(new DoomTexture(name, 64, 64, null));
             }
             else if (type == DataType.PNG)
             {
                 Texture2D image = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                 ImageConversion.LoadImage(image, wad.GetLump(name));
                 image.filterMode = FilterMode.Point;
                 return(new DoomTexture(name, image.width, image.height, null));
             }
             else
             {
                 throw new Exception("Unknown texture type: " + name);
             }
         }
         else
         {
             if (tryUpper)
             {
                 return(GetInfo(name.ToUpper(), false));
             }
             throw new Exception("Cannot find texture: " + name);
         }
     }
 }
コード例 #5
0
    private Texture2D GetChar(char c)
    {
        if (textCache == null)
        {
            textCache = new Dictionary <char, Texture2D>();
        }

        if (textCache.ContainsKey(c))
        {
            return(textCache[c]);
        }

        string lumpName = lumpIdent + (int)char.ToUpper(c);

        if (wad.Contains(lumpName))
        {
            Texture2D output = new DoomGraphic(wad.GetLump(lumpName)).ToRenderMap();
            textCache.Add(c, output);
            return(output);
        }
        return(null);
    }
コード例 #6
0
    public void LoadMultigen(MultigenParser multigen, MultigenObject mobj, WadFile wad)
    {
        this.mobj     = mobj;
        this.multigen = multigen;
        this.wad      = wad;

        if (sprites == null)
        {
            sprites = new Dictionary <string, Sprite[]>();
        }

        if (itemPickupSound == null)
        {
            itemPickupSound = new DoomSound(wad.GetLump("DSITEMUP"), "DSITEMUP").ToAudioClip();
        }

        if (weaponPickupSound == null)
        {
            weaponPickupSound = new DoomSound(wad.GetLump("DSWPNUP"), "DSWPNUP").ToAudioClip();
        }

        boxCollider           = GetComponent <BoxCollider>();
        boxCollider.isTrigger = !mobj.data["flags"].Contains("MF_SOLID");

        radius = ReadFracValue(mobj.data["radius"]);
        height = ReadFracValue(mobj.data["height"]);
        speed  = float.Parse(mobj.data["speed"]) / 128f;
        move   = new Vector3();

        boxCollider.size = new Vector3(radius, height, radius);

        reactionTime = float.Parse(mobj.data["reactiontime"]) * tick;

        spriteMaterial = new Material(Shader.Find("Doom/Texture"));
        Texture2D paletteLookup  = new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture();
        Texture2D colormapLookup = new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture();

        spriteMaterial.SetTexture("_Palette", paletteLookup);
        spriteMaterial.SetTexture("_Colormap", colormapLookup);

        spriteRenderer          = GetComponent <SpriteRenderer>();
        spriteRenderer.material = spriteMaterial;

        string seeSoundName = ParseSoundName(mobj.data["seesound"]);

        if (wad.Contains(seeSoundName))
        {
            seeSound = new DoomSound(wad.GetLump(seeSoundName), seeSoundName).ToAudioClip();
        }

        string activeSoundName = ParseSoundName(mobj.data["activesound"]);

        if (wad.Contains(activeSoundName))
        {
            activeSound = new DoomSound(wad.GetLump(activeSoundName), activeSoundName).ToAudioClip();
        }

        string attackSoundName = ParseSoundName(mobj.data["attacksound"]);

        if (wad.Contains(attackSoundName))
        {
            attackSound = new DoomSound(wad.GetLump(attackSoundName), attackSoundName).ToAudioClip();
        }

        UpdateVerticalPosition();
        SetState(mobj.data["spawnstate"]);
    }
コード例 #7
0
ファイル: GameSetup.cs プロジェクト: raynler/DoomUnity
    // Use this for initialization
    void Start()
    {
        main = this;
        Settings.Init();
        ParseArguments();

        playerInventory = new PlayerInventory();

        Settings.Set("nomonsters", args.nomonsters ? "true" : "false");

        midiEnabled = args.midi;

        engineWad = new WadFile("nasty.wad");

        if (midiEnabled)
        {
            if (File.Exists(args.soundfont))
            {
                midiPlayer = gameObject.AddComponent <MidiPlayer>();
                midiPlayer.LoadBank(new PatchBank(File.OpenRead(args.soundfont), "sf2"));
            }
            else
            {
                if (engineWad.Contains("GMBANK"))
                {
                    midiPlayer = gameObject.AddComponent <MidiPlayer>();
                    midiPlayer.LoadBank(new PatchBank(engineWad.GetLumpAsMemoryStream("GMBANK"), "bank"));
                }
                else
                {
                    Debug.LogError("No soundfont found, disabling midi");
                }
            }
        }

        IwadData iwadData = JsonUtility.FromJson <IwadData>(engineWad.GetLumpAsText("IWADS"));

        cheatCodes = new List <string>()
        {
            "idclev",
            "idclip",
            "kill",
            "test"
        };

        SetupTitleCamera();

        string iwadDirectory = Settings.Get("iwads_path", "./");

        if (args.iwad == "")           // Run IWAD selection tool

        {
            foundIwads = new List <IwadInfo>();
            iwadPaths  = new List <string>();

            var fileInfo = new DirectoryInfo(iwadDirectory).GetFiles();
            foreach (var file in fileInfo)
            {
                string fileMd5 = WadFile.GetMD5(file.FullName);
                if (file.Extension.ToUpper() == ".WAD")
                {
                    for (int i = 0; i < iwadData.iwads.Length; i++)
                    {
                        if (fileMd5 == iwadData.iwads[i].md5)
                        {
                            foundIwads.Add(iwadData.iwads[i]);
                            iwadPaths.Add(file.FullName);
                        }
                    }
                }
            }

            if (foundIwads.Count == 0)
            {
                Debug.LogError("Cannot find any iwads!");
            }
            if (foundIwads.Count > 1)
            {
                iwadSelector = true;
            }

            if (foundIwads.Count == 1)
            {
                SetupWad(foundIwads[0], iwadPaths[0]);
            }
        }
        else
        {
            for (int i = 0; i < iwadData.iwads.Length; i++)
            {
                if (WadFile.GetMD5(args.iwad) == iwadData.iwads[i].md5)
                {
                    SetupWad(iwadData.iwads[i], args.iwad);
                    break;
                }
            }
        }
    }
コード例 #8
0
ファイル: LevelEntity.cs プロジェクト: raynler/DoomUnity
    public void LoadMultigen(MultigenObject mobj, WadFile wad)
    {
        this.mobj = mobj;
        this.wad  = wad;

        if (sprites == null)
        {
            sprites = new Dictionary <string, Sprite[]>();
        }

        if (itemPickupSound == null)
        {
            itemPickupSound = new DoomSound(wad.GetLump("DSITEMUP"), "DSITEMUP").ToAudioClip();
        }

        if (weaponPickupSound == null)
        {
            weaponPickupSound = new DoomSound(wad.GetLump("DSWPNUP"), "DSWPNUP").ToAudioClip();
        }

        MF_MISSILE   = mobj.data["flags"].Contains("MF_MISSILE");
        MF_SPECIAL   = mobj.data["flags"].Contains("MF_SPECIAL");
        MF_SOLID     = mobj.data["flags"].Contains("MF_SOLID");
        MF_COUNTKILL = mobj.data["flags"].Contains("MF_COUNTKILL");

        boxCollider           = GetComponent <BoxCollider>();
        boxCollider.isTrigger = !MF_SOLID;



        radius = ReadFracValue(mobj.data["radius"]);
        height = ReadFracValue(mobj.data["height"]);
        speed  = ReadFracValue(mobj.data["speed"]);
        move   = new Vector3();

        float vHeight = height;

        if (!MF_SPECIAL)
        {
            vHeight -= stepHeight * 0.5f;
        }
        else
        {
            vHeight *= 2f;
        }
        boxCollider.size   = new Vector3(radius, vHeight, radius);
        boxCollider.center = new Vector3(0f, (vHeight * 0.5f), 0f);

        reactionTime = float.Parse(mobj.data["reactiontime"]) * tick;

        spriteMaterial = new Material(Shader.Find("Doom/Texture"));
        Texture2D paletteLookup  = new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture();
        Texture2D colormapLookup = new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture();

        spriteMaterial.SetTexture("_Palette", paletteLookup);
        spriteMaterial.SetTexture("_Colormap", colormapLookup);

        spriteRenderer          = spriteTransform.gameObject.AddComponent <SpriteRenderer>();
        spriteRenderer.material = spriteMaterial;

        switch (mobj.data["seesound"])
        {
        case "sfx_posit1":
        case "sfx_posit2":
        case "sfx_posit3":
            seeSounds = new AudioClip[] {
                new DoomSound(wad.GetLump("DSPOSIT1"), "DSPOSIT1").ToAudioClip(),
                new DoomSound(wad.GetLump("DSPOSIT2"), "DSPOSIT2").ToAudioClip(),
                new DoomSound(wad.GetLump("DSPOSIT3"), "DSPOSIT3").ToAudioClip()
            };
            break;

        case "sfx_bgsit1":
        case "sfx_bgsit2":
            seeSounds = new AudioClip[] {
                new DoomSound(wad.GetLump("DSBGSIT1"), "DSBGSIT1").ToAudioClip(),
                new DoomSound(wad.GetLump("DSBGSIT2"), "DSBGSIT2").ToAudioClip()
            };
            break;

        default:
            string seeSoundName = ParseSoundName(mobj.data["seesound"]);

            if (wad.Contains(seeSoundName))
            {
                seeSound = new DoomSound(wad.GetLump(seeSoundName), seeSoundName).ToAudioClip();
            }
            break;
        }



        string activeSoundName = ParseSoundName(mobj.data["activesound"]);

        if (wad.Contains(activeSoundName))
        {
            activeSound = new DoomSound(wad.GetLump(activeSoundName), activeSoundName).ToAudioClip();
        }

        string attackSoundName = ParseSoundName(mobj.data["attacksound"]);

        if (wad.Contains(attackSoundName))
        {
            attackSound = new DoomSound(wad.GetLump(attackSoundName), attackSoundName).ToAudioClip();
        }

        string deathSoundName = ParseSoundName(mobj.data["deathsound"]);

        if (wad.Contains(deathSoundName))
        {
            deathSound = new DoomSound(wad.GetLump(deathSoundName), deathSoundName).ToAudioClip();
        }

        audioSource = GetComponent <AudioSource>();

        // UpdateVerticalPosition();
        SetState(mobj.data["spawnstate"]);
    }