コード例 #1
0
 private void Start()
 {
     m_Tile = GetComponent <I_Tile>();
     if (m_Tile != null)
     {
         m_Tile.AddTileEvent(this);
     }
 }
コード例 #2
0
    public override void OnTileEnter(I_Tile _Tile)
    {
        I_Unit unit = _Tile.GetUnit();

        if (unit != null && unit is UnitEnemy)
        {
            unit.Kill();
            Kill();
        }
    }
コード例 #3
0
ファイル: Map.cs プロジェクト: Konkage/PocketDungeonAdventure
    public void LoadMap(MapData _MapData)
    {
        m_Walls  = new List <I_Tile>();
        m_Floors = new List <I_Tile>();
        m_Tiles  = new Dictionary <Vector2Int, I_Tile>();
        if (_MapData != null)
        {
            m_MapSize = new Vector2Int(_MapData.MapSizeX, _MapData.MapSizeZ);

            m_Rooms = new List <Room>();
            List <RoomData> roomsToLoad = _MapData.Rooms;
            for (int i = 0; i < roomsToLoad.Count; i++)
            {
                m_Rooms.Add(new Room(new Vector2Int(roomsToLoad[i].m_PosX, roomsToLoad[i].m_PosZ), new Vector2Int(roomsToLoad[i].m_SizeX, roomsToLoad[i].m_SizeZ)));
            }

            List <TileData> tilesToLoad = _MapData.Tiles;
            for (int i = 0; i < tilesToLoad.Count; i++)
            {
                Room room = null;
                if (tilesToLoad[i].m_RoomIndex >= 0)
                {
                    room = m_Rooms[tilesToLoad[i].m_RoomIndex];
                }

                GenerateTile("Tiles/TileEmpty", tilesToLoad[i].m_PosX, tilesToLoad[i].m_PosZ, room);
            }

            m_StairsPosition        = new Vector2Int(_MapData.StairsPositionX, _MapData.StairsPositionZ);
            m_StairsTriggerPosition = new Vector2Int(_MapData.StairsTriggerPositionX, _MapData.StairsTriggerPositionZ);
            I_Tile stairs        = GenerateTile("Tiles/TileStairs", _MapData.StairsPositionX, _MapData.StairsPositionZ, null);
            I_Tile stairsTrigger = GenerateTile("Tiles/TileShakeBell", _MapData.StairsTriggerPositionX, _MapData.StairsTriggerPositionZ, null);

            Tile           trucMoche           = stairsTrigger as Tile;
            TileEventShake trucEncorePlusMoche = trucMoche.GetComponent <TileEventShake>();
            Tile           trucSuperMoche      = stairs as Tile;
            I_Activable    trucSuperPlusMoche  = trucSuperMoche.GetComponent <I_Activable>();
            trucEncorePlusMoche.SetTileToActivate(trucSuperPlusMoche);


            for (int x = -1; x <= m_MapSize.x + 1; x++)
            {
                for (int z = -1; z <= m_MapSize.y + 1; z++)
                {
                    I_Tile tile;
                    if (!m_Tiles.TryGetValue(new Vector2Int(x, z), out tile))
                    {
                        tile = GenerateTile("Tiles/TileWall", x, z, null);
                    }
                    tile.SetMap(this);
                }
            }
            SmoothMap();
        }
    }
コード例 #4
0
    public void TeleportTo(I_Tile _Tile)
    {
        if (m_Tile != null)
        {
            m_Tile.SetUnit(null);
            OnTileExit(m_Tile);
        }
        m_Tile = _Tile;

        transform.position = m_Tile.GetPosition();
        m_Tile.SetUnit(this);
        OnTileEnter(m_Tile);
    }
