예제 #1
0
    private static void Spawn(MonStat monStat, int x, int y, int level, Transform root)
    {
        if (!CollisionMap.Passable(new Vector2i(x, y) * Iso.SubTileCount, monStat.ext.sizeX))
        {
            return;
        }

        int count = Random.Range(monStat.minGrp, monStat.maxGrp + 1);

        for (int i = 0; i < count; ++i)
        {
            var mon = World.SpawnMonster(monStat, Iso.MapTileToWorld(x, y), root);
            mon.level = level;
        }

        if (monStat.minion1 != null)
        {
            int minionCount = Random.Range(monStat.partyMin, monStat.partyMax);
            for (int i = 0; i < minionCount; ++i)
            {
                var mon = World.SpawnMonster(monStat.minion1, Iso.MapTileToWorld(x, y), root);
                mon.level = level;
            }
        }
    }
예제 #2
0
    private void InstantiateDebugGrid(Vector2i offset, Transform root)
    {
        var grid = new GameObject("debug grid");

        grid.transform.SetParent(root);
        grid.layer = UnityLayers.SpecialTiles;

        for (int y = 0; y < gridHeight; ++y)
        {
            for (int x = 0; x < gridWidth; ++x)
            {
                var cellObject = new GameObject(x + ", " + y);
                cellObject.transform.position = Iso.MapToWorld(
                    (x * gridX + offset.x) * Iso.SubTileCount - 2,
                    (y * gridY + offset.y) * Iso.SubTileCount - 2);
                cellObject.transform.SetParent(grid.transform);
                cellObject.layer = UnityLayers.SpecialTiles;
                var line = cellObject.AddComponent <LineRenderer>();
                line.startWidth    = 0.1f;
                line.endWidth      = 0.1f;
                line.material      = Materials.normal;
                line.useWorldSpace = false;
                var corners = new Vector3[] {
                    Iso.MapTileToWorld(0, 0),
                    Iso.MapTileToWorld(0 + gridX, 0),
                    Iso.MapTileToWorld(0 + gridX, gridY),
                    Iso.MapTileToWorld(0, gridY),
                    Iso.MapTileToWorld(0, 0)
                };
                line.positionCount = corners.Length;
                line.SetPositions(corners);
            }
        }
    }
예제 #3
0
        private static void ApplyTileCollisions(DT1.Tile tile, int x, int y)
        {
            var pos = Iso.MapTileToWorld(x, y);
            var collisionMapOffset = Iso.Snap(Iso.MapToIso(pos));
            int flagIndex          = 0;

            DT1.BlockFlags mask = DT1.BlockFlags.Walk | DT1.BlockFlags.PlayerWalk;
            for (int dy = 2; dy > -3; --dy)
            {
                for (int dx = -2; dx < 3; ++dx, ++flagIndex)
                {
                    Vector2i        subCellPos    = collisionMapOffset + new Vector2i(dx, dy);
                    bool            passable      = (tile.flags[flagIndex] & mask) == 0;
                    CollisionLayers blockedLayers = passable ? CollisionLayers.None : CollisionLayers.Walk;
                    if (tile.orientation == 0)
                    {
                        CollisionMap.SetBlocked(subCellPos, blockedLayers);
                    }
                    else if (CollisionMap.Passable(subCellPos, CollisionLayers.Walk) && !passable)
                    {
                        CollisionMap.SetBlocked(subCellPos, blockedLayers);
                    }
                }
            }
        }
예제 #4
0
    void Start()
    {
        currentAct = CreateAct(1);
        Vector2i playerPos = currentAct.entry;

        SpawnPlayer(className, Iso.MapTileToWorld(playerPos));
    }
예제 #5
0
        void Start()
        {
            currentAct = CreateAct(1);
            Vector3 playerPos = Iso.MapTileToWorld(currentAct.entry);

            WorldState.instance.Player = new Player(className, playerPos);
            PlayerController.instance.SetPlayer(WorldState.instance.Player);
        }
예제 #6
0
파일: Popup.cs 프로젝트: D7tila/Diablerie
    public static Popup Create(IntRect triggerArea, IntRect revealArea, int revealMainIndex)
    {
        var gameObject = new GameObject("Popup " + revealMainIndex);

        gameObject.transform.position = Iso.MapTileToWorld(triggerArea.xMin, triggerArea.yMax);
        var popup = gameObject.AddComponent <Popup>();

        popup.triggerArea     = triggerArea;
        popup.revealArea      = revealArea;
        popup.revealMainIndex = revealMainIndex;
        var collider = gameObject.AddComponent <PolygonCollider2D>();

        collider.points    = Iso.CreateTileRectPoints(triggerArea.width, triggerArea.height);
        collider.isTrigger = true;
        return(popup);
    }
