コード例 #1
0
    private void GrowBodyToward(Vector3 direction)
    {
        var addTail    = bodyTiles.Count == 0;
        var tileType   = new BodyTileType(snake.CurrentFacing, direction, addTail);
        var tile       = bodyTileSource.GetTile(tileType);
        var tileObject = tile.Tile;

        tileObject.transform.position = gameObject.transform.position;

        bodyTiles.AddFirst(tile);
        snake.Grow(direction);
    }
コード例 #2
0
    private void ShrinkTail()
    {
        snake.Shrink();

        // remove the tail
        var lastTile = bodyTiles.Last.Value;

        bodyTiles.RemoveLast();
        bodyTileSource.ReturnTile(lastTile);

        // If there is a body piece left, replace it with a new tail
        lastTile = bodyTiles.Last.Value;
        bodyTiles.RemoveLast();
        bodyTileSource.ReturnTile(lastTile);

        var tailType    = new BodyTileType(snake.CurrentFacing, snake.TailFacing, true);
        var newTailTile = bodyTileSource.GetTile(tailType);

        newTailTile.Tile.transform.position = lastTile.Tile.transform.position;
        bodyTiles.AddLast(newTailTile);
    }
コード例 #3
0
        public BodyTile GetTile(BodyTileType bodyTileType)
        {
            string name;

            if (bodyTileType.IsTail)
            {
                name = string.Format("SnakeTail{0}", GetDirectionString(bodyTileType.ToDirection));
            }
            else if (bodyTileType.FromDirection == bodyTileType.ToDirection)
            {
                name = string.Format("SnakeSegment{0}", GetDirectionString(bodyTileType.ToDirection));
            }
            else
            {
                name = string.Format("SnakeBend{0}{1}", GetDirectionString(bodyTileType.FromDirection), GetDirectionString(bodyTileType.ToDirection));
            }
            var preFab     = Resources.Load <GameObject>(name);
            var clonedTile = Instantiate(preFab);

            return(new BodyTile(clonedTile, bodyTileType));
            // TODO: pool tiles
            // TODO: enable
        }
コード例 #4
0
 public BodyTile(GameObject tile, BodyTileType type)
 {
     Tile = tile;
     Type = type;
 }