コード例 #5
0
    public void SetTileLinks()
    {
        if (!m_IsWalkable && !m_IsActivable)
        {
            I_Tile northTile     = GetNeighbour(E_Direction.North);
            I_Tile southTile     = GetNeighbour(E_Direction.South);
            I_Tile eastTile      = GetNeighbour(E_Direction.East);
            I_Tile westTile      = GetNeighbour(E_Direction.West);
            I_Tile northEastTile = GetNeighbour(E_Direction.NorthEast);
            I_Tile northWestTile = GetNeighbour(E_Direction.NorthWest);
            I_Tile southEastTile = GetNeighbour(E_Direction.SouthEast);
            I_Tile southWestTile = GetNeighbour(E_Direction.SouthWest);

            bool isNorthWalkable     = northTile != null && northTile.IsWalkable();
            bool isSouthWalkable     = southTile != null && southTile.IsWalkable();
            bool isEastWalkable      = eastTile != null && eastTile.IsWalkable();
            bool isWestWalkable      = westTile != null && westTile.IsWalkable();
            bool isNorthEastWalkable = northEastTile != null && northEastTile.IsWalkable();
            bool isNorthWestWalkable = northWestTile != null && northWestTile.IsWalkable();
            bool isSouthEastWalkable = southEastTile != null && southEastTile.IsWalkable();
            bool isSouthWestWalkable = southWestTile != null && southWestTile.IsWalkable();

            m_NorthIfIsWalkable.SetActive(isNorthWalkable);
            m_SouthIfIsWalkable.SetActive(isSouthWalkable);
            m_EastIfIsWalkable.SetActive(isEastWalkable);
            m_WestIfIsWalkable.SetActive(isWestWalkable);

            m_NorthEastIfIsWalkable.SetActive(isNorthEastWalkable && isNorthWalkable && isEastWalkable);
            m_NorthWestIfIsWalkable.SetActive(isNorthWestWalkable && isNorthWalkable && isWestWalkable);
            m_SouthEastIfIsWalkable.SetActive(isSouthEastWalkable && isSouthWalkable && isEastWalkable);
            m_SouthWestIfIsWalkable.SetActive(isSouthWestWalkable && isSouthWalkable && isWestWalkable);

            m_NorthIsNotWalkableButEastAndNorthEastAre.SetActive(!isNorthWalkable && isEastWalkable && isNorthEastWalkable);
            m_NorthIsNotWalkableButWestAndNorthWestAre.SetActive(!isNorthWalkable && isWestWalkable && isNorthWestWalkable);
            m_SouthIsNotWalkableButEastAndSouthEastAre.SetActive(!isSouthWalkable && isEastWalkable && isSouthEastWalkable);
            m_SouthIsNotWalkableButWestAndSouthWestAre.SetActive(!isSouthWalkable && isWestWalkable && isSouthWestWalkable);
            m_EastIsNotWalkableButNorthAndNorthEastAre.SetActive(!isEastWalkable && isNorthWalkable && isNorthEastWalkable);
            m_EastIsNotWalkableButSouthAndSouthEastAre.SetActive(!isEastWalkable && isSouthWalkable && isSouthEastWalkable);
            m_WestIsNotWalkableButNorthAndNorthWestAre.SetActive(!isWestWalkable && isNorthWalkable && isNorthWestWalkable);
            m_WestIsNotWalkableButSouthAndSouthWestAre.SetActive(!isWestWalkable && isSouthWalkable && isSouthWestWalkable);

            m_NorthEastIsNotWalkableButNorthIs.SetActive(!isNorthEastWalkable && isNorthWalkable);
            m_NorthEastIsNotWalkableButEastIs.SetActive(!isNorthEastWalkable && isEastWalkable);
            m_NorthWestIsNotWalkableButNorthIs.SetActive(!isNorthWestWalkable && isNorthWalkable);
            m_NorthWestIsNotWalkableButWestIs.SetActive(!isNorthWestWalkable && isWestWalkable);
            m_SouthEastIsNotWalkableButSouthIs.SetActive(!isSouthEastWalkable && isSouthWalkable);
            m_SouthEastIsNotWalkableButEastIs.SetActive(!isSouthEastWalkable && isEastWalkable);
            m_SouthWestIsNotWalkableButSouthIs.SetActive(!isSouthWestWalkable && isSouthWalkable);
            m_SouthWestIsNotWalkableButWestIs.SetActive(!isSouthWestWalkable && isWestWalkable);
        }
    }
コード例 #6
0
    public E_TileAction Move(E_Direction _Direction)
    {
        E_TileAction action = E_TileAction.None;
        I_Tile       tile   = m_Tile.GetNeighbour(_Direction);

        if (tile != null)
        {
            m_IsMoving = true;
            OnTileExit(m_Tile);
            m_Tile = tile;
            OnTileEnter(m_Tile);
            m_Tile.OnUnitEnter(this);
        }
        return(action);
    }