예제 #7
0
    public GameObject Instantiate(Vector2i offset)
    {
        var root = new GameObject(name);

        if (info != null)
        {
            var collider = root.AddComponent <PolygonCollider2D>();
            collider.offset    = Iso.MapTileToWorld(offset);
            collider.points    = Iso.CreateTileRectPoints(info.sizeX, info.sizeY);
            collider.isTrigger = true;

            var level = root.AddComponent <Level>();
            level.info = info;

            SelectMonsterTypes();
        }

        int i = 0;

        for (int y = 0; y < gridHeight; ++y)
        {
            for (int x = 0; x < gridWidth; ++x, ++i)
            {
                var ds1     = grid[i];
                int offsetX = offset.x + x * gridX;
                int offsetY = offset.y + y * gridY;
                if (ds1 != null)
                {
                    Instantiate(ds1, offsetX, offsetY, root.transform);
                    InstantiateMonsters(offsetX, offsetY, root.transform);
                }
                else if (info != null && info.drlgType == 3)
                {
                    FillGap(offset, x, y, root.transform);
                    InstantiateMonsters(offsetX, offsetY, root.transform);
                }
            }
        }

        InstantiateDebugGrid(offset, root.transform);

        return(root);
    }
예제 #8
0
    void Start()
    {
        var town      = new LevelBuilder("Act 1 - Town");
        var bloodMoor = CreateBloodMoor();

        var townOffset = new Vector2i(bloodMoor.gridWidth * bloodMoor.gridX - town.gridWidth * town.gridX, bloodMoor.gridHeight * bloodMoor.gridY);

        town.Instantiate(townOffset);
        bloodMoor.Instantiate(new Vector2i(0, 0));

        var doe       = CreateDenOfEvil();
        var doeOffset = new Vector2i(120, 0);

        doe.Instantiate(doeOffset);

        var entry = town.FindEntry();

        SpawnPlayer("Sorceress", Iso.MapTileToWorld(entry + townOffset));
    }
예제 #9
0
        private Renderer CreateTileRenderer(DT1.Tile tile, int x, int y, Transform parent = null)
        {
            var pos = Iso.MapTileToWorld(x, y);

            var gameObject = new GameObject();

            gameObject.name = tile.mainIndex + "_" + tile.subIndex + "_" + tile.orientation;
            gameObject.transform.position = pos;
            if (parent)
            {
                gameObject.transform.SetParent(parent);
            }
            var meshRenderer = gameObject.AddComponent <MeshRenderer>();
            var meshFilter   = gameObject.AddComponent <MeshFilter>();

            if (tile.orientation == 0 || tile.orientation == 15)
            {
                meshRenderer.sortingLayerID = tile.orientation == 0 ? SortingLayers.Floor : SortingLayers.Roof;

                gameObject.name += tile.orientation == 0 ? " (floor)" : " (roof)";
            }
            else if (tile.orientation > 15)
            {
                meshRenderer.sortingLayerID = SortingLayers.LowerWall;
                gameObject.name            += " (lower wall)";
            }
            else
            {
                if (tile.orientation == 13) // shadows
                {
                    meshRenderer.sortingLayerID = SortingLayers.Shadow;
                }

                meshRenderer.sortingOrder = Iso.SortingOrder(pos) - 4;
            }

            meshFilter.mesh = CreateTileMesh(tile);

            meshRenderer.material = tile.material;
            return(meshRenderer);
        }
예제 #10
0
        private IEnumerator LoadActCoroutine(int actNumber)
        {
            PlayerController.instance.enabled = false;
            MouseSelection.instance.enabled   = false;
            LoadingScreen.Show(0.5f);  // It's not zero due to preceding Unity scene load
            ScreenFader.SetToBlack();
            yield return(null);

            if (_currentAct != null)
            {
                Destroy(_currentAct.root);
            }
            _currentAct = CreateAct(actNumber);

            LoadingScreen.Show(0.75f);
            yield return(null);

            if (WorldState.instance.Player == null)
            {
                WorldState.instance.Player = new Player(className, _currentAct.entry);
                PlayerController.instance.SetPlayer(WorldState.instance.Player);
            }
            else
            {
                WorldState.instance.Player.unit.InstantMove(Iso.MapToIso(Iso.MapTileToWorld(_currentAct.entry)));
            }

            LoadingScreen.Show(0.9f);
            yield return(null); // Workaround to load first DCC while screen is black to avoid visible spikes

            LoadingScreen.Show(1.0f);
            yield return(null);

            PlayerController.instance.enabled = true;
            MouseSelection.instance.enabled   = true;
            LoadingScreen.Hide();
            ScreenFader.FadeToClear();
        }
