Exemplo n.º 1
0
    public void Dig(int x, int z)
    {
        if (!LevelHelpers.TileIsInBounds(Model, x, z))
        {
            return;
        }

        LevelTile tile = Model.Tiles[x, z];

        if (tile.Opened)
        {
            return;
        }

        tile.Opened = true;
        UpdateTileDigMarker(tile);

        List <LevelTile> surroundingTiles = LevelHelpers.GetSurroundingTiles(Model, x, z);

        foreach (LevelTile t in surroundingTiles)
        {
            Model.EvaluateTile(t.X, t.Z);
            UpdateObjectsForTile(t);
        }

        Model.UpdateContiguousTilesFrom(x, z);
        UpdateCeilingMask();
    }
Exemplo n.º 2
0
    public GameObject GetNearestNonBusyMinion(LevelTile tile)
    {
        float      closestDist = Mathf.Infinity;
        GameObject closest     = null;

        foreach (GameObject minion in minions)
        {
            if (minion.GetComponent <ActionQueue>().IsBusy())
            {
                continue;
            }

            Vector3 pos = LevelHelpers.WorldPosFromTilePos(tile.X, tile.Z);

            float dist = (minion.transform.position - pos).sqrMagnitude;
            if (dist < closestDist)
            {
                closestDist = dist;

                closest = minion;
            }
        }

        return(closest);
    }
Exemplo n.º 3
0
    IEnumerator ProcessDigList()
    {
        while (true)
        {
            digList.RemoveAll(tile => tile.Opened);

            digList.ForEach(tile => {
                // Do we have surrounding tiles in Hell?
                List <LevelTile> surrounding = LevelHelpers.GetAdjacentTiles(LevelController.Instance.Model, tile.X, tile.Z);
                LevelTile found = surrounding.Find(obj => (obj.Opened && LevelHelpers.IsTileInHell(LevelController.Instance.Model, obj.X, obj.Z)));

                // If so, dig them with some minions
                if (found != null)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        GameObject minion = GetNearestNonBusyMinion(tile);

                        if (minion)
                        {
                            minion.GetComponent <ActionQueue>().InsertBeforeCurrent(new DigAction(minion, new Vector2(tile.X, tile.Z)));
                        }
                    }
                }
            });

            yield return(new WaitForSeconds(1));
        }
    }
Exemplo n.º 4
0
 public void UpdateTileDigMarker(LevelTile tile)
 {
     // If there is a marker already...
     if (tile.DigMarker != null)
     {
         // and the tile isn't marked for digging, or it's opened now - then remove it
         if (!tile.MarkedForDigging || tile.Opened)
         {
             GameObject.Destroy(tile.DigMarker);
         }
     }
     // If there is no marker yet...
     else
     {
         // and the tile is marked for digging - the add it
         if (tile.MarkedForDigging)
         {
             tile.DigMarker = GameObject.Instantiate(DigMarkerPrefab);
             tile.DigMarker.transform.position = LevelHelpers.WorldPosFromTilePosSetY(
                 tile.X,
                 tile.Z,
                 LevelHelpers.TileDigMarkerPositionY);
             tile.DigMarker.transform.parent = transform;
         }
     }
 }
Exemplo n.º 5
0
    public void PaintDig(DestinationMarkerEventArgs args)
    {
        if (!IsDigging)
        {
            return;
        }

        // TODO: improve by using raycast to dig marker height
        Vector3 target = new Vector3(args.destinationPosition.x, DigMarkerWorldPositionY, args.destinationPosition.z);

        LevelTile tile = LevelHelpers.GetTileAtWorldPos(LevelController.Instance.Model, target);

        if (TileIsDiggable(tile))
        {
            if (paintMode == PaintModes.ERASE)
            {
                tile.MarkedForDigging = false;
                MinionManager.Instance.RemoveDigTile(tile);
            }
            else if (paintMode == PaintModes.PAINT)
            {
                tile.MarkedForDigging = true;
                MinionManager.Instance.AddDigTile(tile);
            }

            LevelController.Instance.UpdateTileDigMarker(tile);
        }
    }
Exemplo n.º 6
0
    public static List <LevelTile> GetAdjacentTiles(LevelModel model, int xPosition, int zPosition)
    {
        List <LevelTile> tiles = new List <LevelTile>();

        for (int x = (int)xPosition - 1; x <= (int)xPosition + 1; ++x)
        {
            if (!LevelHelpers.TileIsInBounds(model, x, zPosition))
            {
                continue;
            }

            tiles.Add(model.Tiles[x, zPosition]);
        }

        for (int z = (int)zPosition - 1; z <= (int)zPosition + 1; ++z)
        {
            if (!LevelHelpers.TileIsInBounds(model, xPosition, z))
            {
                continue;
            }

            tiles.Add(model.Tiles[xPosition, z]);
        }

        return(tiles);
    }