コード例 #7
0
ファイル: Map.cs プロジェクト: Konkage/PocketDungeonAdventure
    private Room GenerateSpecialRoom(Vector2Int _MapSize)
    {
        Vector2Int bottomLeftCorner = new Vector2Int(Random.Range(1, _MapSize.x - 10), Random.Range(1, _MapSize.y - 10));
        Vector2Int size             = new Vector2Int(6, 6);
        Room       room             = new Room(bottomLeftCorner, size);

        I_Tile stairs = GenerateTile("Tiles/TileStairs", bottomLeftCorner.x + 3, bottomLeftCorner.y + 3, room);

        m_StairsPosition = new Vector2Int(bottomLeftCorner.x + 3, bottomLeftCorner.y + 3);
        I_Tile activator = null;

        m_StairsTriggerPosition = new Vector2Int();
        int rand = Random.Range(0, 4);

        if (rand == 0)
        {
            m_StairsTriggerPosition = new Vector2Int(bottomLeftCorner.x + 1, bottomLeftCorner.y + Random.Range(1, 6));
        }
        else if (rand == 1)
        {
            m_StairsTriggerPosition = new Vector2Int(bottomLeftCorner.x + 5, bottomLeftCorner.y + Random.Range(1, 6));
        }
        else if (rand == 2)
        {
            m_StairsTriggerPosition = new Vector2Int(bottomLeftCorner.x + Random.Range(1, 6), bottomLeftCorner.y + 1);
        }
        else if (rand == 3)
        {
            m_StairsTriggerPosition = new Vector2Int(bottomLeftCorner.x + Random.Range(1, 6), bottomLeftCorner.y + 5);
        }
        activator = GenerateTile("Tiles/TileShakeBell", m_StairsTriggerPosition.x, m_StairsTriggerPosition.y, room);
        Tile           trucMoche           = activator as Tile;
        TileEventShake trucEncorePlusMoche = trucMoche.GetComponent <TileEventShake>();
        Tile           trucSuperMoche      = stairs as Tile;
        I_Activable    trucSuperPlusMoche  = trucSuperMoche.GetComponent <I_Activable>();

        trucEncorePlusMoche.SetTileToActivate(trucSuperPlusMoche);

        return(room);
    }
コード例 #8
0
 public void AddTile(I_Tile _Tile)
 {
     m_TilesInRoom.Add(_Tile);
 }
コード例 #9
0
 public void SetNeighbour(E_Direction _Direction, I_Tile _Tile)
 {
     m_Neighbours[_Direction] = _Tile;
 }
コード例 #10
0
 public override void OnTileExit(I_Tile _Tile)
 {
     _Tile.SetUnit(null);
 }
コード例 #11
0
 public override void OnTileEnter(I_Tile _Tile)
 {
     _Tile.SetUnit(this);
 }
コード例 #12
0
 public override bool CanBeOnTile(I_Tile _Tile)
 {
     return(_Tile.IsWalkable());
 }
コード例 #13
0
 public override void OnTileExit(I_Tile _Tile)
 {
 }
コード例 #14
0
 public abstract bool CanBeOnTile(I_Tile _Tile);
コード例 #15
0
 public abstract void OnTileExit(I_Tile _Tile);
コード例 #16
0
 public abstract void OnTileEnter(I_Tile _Tile);