예제 #11
0
        public GameObject Instantiate(Vector2i offset)
        {
            UnityEngine.Profiling.Profiler.BeginSample("LevelBuilder.Instantiate");
            var root = new GameObject(name);

            if (info != null)
            {
                var collider = root.AddComponent <PolygonCollider2D>();
                collider.offset    = Iso.MapTileToWorld(offset);
                collider.points    = Iso.CreateTileRectPoints(info.sizeX, info.sizeY);
                collider.isTrigger = true;

                var level = root.AddComponent <Level>();
                level.info = info;

                SelectMonsterTypes();
            }

            InstantiateGrid(offset, root.transform);
            InstantiateDebugGrid(offset, root.transform);

            UnityEngine.Profiling.Profiler.EndSample();
            return(root);
        }
예제 #12
0
    void Start()
    {
        Vector2i playerPos = CreateAct1();

        SpawnPlayer(className, Iso.MapTileToWorld(playerPos));
    }
예제 #13
0
    static Renderer CreateTile(DT1.Tile tile, int x, int y, int orderInLayer = 0, Transform parent = null)
    {
        var texture = tile.texture;
        var pos     = Iso.MapTileToWorld(x, y);

        GameObject gameObject = new GameObject();

        gameObject.name = tile.mainIndex + "_" + tile.subIndex + "_" + tile.orientation;
        gameObject.transform.position = pos;
        if (parent)
        {
            gameObject.transform.SetParent(parent);
        }
        var   meshRenderer = gameObject.AddComponent <MeshRenderer>();
        var   meshFilter   = gameObject.AddComponent <MeshFilter>();
        Mesh  mesh         = new Mesh();
        float x0           = tile.textureX;
        float y0           = tile.textureY;
        float w            = tile.width / Iso.pixelsPerUnit;
        float h            = (-tile.height) / Iso.pixelsPerUnit;

        if (tile.orientation == 0 || tile.orientation == 15)
        {
            var topLeft = new Vector3(-1f, 0.5f);
            if (tile.orientation == 15)
            {
                topLeft.y += tile.roofHeight / Iso.pixelsPerUnit;
            }
            mesh.vertices = new Vector3[] {
                topLeft,
                topLeft + new Vector3(0, -h),
                topLeft + new Vector3(w, -h),
                topLeft + new Vector3(w, 0)
            };
            mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 };
            mesh.uv        = new Vector2[] {
                new Vector2(x0 / texture.width, -y0 / texture.height),
                new Vector2(x0 / texture.width, (-y0 + tile.height) / texture.height),
                new Vector2((x0 + tile.width) / texture.width, (-y0 + tile.height) / texture.height),
                new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height)
            };

            meshRenderer.sortingLayerName = tile.orientation == 0 ? "Floor" : "Roof";
            meshRenderer.sortingOrder     = orderInLayer;
        }
        else
        {
            var topLeft = new Vector3(-1f, h - 0.5f);
            mesh.vertices = new Vector3[] {
                topLeft,
                topLeft + new Vector3(0, -h),
                topLeft + new Vector3(w, -h),
                topLeft + new Vector3(w, 0)
            };
            mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 };
            mesh.uv        = new Vector2[] {
                new Vector2(x0 / texture.width, (-y0 - tile.height) / texture.height),
                new Vector2(x0 / texture.width, -y0 / texture.height),
                new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height),
                new Vector2((x0 + tile.width) / texture.width, (-y0 - tile.height) / texture.height)
            };
            meshRenderer.sortingOrder = Iso.SortingOrder(pos) - 4;
        }
        meshFilter.mesh = mesh;

        int  flagIndex          = 0;
        var  collisionMapOffset = Iso.Snap(Iso.MapToIso(pos));
        byte mask = DT1.BlockFlags.Walk | DT1.BlockFlags.PlayerWalk;

        for (int dy = 2; dy > -3; --dy)
        {
            for (int dx = -2; dx < 3; ++dx, ++flagIndex)
            {
                var  subCellPos = collisionMapOffset + new Vector2i(dx, dy);
                bool passable   = (tile.flags[flagIndex] & mask) == 0;
                if (tile.orientation == 0)
                {
                    CollisionMap.SetPassable(subCellPos, passable);
                }
                else if (CollisionMap.Passable(subCellPos) && !passable)
                {
                    CollisionMap.SetPassable(subCellPos, false);
                }
            }
        }

        meshRenderer.material = tile.material;
        return(meshRenderer);
    }