Exemplo n.º 7
0
 private bool TileIsDiggable(LevelTile tile)
 {
     // tile is not opened AND (tile is adjacent to room OR tile is adjacent to highlighted tile)
     return(!tile.Opened &&
            (LevelHelpers.IsTileAdjacentToDigMarkedTile(LevelController.Instance.Model, tile.X, tile.Z) ||
             LevelHelpers.IsTileAdjacentToHell(LevelController.Instance.Model, tile.X, tile.Z)));
 }
Exemplo n.º 8
0
    public DigAction(GameObject owner, Vector2 position)
        : base(owner, LevelHelpers.WorldPosFromTilePos((int)position.x, (int)position.y) + new Vector3(LevelHelpers.TileSize / 2, 0, LevelHelpers.TileSize / 2))
    {
        stoppingDistance = LevelHelpers.TileSize / 2;
        digPosition      = position;

        agent = owner.GetComponent <NavMeshAgent>();
    }
Exemplo n.º 9
0
    public void SpawnPlayer()
    {
        LevelModel model = LevelController.Instance.Model;

        Vector3 spawnPosition = LevelHelpers.WorldPosFromTilePos((int)model.HellSpawn.x, (int)model.HellSpawn.y);

        SpawnPlayer(spawnPosition);
    }
Exemplo n.º 10
0
    public void SetPlayerPosition(Vector3 position)
    {
        // HACK - APPEARS TO BE UNNECESSARY NOW FOR [INSERT DARK MAGIC REASONS HERE].
        float playerHeightOffset = 0f;

        float terrainHeight = LevelHelpers.GetTerrainHeightAtWorldPos(position);

        PlayArea.position = new Vector3(position.x, terrainHeight + playerHeightOffset, position.z);
    }
Exemplo n.º 11
0
        public static void FillListRecursive(string dirPath, List <ILevel> list, string excludeFilename = null, string includeOnlyFilename = null)
        {
            DirectoryInfo dir = new DirectoryInfo(dirPath);

            LevelHelpers.FromFolder(dir.FullName, list, excludeFilename, includeOnlyFilename);
            foreach (var childDir in dir.EnumerateDirectories())
            {
                FillListRecursive(childDir.FullName, list, excludeFilename, includeOnlyFilename);
            }
        }
Exemplo n.º 12
0
    private void FloodFill(int x, int z, LevelTile[,] tileList)
    {
        if (tileList[x, z] == null &&
            Tiles[x, z].Opened)
        {
            tileList[x, z] = Tiles[x, z];

            List <LevelTile> surroundingTiles = LevelHelpers.GetAdjacentTiles(this, x, z);

            surroundingTiles.ForEach(tile => FloodFill(tile.X, tile.Z, tileList));
        }
    }
Exemplo n.º 13
0
    private GameObject CreateObjectOnTile(LevelTile tile, GameObject prefab, Transform parent = null, bool isWall = false)
    {
        GameObject created = GameObject.Instantiate(prefab);

        Vector3 worldPosition = isWall ?
                                LevelHelpers.WorldPosFromTilePosSetY(tile.X, tile.Z, LevelHelpers.WallPositionY)
            : LevelHelpers.WorldPosFromTilePos(tile.X, tile.Z);

        created.transform.position = worldPosition;
        created.transform.parent   = (parent == null) ? transform : parent;

        return(created);
    }
Exemplo n.º 14
0
    public void SpawnStartingMinions(int num, Vector3 centerPosition)
    {
        float interval = (2 * Mathf.PI) / num;

        for (int i = 0; i < num; ++i)
        {
            float angle = interval * i;

            float x = MinionSpawnDistance * Mathf.Cos(angle);
            float z = MinionSpawnDistance * Mathf.Sin(angle);
            float y = LevelHelpers.GetTerrainHeightAtWorldPos(new Vector3(x, 0f, z));

            Vector3 position = (new Vector3(x + centerPosition.x, y, z + centerPosition.z));

            MinionManager.Instance.SpawnMinion(position);
        }
    }
Exemplo n.º 15
0
    public void Start()
    {
        int amount = Random.Range(2, 5);

        float radius = 15;

        for (int i = 0; i < amount; i++)
        {
            Vector2 offset   = radius * Random.insideUnitCircle;
            Vector3 spawnPos = transform.position;
            spawnPos.x = spawnPos.x + offset.x;
            spawnPos.z = spawnPos.z + offset.y;
            spawnPos.y = LevelHelpers.GetTerrainHeightAtWorldPos(spawnPos);

            GameObject.Instantiate(goblin, spawnPos, Quaternion.identity);
        }
    }
Exemplo n.º 16
0
    public void Dig(DestinationMarkerEventArgs args)
    {
        // TODO: improve by using raycast to dig marker height
        Vector3 target = new Vector3(args.destinationPosition.x, DigMarkerWorldPositionY, args.destinationPosition.z);

        // Debug.LogWarning("START DIG");

        IsDigging = true;

        LevelTile tile = LevelHelpers.GetTileAtWorldPos(LevelController.Instance.Model, target);

        paintMode = tile.MarkedForDigging ? PaintModes.ERASE : PaintModes.PAINT;

        if (TileIsDiggable(tile))
        {
            PaintDig(args);
        }
    }