コード例 #17
0
 public void StartTurn()
 {
     if (m_MovingDirection != E_Direction.None && !m_Enemy.IsMoving())
     {
         I_Tile currentTile = m_Enemy.GetTile();
         if (currentTile != null)
         {
             bool isPlayerAtNorth = currentTile.GetNeighbour(E_Direction.North).GetUnit() is UnitPlayer;
             bool isPlayerAtSouth = currentTile.GetNeighbour(E_Direction.South).GetUnit() is UnitPlayer;
             bool isPlayerAtEast  = currentTile.GetNeighbour(E_Direction.East).GetUnit() is UnitPlayer;
             bool isPlayerAtWest  = currentTile.GetNeighbour(E_Direction.West).GetUnit() is UnitPlayer;
             if (isPlayerAtNorth || isPlayerAtSouth || isPlayerAtEast || isPlayerAtWest)
             {
                 if (isPlayerAtNorth)
                 {
                     m_Enemy.TurnToward(E_Direction.North);
                     UnitPlayer player = currentTile.GetNeighbour(E_Direction.North).GetUnit() as UnitPlayer;
                     if (!player.IsAttackedByEnemy())
                     {
                         player.SetAttackingEnemy(m_Enemy);
                     }
                 }
                 else if (isPlayerAtSouth)
                 {
                     m_Enemy.TurnToward(E_Direction.South);
                     UnitPlayer player = currentTile.GetNeighbour(E_Direction.South).GetUnit() as UnitPlayer;
                     if (!player.IsAttackedByEnemy())
                     {
                         player.SetAttackingEnemy(m_Enemy);
                     }
                 }
                 else if (isPlayerAtEast)
                 {
                     m_Enemy.TurnToward(E_Direction.East);
                     UnitPlayer player = currentTile.GetNeighbour(E_Direction.East).GetUnit() as UnitPlayer;
                     if (!player.IsAttackedByEnemy())
                     {
                         player.SetAttackingEnemy(m_Enemy);
                     }
                 }
                 else if (isPlayerAtWest)
                 {
                     m_Enemy.TurnToward(E_Direction.West);
                     UnitPlayer player = currentTile.GetNeighbour(E_Direction.West).GetUnit() as UnitPlayer;
                     if (!player.IsAttackedByEnemy())
                     {
                         player.SetAttackingEnemy(m_Enemy);
                     }
                 }
             }
             else
             {
                 m_TimerMove -= Time.deltaTime;
                 if (m_TimerMove < 0)
                 {
                     List <E_Direction> directionsPossible = new List <E_Direction>();
                     if (m_MovingDirection != E_Direction.South && m_Enemy.CanMoveTo(E_Direction.North))
                     {
                         directionsPossible.Add(E_Direction.North);
                     }
                     if (m_MovingDirection != E_Direction.North && m_Enemy.CanMoveTo(E_Direction.South))
                     {
                         directionsPossible.Add(E_Direction.South);
                     }
                     if (m_MovingDirection != E_Direction.West && m_Enemy.CanMoveTo(E_Direction.East))
                     {
                         directionsPossible.Add(E_Direction.East);
                     }
                     if (m_MovingDirection != E_Direction.East && m_Enemy.CanMoveTo(E_Direction.West))
                     {
                         directionsPossible.Add(E_Direction.West);
                     }
                     if (directionsPossible.Count > 0)
                     {
                         m_MovingDirection = directionsPossible[Random.Range(0, directionsPossible.Count)];
                         m_TimerMove       = Random.Range(1.0f, 3.0f);
                     }
                 }
                 if (m_Enemy.CanMoveTo(m_MovingDirection))
                 {
                     m_Enemy.Move(m_MovingDirection);
                 }
                 else
                 {
                     if (!m_Enemy.GetTile().GetNeighbour(m_MovingDirection).IsWalkable() || m_Enemy.GetTile().GetNeighbour(m_MovingDirection).GetUnit() is UnitEnemy)
                     {
                         List <E_Direction> directionsPossible = new List <E_Direction>();
                         if (m_MovingDirection != E_Direction.North && m_Enemy.CanMoveTo(E_Direction.North))
                         {
                             directionsPossible.Add(E_Direction.North);
                         }
                         if (m_MovingDirection != E_Direction.South && m_Enemy.CanMoveTo(E_Direction.South))
                         {
                             directionsPossible.Add(E_Direction.South);
                         }
                         if (m_MovingDirection != E_Direction.East && m_Enemy.CanMoveTo(E_Direction.East))
                         {
                             directionsPossible.Add(E_Direction.East);
                         }
                         if (m_MovingDirection != E_Direction.West && m_Enemy.CanMoveTo(E_Direction.West))
                         {
                             directionsPossible.Add(E_Direction.West);
                         }
                         if (directionsPossible.Count > 0)
                         {
                             m_MovingDirection = directionsPossible[Random.Range(0, directionsPossible.Count)];
                         }
                     }
                 }
             }
         }
         else
         {
             TurnOrder.RemoveUnit(this);
         }
     }
 }
コード例 #18
0
 public override bool CanBeOnTile(I_Tile _Tile)
 {
     return(_Tile.IsWalkable() && _Tile.GetUnit() == null);
 }