예제 #14
0
        static Renderer CreateTile(DT1.Tile tile, int x, int y, int orderInLayer = 0, Transform parent = null)
        {
            var texture = tile.texture;
            var pos     = Iso.MapTileToWorld(x, y);

            GameObject gameObject = new GameObject();

            gameObject.name = tile.mainIndex + "_" + tile.subIndex + "_" + tile.orientation;
            gameObject.transform.position = pos;
            if (parent)
            {
                gameObject.transform.SetParent(parent);
            }
            var   meshRenderer = gameObject.AddComponent <MeshRenderer>();
            var   meshFilter   = gameObject.AddComponent <MeshFilter>();
            Mesh  mesh         = new Mesh();
            float x0           = tile.textureX;
            float y0           = tile.textureY;
            float w            = tile.width / Iso.pixelsPerUnit;
            float h            = (-tile.height) / Iso.pixelsPerUnit;

            if (tile.orientation == 0 || tile.orientation == 15)
            {
                var topLeft = new Vector3(-1f, 0.5f);
                if (tile.orientation == 15)
                {
                    topLeft.y += tile.roofHeight / Iso.pixelsPerUnit;
                }
                mesh.vertices = new Vector3[]
                {
                    topLeft,
                    topLeft + new Vector3(0, -h),
                    topLeft + new Vector3(w, -h),
                    topLeft + new Vector3(w, 0)
                };
                mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 };
                mesh.uv        = new Vector2[]
                {
                    new Vector2(x0 / texture.width, -y0 / texture.height),
                    new Vector2(x0 / texture.width, (-y0 + tile.height) / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, (-y0 + tile.height) / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height)
                };

                meshRenderer.sortingLayerID = tile.orientation == 0 ? SortingLayers.Floor : SortingLayers.Roof;
                meshRenderer.sortingOrder   = orderInLayer;

                gameObject.name += tile.orientation == 0 ? " (floor)" : " (roof)";
            }
            else if (tile.orientation > 15)
            {
                int upperPart = Math.Min(96, -tile.height);
                y0 -= upperPart;
                var topLeft = new Vector3(-1f, upperPart / Iso.pixelsPerUnit - 0.5f);
                mesh.vertices = new Vector3[] {
                    topLeft,
                    topLeft + new Vector3(0, -h),
                    topLeft + new Vector3(w, -h),
                    topLeft + new Vector3(w, 0)
                };
                mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 };
                mesh.uv        = new Vector2[] {
                    new Vector2(x0 / texture.width, -y0 / texture.height),
                    new Vector2(x0 / texture.width, (-y0 + tile.height) / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, (-y0 + tile.height) / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height)
                };
                meshRenderer.sortingLayerID = SortingLayers.LowerWall;
                meshRenderer.sortingOrder   = orderInLayer;

                gameObject.name += " (lower wall)";
            }
            else
            {
                var topLeft = new Vector3(-1f, h - 0.5f);
                mesh.vertices = new Vector3[] {
                    topLeft,
                    topLeft + new Vector3(0, -h),
                    topLeft + new Vector3(w, -h),
                    topLeft + new Vector3(w, 0)
                };
                mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 };
                mesh.uv        = new Vector2[] {
                    new Vector2(x0 / texture.width, (-y0 - tile.height) / texture.height),
                    new Vector2(x0 / texture.width, -y0 / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, (-y0 - tile.height) / texture.height)
                };
                if (tile.orientation == 13) // shadows
                {
                    meshRenderer.sortingLayerID = SortingLayers.Shadow;
                }
                meshRenderer.sortingOrder = Iso.SortingOrder(pos) - 4;
            }
            meshFilter.mesh = mesh;

            int flagIndex          = 0;
            var collisionMapOffset = Iso.Snap(Iso.MapToIso(pos));

            DT1.BlockFlags mask = DT1.BlockFlags.Walk | DT1.BlockFlags.PlayerWalk;
            for (int dy = 2; dy > -3; --dy)
            {
                for (int dx = -2; dx < 3; ++dx, ++flagIndex)
                {
                    Vector2i        subCellPos    = collisionMapOffset + new Vector2i(dx, dy);
                    bool            passable      = (tile.flags[flagIndex] & mask) == 0;
                    CollisionLayers blockedLayers = passable ? CollisionLayers.None : CollisionLayers.Walk;
                    if (tile.orientation == 0)
                    {
                        CollisionMap.SetBlocked(subCellPos, blockedLayers);
                    }
                    else if (CollisionMap.Passable(subCellPos, CollisionLayers.Walk) && !passable)
                    {
                        CollisionMap.SetBlocked(subCellPos, blockedLayers);
                    }
                }
            }

            meshRenderer.material = tile.material;
            return(meshRenderer);
        }
예제 #15
0
 public static void GoToAct(int actNumber)
 {
     Destroy(currentAct.root);
     currentAct = CreateAct(actNumber);
     PlayerController.instance.character.InstantMove(Iso.MapToIso(Iso.MapTileToWorld(currentAct.entry)));
 }