Beispiel #1
0
    public void UnSpawnbin()
    {
        if (TileManagerProxy.Get().GetTile(GetCoordinates()).GetTileObject() == null)
        {
            return;
        }

        Destroy(TileManagerProxy.Get().GetTile(GetCoordinates()).GetTileObject().gameObject);
        ms_BinNumber--;
    }
Beispiel #2
0
    public void SpawnBin(int binNumber)
    {
        if (!TileManagerProxy.Get().GetTile(GetCoordinates()).IsEmpty())
        {
            new DialogueEvent("Cannot Spawn").Push();
            CommandStackProxy.Get().PopCommand().Undo();
            return;
        }

        StartCoroutine(SpawnRountine(binNumber));
    }
Beispiel #3
0
 public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
 {
     if (GetActiveSceneName() == "Level")
     {
         TileManagerProxy.Get().Reset();
         GoalManagerProxy.Get().Reset();
         CommandStackProxy.Get().Reset();
         m_NumberOfMove = 0;
         string levelName = GetCurrentLevelName();
         m_LevelDimension = LevelParser.GenLevel("/" + levelName + ".txt");
         new LevelEvent(m_CurrentLevel, true).Push();
         new BinSpawnEvent(true, 0).Push();
         new DialogueEvent(levelName + "-start").Push();
     }
 }
Beispiel #4
0
    public static TileCoordinates GenLevel(string filename)
    {
        filename = Application.streamingAssetsPath + filename;

        string[] lines = File.ReadAllLines(filename);
        int      x     = 0;
        int      y     = 0;

        foreach (string line in lines)
        {
            string[] lienOfTile = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            x = 0;
            foreach (string tileInfo in lienOfTile)
            {
                string[] words = tileInfo.Split(',');

                ETileType tileType = ms_CharToTileType[words[0]];
                if (tileType == ETileType.None)
                {
                    x++;
                    continue;
                }
                GameObject tileGameObject = GameObject.Instantiate(RessourceManager.LoadPrefab("Tile"));
                tileGameObject.transform.position = new Vector3(x.ToWorldUnit(), y.ToWorldUnit(), 0);
                Tile tile = tileGameObject.AddComponent <Tile> ();
                tile.SetCoordinates(new TileCoordinates(x, y));
                tile.SetType(tileType);

                TileManagerProxy.Get().AddTile(tile);

                if (words.Length > 1)
                {
                    ETileObjectType tileObjectType       = (ETileObjectType)Enum.Parse(typeof(ETileObjectType), (String)words.GetValue(1), true);
                    GameObject      tileObjectGameObject = GameObject.Instantiate(RessourceManager.LoadPrefab("TileObject_" + words[1]));
                    tileObjectGameObject.transform.position = new Vector3(x.ToWorldUnit(), y.ToWorldUnit(), 0);
                    TileObject tileObject = tileObjectGameObject.GetComponent <TileObject> ();
                    tileObject.Init(tileObjectType, x, y, words.SubArray(2, -1));
                    tile.SetTileObject(tileObject);
                }

                x++;
            }
            y--;
        }

        return(new TileCoordinates(x, y));
    }
Beispiel #5
0
    private bool CanMoveTo(int xDir, int yDir)
    {
        if (m_IsMoving || m_IsTurning)
        {
            return(false);
        }

        Tile nextTruckTile = TileManagerProxy.Get().GetTile(((int)transform.position.x).ToTileUnit() + xDir, ((int)transform.position.y).ToTileUnit() + yDir);

        if (m_Bin == null)
        {
            return(nextTruckTile != null && nextTruckTile.IsEmpty());
        }
        else
        {
            TileCoordinates facingCoordinate = GetFacingTileCoordinates();
            Tile            nextBarrelTile   = TileManagerProxy.Get().GetTile(new TileCoordinates(facingCoordinate.x + xDir, facingCoordinate.y + yDir));
            return(nextBarrelTile != null && nextTruckTile != null && nextTruckTile.IsEmpty() && nextBarrelTile.IsEmpty());
        }
    }
Beispiel #6
0
    IEnumerator SpawnRountine(int binNumber)
    {
        m_Animator.SetBool("IsSpawning", true);
        SoundManagerProxy.Get().PlayMultiple(m_FallingSound);
        UpdaterProxy.Get().SetPause(true);
        yield return(new WaitForSeconds(1f));

        GameObject      binGameObject = GameObject.Instantiate(m_BinPrefab);
        TileCoordinates coordinates   = GetCoordinates();

        binGameObject.transform.position = new Vector3(coordinates.x.ToWorldUnit(), coordinates.y.ToWorldUnit(), 0);
        Bin bin = binGameObject.GetComponent <Bin> ();

        bin.Init(ETileObjectType.Bin, coordinates.x, coordinates.y, new string[] { binNumber.ToString() });
        bin.SetSpawnedCommandNumber();
        TileManagerProxy.Get().SetTileObject(coordinates, bin);
        ms_BinNumber++;

        UpdaterProxy.Get().SetPause(false);
        m_Animator.SetBool("IsSpawning", false);
    }
Beispiel #7
0
    private bool CanTurn(int newFacingDirection)
    {
        if (m_IsMoving || m_IsTurning)
        {
            return(false);
        }

        if (m_Bin == null)
        {
            return(true);
        }

        else
        {
            TileCoordinates currentTileCoordinates = new TileCoordinates(((int)transform.position.x).ToTileUnit(), ((int)transform.position.y).ToTileUnit());
            TileCoordinates oldFacingTileOffset    = ms_NeighboorTiles[m_FacingDirection];
            TileCoordinates newFacingOffset        = ms_NeighboorTiles[(EFacingDirection)newFacingDirection];
            TileCoordinates passingTileOffset      = oldFacingTileOffset + newFacingOffset;
            Tile            nextTile    = TileManagerProxy.Get().GetTile(currentTileCoordinates + newFacingOffset);
            Tile            passingTile = TileManagerProxy.Get().GetTile(currentTileCoordinates + passingTileOffset);
            return(passingTile != null && passingTile.CanTurn() &&
                   nextTile != null && nextTile.IsEmpty());
        }
    }
Beispiel #8
0
 private Tile GetFacingTile()
 {
     return(TileManagerProxy.Get().GetTile(GetFacingTileCoordinates()));
 }