コード例 #19
0
ファイル: Map.cs プロジェクト: Konkage/PocketDungeonAdventure
    private I_Tile GenerateTile(string _Path, int _X, int _Z, Room _Room)
    {
        I_Tile tileScript;

        if (!m_Tiles.TryGetValue(new Vector2Int(_X, _Z), out tileScript))
        {
            GameObject prefab = Resources.Load <GameObject>(_Path);
            if (prefab != null)
            {
                tileScript = null;
                GameObject tileGameObject = Instantiate(prefab, new Vector3(_X, 0, _Z), Quaternion.identity, transform);
                tileGameObject.name = "Tile [" + _X + ", " + _Z + "]";
                if (tileGameObject != null)
                {
                    tileScript = tileGameObject.GetComponent <I_Tile>();
                    if (tileScript != null)
                    {
                        tileScript.SetPrefabName(_Path);
                        m_Tiles[new Vector2Int(_X, _Z)] = tileScript;
                        if (_Path == "Tiles/TileWall")
                        {
                            m_Walls.Add(tileScript);
                        }
                        else if (_Path == "Tiles/TileEmpty")
                        {
                            m_Floors.Add(tileScript);
                        }
                        if (_Room != null)
                        {
                            tileScript.SetRoom(_Room);
                            _Room.AddTile(tileScript);
                        }
                        I_Tile northTile;
                        I_Tile southTile;
                        I_Tile eastTile;
                        I_Tile westTile;
                        I_Tile northEastTile = null;
                        I_Tile northWestTile = null;
                        I_Tile southEastTile = null;
                        I_Tile southWestTile = null;
                        if (m_Tiles.TryGetValue(new Vector2Int(_X, _Z + 1), out northTile))
                        {
                            if (northEastTile == null)
                            {
                                northEastTile = northTile.GetNeighbour(E_Direction.East);
                            }
                            if (northWestTile == null)
                            {
                                northWestTile = northTile.GetNeighbour(E_Direction.West);
                            }
                        }
                        if (m_Tiles.TryGetValue(new Vector2Int(_X, _Z - 1), out southTile))
                        {
                            if (southEastTile == null)
                            {
                                southEastTile = southTile.GetNeighbour(E_Direction.East);
                            }
                            if (southWestTile == null)
                            {
                                southWestTile = southTile.GetNeighbour(E_Direction.West);
                            }
                        }
                        if (m_Tiles.TryGetValue(new Vector2Int(_X + 1, _Z), out eastTile))
                        {
                            if (northEastTile == null)
                            {
                                northEastTile = eastTile.GetNeighbour(E_Direction.North);
                            }
                            if (southEastTile == null)
                            {
                                southEastTile = eastTile.GetNeighbour(E_Direction.South);
                            }
                        }
                        if (m_Tiles.TryGetValue(new Vector2Int(_X - 1, _Z), out westTile))
                        {
                            if (northWestTile == null)
                            {
                                northWestTile = westTile.GetNeighbour(E_Direction.North);
                            }
                            if (southWestTile == null)
                            {
                                southWestTile = westTile.GetNeighbour(E_Direction.South);
                            }
                        }

                        if (northTile != null)
                        {
                            tileScript.SetNeighbour(E_Direction.North, northTile);
                            northTile.SetNeighbour(E_Direction.South, tileScript);
                        }
                        if (southTile != null)
                        {
                            tileScript.SetNeighbour(E_Direction.South, southTile);
                            southTile.SetNeighbour(E_Direction.North, tileScript);
                        }
                        if (eastTile != null)
                        {
                            tileScript.SetNeighbour(E_Direction.East, eastTile);
                            eastTile.SetNeighbour(E_Direction.West, tileScript);
                        }
                        if (westTile != null)
                        {
                            tileScript.SetNeighbour(E_Direction.West, westTile);
                            westTile.SetNeighbour(E_Direction.East, tileScript);
                        }
                        if (northEastTile != null)
                        {
                            tileScript.SetNeighbour(E_Direction.NorthEast, northEastTile);
                            northEastTile.SetNeighbour(E_Direction.SouthWest, tileScript);
                        }
                        if (northWestTile != null)
                        {
                            tileScript.SetNeighbour(E_Direction.NorthWest, northWestTile);
                            northWestTile.SetNeighbour(E_Direction.SouthEast, tileScript);
                        }
                        if (southEastTile != null)
                        {
                            tileScript.SetNeighbour(E_Direction.SouthEast, southEastTile);
                            southEastTile.SetNeighbour(E_Direction.NorthWest, tileScript);
                        }
                        if (southWestTile != null)
                        {
                            tileScript.SetNeighbour(E_Direction.SouthWest, southWestTile);
                            southWestTile.SetNeighbour(E_Direction.NorthEast, tileScript);
                        }
                    }
                }
            }
        }
        return(tileScript);
    }
コード例 #20
0
    public bool CanMoveTo(E_Direction _Direction)
    {
        I_Tile tile = m_Tile.GetNeighbour(_Direction);

        return(tile != null && CanBeOnTile(tile));
    }