Ejemplo n.º 1
0
        public bool PlaceTile(int x, int y, int layer, ITile tile, out ITileObject tileObject)
        {
            var chunkPoint = ChunkPointFromTileLocation(x, y);
            var chunk      = GetChunk(chunkPoint.X, chunkPoint.Y);

            return(chunk.PlaceTile(x - chunk.Location.AsTile.X, y - chunk.Location.AsTile.Y, layer, tile, out tileObject));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiates the given tile at the given local coordinate.
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public bool PlaceTile(int x, int y, int layer, ITile tile, out ITileObject tileObject)
        {
            if (0 > layer && layer > World.Info.LayerCount)
            {
                throw new System.ArgumentOutOfRangeException(nameof(layer));
            }

            if (IsValidChunkCoordinate(World, x, y))
            {
                if (tile == null)
                {
                    tiles[x, y, layer] = tileObject = null;
                }
                else
                {
                    TileLocation location = new TileLocation(x + this.Location.AsTile.X, y + this.Location.AsTile.Y, layer, this, x, y);
                    if (!tile.TileModifier.CanPlace(tile, location))
                    {
                        tileObject = null;
                        return(false);
                    }

                    tileObject             = tile?.TileModifier.Place(tile, location);
                    tileObject.RenderDepth = World.LayerToDepth(layer);
                }
            }
            else
            {
                return(World.PlaceTile(x + Location.AsTile.X, y + Location.AsTile.Y, layer, tile, out tileObject));
            }
            return(true);
        }
Ejemplo n.º 3
0
        public FVec3 RestrictInBounds(ITileObject tileObject, bool ignoreObstacle)
        {
            int     index    = this.GlobalPointToLocalIndex(tileObject.position);
            FBounds bounds   = this.GetTileBounds(index);
            FVec3   min      = bounds.min;
            FVec3   max      = bounds.max;
            FVec3   halfSize = tileObject.worldBounds.size * Fix64.Half;
            FVec3   p        = tileObject.position;

            if ((ignoreObstacle || this._tiles[index + 1].flag != Tile.Flag.Walkable) &&
                p.x > max.x - halfSize.x)
            {
                p.x = max.x - halfSize.x;
            }
            else if ((ignoreObstacle || this._tiles[index - 1].flag != Tile.Flag.Walkable) &&
                     p.x < min.x + halfSize.x)
            {
                p.x = min.x + halfSize.x;
            }
            if ((ignoreObstacle || this._tiles[index - this.col].flag != Tile.Flag.Walkable) &&
                p.z > max.z - halfSize.z)
            {
                p.z = max.z - halfSize.z;
            }
            else if ((ignoreObstacle || this._tiles[index + this.col].flag != Tile.Flag.Walkable) &&
                     p.z < min.z + halfSize.z)
            {
                p.z = min.z + halfSize.z;
            }
            return(p);
        }
Ejemplo n.º 4
0
        public ITileObject[] GetTiles(int x, int y)
        {
            var tiles = new ITileObject[Info.LayerCount];

            for (int layer = 0; layer < Info.LayerCount; layer++)
            {
                tiles[layer] = GetTile(x, y, layer);
            }
            return(tiles);
        }
Ejemplo n.º 5
0
 private void GetDownNeighborBounds(ITileObject self, int tileIndex, ref List <FBounds> boundsList)
 {
     this._tmpIndices[0] = tileIndex;
     this._tmpIndices[1] = tileIndex - 1;
     this._tmpIndices[2] = tileIndex + 1;
     this._tmpIndices[3] = tileIndex + this.col;
     this._tmpIndices[4] = tileIndex + this.col - 1;
     this._tmpIndices[5] = tileIndex + this.col + 1;
     this.GetColliderBoundsWithinIndices(self, this._tmpIndices, ref boundsList);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Sets a prepared tile.
 /// </summary>
 /// <param name="tile"></param>
 public void AddTile(ITileObject tile)
 {
     if (tile.Location.Chunk == this)
     {
         tiles[tile.Location.AsLocalized.X, tile.Location.AsLocalized.Y, tile.Location.Z] = tile;
     }
     else
     {
         World.AddTile(tile);
     }
 }
Ejemplo n.º 7
0
 private void GetColliderBoundsWithinIndices(ITileObject self, int[] indices, ref List <FBounds> boundsList)
 {
     for (int i = 0; i < 6; i++)
     {
         int  index = indices[i];
         Tile tile  = this._tiles[index];
         if (tile.flag != Tile.Flag.Walkable)
         {
             boundsList.Add(tile.aabb);
         }
         this.GetCollidersInTile(self, index, ref boundsList);
     }
 }
Ejemplo n.º 8
0
        private void GetCollidersInTile(ITileObject self, int tileIndex, ref List <FBounds> boundsList)
        {
            List <ITileObject> objects = this._tiles[tileIndex].objects;
            int count = objects.Count;

            for (int i = 0; i < count; i++)
            {
                ITileObject tileObject = objects[i];
                if (tileObject != self && tileObject.enableCollision)
                {
                    boundsList.Add(tileObject.worldBounds);
                }
            }
        }
Ejemplo n.º 9
0
        public void UpdateObjectPosition(ITileObject tileObject, bool removeOnly)
        {
            if (tileObject.tileIndex >= 0)
            {
                this._tiles[tileObject.tileIndex].RemoveObject(tileObject);
            }
            if (removeOnly)
            {
                return;
            }
            int index = this.GlobalPointToLocalIndex(tileObject.position);

            this._tiles[index].AddObject(tileObject);
            tileObject.tileIndex = index;
        }
Ejemplo n.º 10
0
        public Fix64 MoveDetection(ITileObject self, Fix64 distance, int direction)
        {
            if (distance == Fix64.Zero)
            {
                return(Fix64.Zero);
            }

            FBounds bounds   = self.worldBounds;
            FVec3   position = bounds.center;

            position.y = Fix64.Zero;
            int girdIndex = this.GlobalPointToLocalIndex(position);

            Fix64 minT;

            if (direction == 0)              //x轴
            {
                if (distance > Fix64.Zero)   //右
                {
                    this.GetRightNeighborBounds(self, girdIndex, ref this._tmpBounds);
                }
                else if (distance < Fix64.Zero)                  //左
                {
                    this.GetLeftNeighborBounds(self, girdIndex, ref this._tmpBounds);
                }

                minT = this.GetMinIntersectTime(bounds, this._tmpBounds, distance, FBounds.Axis.X);
                this._tmpBounds.Clear();
            }
            else            //z轴
            {
                if (distance > Fix64.Zero)
                {
                    this.GetUpNeighborBounds(self, girdIndex, ref this._tmpBounds);
                }
                else if (distance < Fix64.Zero)
                {
                    this.GetDownNeighborBounds(self, girdIndex, ref this._tmpBounds);
                }

                minT = this.GetMinIntersectTime(bounds, this._tmpBounds, distance, FBounds.Axis.Z);
                this._tmpBounds.Clear();
            }
            distance = minT * distance;

            return(distance);
        }
Ejemplo n.º 11
0
    private void OnDisable()
    {
        if (EventDisableTile != null)
        {
            EventDisableTile(this);

            ITileObject tileObject = null;
            for (int i = 0; i < arrTileType.Length / 4; i++)
            {
                for (int j = 0; j < arrTileType.Length / 2; j++)
                {
                    tileObject = transform.GetChild(j + (i * 4)).GetChild(0).GetComponent <ITileObject>();
                    if (tileObject != null)
                    {
                        tileObject.Init();
                    }
                }
            }
        }
    }
Ejemplo n.º 12
0
    private void Awake()
    {
        tileID      = globalTileID++;
        arrTileType = new eTileType[8];

        ITileObject tileObject = null;

        for (int i = 0; i < arrTileType.Length / 4; i++)
        {
            for (int j = 0; j < arrTileType.Length / 2; j++)
            {
                tileObject = transform.GetChild(j + (i * 4)).GetChild(0).GetComponent <ITileObject>();
                if (tileObject == null)
                {
                    arrTileType[j + (i * 4)] = eTileType.TileNormal;
                }
                else
                {
                    arrTileType[j + (i * 4)] = tileObject.GetTileType();
                }
            }
        }
    }
Ejemplo n.º 13
0
        private void TriggerDetection()
        {
            int count = this._triggers.Count;

            for (int i = 0; i < count; i++)
            {
                ITrigger trigger = this._triggers[i];
                Fix64    r       = trigger.triggerRadius * trigger.triggerRadius;
                this._battle.maze.GetTileObjectsAround(trigger.tileIndex, ref this._championsAround);
                int      c2       = this._championsAround.Count;
                Champion champion = null;
                Fix64    min      = Fix64.MaxValue;
                for (int j = 0; j < c2; j++)
                {
                    ITileObject tileObject = this._championsAround[j];
                    if (!(tileObject is Champion))
                    {
                        continue;
                    }

                    Fix64 d = tileObject.position.DistanceSquared(trigger.position);
                    if (d <= r && d < min)
                    {
                        champion = ( Champion )tileObject;
                        min      = d;
                    }
                }
                if (champion != null)
                {
                    trigger.OnTrigger(champion);
                    --i;
                    --count;
                }
                this._championsAround.Clear();
            }
        }
Ejemplo n.º 14
0
 public virtual void Remove(ITileObject tile)
 {
     tile.Location.Chunk.PlaceTile(tile.Location.AsLocalized.X, tile.Location.AsLocalized.Y, tile.Location.Z, null);
 }
Ejemplo n.º 15
0
 public void AddTile(ITileObject tile)
 {
     tile.Location.Chunk.AddTile(tile);
 }
Ejemplo n.º 16
0
 internal void RemoveObject(ITileObject tileObject)
 {
     this._objects.Remove(tileObject);
 }
Ejemplo n.º 17
0
 internal void AddObject(ITileObject tileObject)
 {
     this._objects.Add(tileObject);
 }
Ejemplo n.º 18
0
 public void SetTileObject(string tile, ITileObject o) => _tiles[tile].ObjectOnTile = o;
Ejemplo n.º 19
0
 public void Remove(ITileObject tile)
 {
     TileModifier.Remove(tile);
 }