Exemplo n.º 17
0
    void Update()
    {
        if (Input.GetMouseButton(1))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector2 tilePos = LevelHelpers.TilePosFromWorldPos(hit.point);

                LevelTile tile = LevelController.Instance.Model.Tiles[(int)tilePos.x, (int)tilePos.y];

                if (tile != null && !digList.Contains(tile))
                {
                    AddDigTile(tile);
                }
            }
        }
    }
Exemplo n.º 18
0
    public void PunchHole(Vector2 origin, int size)
    {
        float radius   = (float)size / 2f;
        int   halfSize = Mathf.CeilToInt(radius);

        for (int z = (int)origin.y - halfSize; z < (int)origin.y + halfSize; ++z)
        {
            for (int x = (int)origin.x - halfSize; x < (int)origin.x + halfSize; ++x)
            {
                if (!LevelHelpers.TileIsInBounds(this, x, z))
                {
                    continue;
                }

                if (Vector2.Distance(origin, new Vector2(x, z)) < radius)
                {
                    Tiles[x, z].Opened = true;
                }
            }
        }
    }
Exemplo n.º 19
0
    IEnumerator CheckDig()
    {
        while (true)
        {
            Vector3 tileInFront = transform.position + transform.forward * DigDistance;

            Vector2 tilePosition = LevelHelpers.TilePosFromWorldPos(tileInFront);

            LevelTile tile = LevelController.Instance.Model.Tiles[(int)tilePosition.x, (int)tilePosition.y];

            if (!tile.Opened)
            {
                ActionQueue queue = GetComponent <ActionQueue>();

                queue.InsertBeforeCurrent(new DigAction(gameObject, tilePosition));

                yield return(new WaitForSeconds(DigTime));
            }

            yield return(0);
        }
    }
Exemplo n.º 20
0
    public void UpdateContiguousTilesFrom(int x, int z)
    {
        List <LevelTile> surroundingTiles = LevelHelpers.GetAdjacentTiles(this, x, z);

        LevelTile foundHell = surroundingTiles.Find(tile => HellContiguousTiles[tile.X, tile.Z] != null);

        LevelTile foundHeaven = surroundingTiles.Find(tile => HeavenContiguousTiles[tile.X, tile.Z] != null);

        // if we're about to join, just copy everything to save a painful flood fill.
        if (foundHell != null &&
            foundHeaven != null)
        {
            for (int iz = 0; iz < Length; ++iz)
            {
                for (int ix = 0; ix < Width; ++ix)
                {
                    if (HellContiguousTiles[ix, iz] != null)
                    {
                        HeavenContiguousTiles[ix, iz] = HellContiguousTiles[ix, iz];
                    }
                    else if (HeavenContiguousTiles[ix, iz] != null)
                    {
                        HellContiguousTiles[ix, iz] = HeavenContiguousTiles[ix, iz];
                    }
                }
            }
        }

        if (foundHell != null)
        {
            FloodFill(x, z, HellContiguousTiles);
        }

        if (foundHeaven != null)
        {
            FloodFill(x, z, HeavenContiguousTiles);
        }
    }
Exemplo n.º 21
0
    public bool PositionIsValidLandingZone(Vector3 destination)
    {
        Vector2 tilePos = LevelHelpers.TilePosFromWorldPos(destination);

        LevelModel model = LevelController.Instance.Model;

        int x = (int)tilePos.x;
        int z = (int)tilePos.y;

        if (!LevelHelpers.TileIsInBounds(model, x, z))
        {
            return(false);
        }

        LevelTile tile = model.Tiles[x, z];

        if (tile.Opened)
        {
            return(true);
        }

        return(false);
    }
Exemplo n.º 22
0
 public static List <ILevel> MediumGallery3()
 {
     return(LevelHelpers.FromFolder(@"LevelImages\MediumGallery3\"));
 }
Exemplo n.º 23
0
 public static List <ILevel> HardGallery1()
 {
     return(LevelHelpers.FromFolder(@"LevelImages\HardGallery1\"));
 }
Exemplo n.º 24
0
 public static List <ILevel> EasyGallery4()
 {
     return(LevelHelpers.FromFolder(@"LevelImages\EasyGallery4\"));
 }
Exemplo n.º 25
0
 public static List <ILevel> Bonus2Gallery3()
 {
     return(LevelHelpers.FromFolder(@"LevelImages\Bonus2Gallery3\"));
 }
Exemplo n.º 26
0
 public static List <ILevel> ExpertGallery2()
 {
     return(LevelHelpers.FromFolder(@"LevelImages\ExpertGallery2\"));
 }