コード例 #1
0
        public void Should_generate_unique_keys()
        {
            var a = BlockUtilities.GenerateKey();
            var b = BlockUtilities.GenerateKey();

            Assert.NotEqual(a, b);
        }
コード例 #2
0
    public override void OnInitializeEntity()
    {
        if (initialDirection != 1 && initialDirection != -1 || randomiseInitialDirection)
        {
            int r = UnityEngine.Random.Range(0, 2);

            if (r == 0)
            {
                currentDirection = 1;
            }
            else
            {
                currentDirection = -1;
            }
        }
        else
        {
            currentDirection = initialDirection;
        }

        eTransform.parent        = parentMap.transform;
        eTransform.localPosition = BlockUtilities.GetMathematicalPosition(parentMap, x, y, z);

        ProcessPatrolNode();
    }
コード例 #3
0
    void Awake()
    {
        //First we will create our map using the parameters we have set
        createdMap = BlockUtilities.CreateBlockMap(mapName, tileSize, chunkWidth, chunkHeight, growthAxis);

        //Now we will create a big old block of cubes, according to the dimensions we've set above
        for (int x = 0; x < levelWidth; x++)
        {
            for (int y = 0; y < levelWidth; y++)
            {
                for (int z = 0; z < levelDepth; z++)
                {
                    //We instantiate the block outside of the BlockUtilites library
                    //I've made it this way to allow you to pool GameObjects or anything you like
                    //So you have control over where your blocks come from
                    Block b = GameObject.Instantiate(blockPrefab) as Block;

                    //Now we add the block to the map at the desired coordinates
                    //We won't randomise or refresh at this point, as we're creating a large map
                    //We will do that as one call later
                    BlockUtilities.AddBlockToMap(createdMap, b, false, 0, false, x, y, z, false, true);
                }
            }
        }

        //Now that our map has been created, we will refresh it
        //Refreshing your map sets your blocks to orient correctly
        //And gives you an opportunity to randomise your variants en'masse
        BlockUtilities.RefreshMap(createdMap, randomiseInitialMap);
    }
コード例 #4
0
    void RandomlyModifyMap()
    {
        //We'll retrieve the bounds of our map in order to pick a nice random block
        int x = UnityEngine.Random.Range(0, BlockUtilities.GetMapWidth(createdMap));
        int y = UnityEngine.Random.Range(0, BlockUtilities.GetMapHeight(createdMap));

        //The depth is a little different from the width/height, as depth may be negative
        int z = UnityEngine.Random.Range(BlockUtilities.GetMapLowerDepth(createdMap), BlockUtilities.GetMapUpperDepth(createdMap));

        //Here we'll flip a figurative coin to decide if we'll add or remove
        if (UnityEngine.Random.Range(0, 2) == 1)
        {
            //We'll remove a block in this case
            BlockUtilities.RemoveBlockFromMap(createdMap, x, y, z, true, false);
        }
        else
        {
            //Again, we'll create a block
            Block b = GameObject.Instantiate(blockPrefab) as Block;

            //And then add it to the map
            //We'll randomise on addition
            //And pending our CleanMap parameter, we'll refresh the surrounding blocks
            BlockUtilities.AddBlockToMap(createdMap, b, true, 0, true, x, y, z, false, true);
        }
    }
コード例 #5
0
    public void HandleBlockEntry(int x, int y, int z)
    {
        Block b = BlockUtilities.GetBlockAt(parentMap, x, y, z);

        if (b != null)
        {
            b.ObjectEnteredBlock(this);
        }

        List <Entity> ce = controller.GetEntitiesAt(x, y, z);

        for (int i = 0; i < ce.Count; i++)
        {
            ce[i].OnEntityCollision(this);
            OnEntityCollision(ce[i]);
        }

        this.x = x;
        this.y = y;
        this.z = z;

        if (automaticallyReservePosition)
        {
            controller.ReserveBlock(entityType, new Vector3(x, y, z));
        }

        OnBlockEntry(x, y, z);
    }
コード例 #6
0
 /// <summary>
 /// Create a span model with customization options
 /// </summary>
 /// <param name="type">The type of the span, default is 'span'</param>
 /// <param name="text">The text to set in the span model</param>
 public SpanModel(string type = null, string text = null)
 {
     Type  = type ?? "span";
     Text  = text ?? string.Empty;
     Key   = BlockUtilities.GenerateKey();
     Marks = new List <string>();
 }
コード例 #7
0
 protected override SpanModel CreateSpan(HtmlNode node)
 {
     if (string.IsNullOrWhiteSpace(node.InnerText))
     {
         return(null);
     }
     return(new SpanModel(text: BlockUtilities.HtmlDecode(node.InnerText)));
 }
コード例 #8
0
 /// <summary>
 /// Create a block model with customization options
 /// </summary>
 /// <param name="type">The type of the block, default is 'block'</param>
 /// <param name="style">The style of the block, default is 'normal'</param>
 /// <param name="listItem">Specifies the type of a list item</param>
 /// <param name="level">Specifies the indentation level of a list item</param>
 public BlockModel(string type = null, string style = null, string listItem = null, int?level = null)
 {
     Type     = type ?? "block";
     Style    = style ?? "normal";
     ListItem = listItem;
     Level    = level;
     Key      = BlockUtilities.GenerateKey();
     Children = new List <SpanModel>();
     MarkDefs = new List <MarkDefModel>();
 }
コード例 #9
0
    //We wish to set the coordinates without triggering any Entry/Exit events
    protected void InitializeMapPosition()
    {
        Vector3 pos = BlockUtilities.GetMathematicalCoordinates(parentMap, eTransform.position);

        this.x = (int)pos.x;
        this.y = (int)pos.y;
        this.z = (int)pos.z;

        controller.ReserveBlock(entityType, new Vector3(x, y, z));
    }
コード例 #10
0
    public void SetMap(BlockMap map)
    {
        this.blockMap = map;

        InitializeStreamingMap(
            BlockUtilities.GetMapWidth(map),
            BlockUtilities.GetMapHeight(map),
            BlockUtilities.GetMapUpperDepth(map) - BlockUtilities.GetMapLowerDepth(map) + 1
            );
    }
コード例 #11
0
        private void ShowPreview(BlockPosition position, byte rotation)
        {
            Destroy(_previewObject);
            _previousPreviewPosition = position;
            BlockInfo info = BlockFactory.GetInfo(BlockFactory.GetType(_blockType));

            Color color;

            if (_structure.CanAddBlock(position, info, rotation))
            {
                color = Color.white;
            }
            else
            {
                if (_structure.IsPositionOccupied(position))
                {
                    return;
                }
                else
                {
                    color = Color.red;
                }
            }

            RealPlacedBlock block;

            if (info is SingleBlockInfo single)
            {
                block = BlockFactory.MakeSinglePlaced(_structure.transform, single, rotation, position);
            }
            else
            {
                // ReSharper disable once UnusedVariable
                block = BlockFactory.MakeMultiPlaced(_structure.transform, (MultiBlockInfo)info, rotation,
                                                     position, out PlacedMultiBlockPart[] parts);
                if (block == null)
                {
                    return;
                }
            }

            _previewObject = block.gameObject;
            _previewObject.gameObject.name = "PreviewBlock";
            BlockUtilities.RemoveCollider(_previewObject, true);

            color.a = 0.5f;
            BlockUtilities.SetColor(_previewObject, color, true);
        }
コード例 #12
0
    //Trigger-styled events that will send Block exit / Block entry messages
    public void HandleBlockExit(int x, int y, int z)
    {
        Block b = BlockUtilities.GetBlockAt(parentMap, x, y, z);

        if (b != null)
        {
            b.ObjectExitedBlock(this);
        }

        if (automaticallyReservePosition)
        {
            controller.UnreserveBlock(entityType, new Vector3(x, y, z));
        }

        OnBlockExit(x, y, z);
    }
コード例 #13
0
    protected bool BlockIsEmpty(int x, int y, int z)
    {
        if (!BlockUtilities.IsWithinMapBounds(parentMap, x, y, z))
        {
            return(false);
        }

        Block b = BlockUtilities.GetBlockAt(parentMap, x, y, z);

        if (b == null || (b.isNullBlock || b.actAsEmptyBlock))
        {
            return(true);
        }

        return(false);
    }
コード例 #14
0
    //We need to check if we have changed position
    public void UpdateMapPosition()
    {
        Vector3 pos = BlockUtilities.GetMathematicalCoordinates(parentMap, eTransform.position);

        //We temporarily store these values and will check against changes
        int t_x = (int)pos.x;
        int t_y = (int)pos.y;
        int t_z = (int)pos.z;

        //If our position has changed at all
        if (t_x != x || t_y != y || t_z != z)
        {
            HandleBlockExit(x, y, z);

            HandleBlockEntry(t_x, t_y, t_z);
        }
    }
コード例 #15
0
    //Generate our map
    public void GenerateMap(int width, int height, int depth,
                            string mapName, Vector3 tileScale,
                            int chunkWidth, int chunkHeight,
                            BlockMap.GrowthAxis growthAxis,
                            float deleteUpdateRate, float createUpdateRate, int actionsPerPass)
    {
        this.deleteRate     = deleteUpdateRate;
        this.createRate     = createUpdateRate;
        this.actionsPerPass = actionsPerPass;

        if (this.blockMap == null)
        {
            InitializeStreamingMap(width, height, depth);

            this.blockMap = BlockUtilities.CreateBlockMap(mapName, tileScale, chunkWidth, chunkHeight, growthAxis);
        }
    }
コード例 #16
0
    public void PathTo(int x, int y, int z)
    {
        currentPath.Clear();

        currentPath = BlockUtilities.GetPath(parentMap, this.x, this.y, (int)x, (int)y, z, false);

        if (currentPath == null || currentPath.Count <= 0)
        {
            currentPath = new List <Vector3>();
        }
        else
        {
            currentPath.Add(new Vector3(x, y, z));
        }

        SetIsIdle(true);
    }
コード例 #17
0
    void OnDrawGizmos()
    {
        BlockMap map = parentMap;

        List <Vector3> v = currentPath;

        Gizmos.color = new Color(0.0f, 0.0f, 1.0f, 0.5f);

        for (int i = 0; i < v.Count; i++)
        {
            Vector3 pos = BlockUtilities.GetMathematicalPosition(map, (int)v[i].x, (int)v[i].y, (int)v[i].z);

            pos = map.transform.TransformPoint(pos);

            Gizmos.DrawSphere(pos, 0.5f);
        }
    }
コード例 #18
0
    void Start()
    {
        blocks                      = new List <GameObject>();
        userId                      = System.Guid.NewGuid().ToString();
        blocksService               = new BlocksService(userId);
        blocksService.BlockAdded   += new BlockAddEventHandler(handleBlockAdded);
        blocksService.BlockRemoved += new BlockRemoveEventHandler(handleBlockRemoved);
        blocksService.Start();
        blockTypeToGameObject    = new Dictionary <int, GameObject>();
        blockTypeToGameObject[0] = Block0;
        blockTypeToGameObject[1] = Block1;
        blockTypeToGameObject[2] = Block2;
        blockTypeToGameObject[3] = Block3;
        blockTypeToGameObject[4] = Block4;


        blockUtilities = new BlockUtilities();
    }
コード例 #19
0
    void AddPlayerToMap()
    {
        player_x = start_player_x;
        player_y = start_player_y;

        streamingMap.DrawMap(player_x, player_y, 1, drawRadius, true);

        //We want to draw the map before we add the player
        player = GameObject.Instantiate(playerPrefab) as PlatformerPlayer;

        Vector3 coords = BlockUtilities.GetMathematicalPosition(streamingMap.blockMap, player_x, player_y, 0);

        player.transform.parent = streamingMap.blockMap.transform;

        player.transform.localPosition = coords;

        player.InitializeEntity(streamingMap.blockMap);
    }
コード例 #20
0
ファイル: PathingEntity.cs プロジェクト: chapayGhub/GGJ13
    public void PathTo(int x, int y, int z)
    {
        currentPath.Clear();

        currentPath = BlockUtilities.GetPath(parentMap, this.x, this.y, (int)x, (int)y, z, false);

        if (currentPath == null || currentPath.Count <= 0)
        {
            currentPath = new List <Vector3>();
            //Debug.Log ("empty path");
        }
        else
        {
            //Debug.Log ("adding path: " + x + " " + y + " " + z);
            currentPath.Add(new Vector3(x, y, z));
        }

        SetIsIdle(true);
    }
コード例 #21
0
    void OnDrawGizmos()
    {
        BlockMap map = GameObject.FindObjectOfType(typeof(BlockMap)) as BlockMap;

        foreach (string s in reservationRegister.Keys)
        {
            List <Vector3> v = new List <Vector3>(reservationRegister[s]);

            Gizmos.color = new Color(0.0f, 1.0f, 0.0f, 0.5f);

            for (int i = 0; i < v.Count; i++)
            {
                Vector3 pos = BlockUtilities.GetMathematicalPosition(map, (int)v[i].x, (int)v[i].y, (int)v[i].z);

                pos = map.transform.TransformPoint(pos);

                Gizmos.DrawSphere(pos, 0.5f);
            }
        }
    }
コード例 #22
0
    void DestroyBlock(Vector3 coords)
    {
        int x = (int)coords.x;
        int y = (int)coords.y;
        int z = (int)coords.z;

        Block         b  = BlockUtilities.GetBlockAt(blockMap, x, y, z);
        OrientedBlock ob = null;

        if (b != null)
        {
            ob = b as OrientedBlock;
        }

        if (ob != null)
        {
            StreamingMapNode n = GetNodeAt(x, y, z);

            if (n != null)
            {
                n.variantIndex = ob.GetCurrentVariant();
            }

            GameObject cio = ob.GetCurrentInstantiatedObject();

            if (cio != null)
            {
                TidyMapBoundObject mbo = cio.GetComponentInChildren <TidyMapBoundObject>();

                if (mbo != null)
                {
                    if (!mbo.DestroyWhenStreaming())
                    {
                        return;
                    }
                }
            }
        }

        BlockUtilities.AddBlockToMap(blockMap, null, false, 0, true, x, y, z, false, false);
    }
コード例 #23
0
        private void ColorNotConnectedBlocks()
        {
            foreach (RealPlacedBlock block in _previousNotConnected)
            {
                BlockUtilities.SetColor(block.gameObject, Color.white, false);
            }
            _previousNotConnected.Clear();

            IDictionary <BlockPosition, IPlacedBlock> notConnected = _structure.GetNotConnectedBlocks();

            if (notConnected == null)
            {
                return;
            }

            foreach (RealPlacedBlock real in notConnected.Values.OfType <RealPlacedBlock>())
            {
                BlockUtilities.SetColor(real.gameObject, Color.red, false);
                _previousNotConnected.Add(real);
            }
        }
コード例 #24
0
    protected bool CanMoveTo(int x, int y, int z)
    {
        if (!BlockUtilities.IsWithinMapBounds(parentMap, x, y, z))
        {
            return(false);
        }

        if (!controller.CanMoveTo(x, y, z))
        {
            return(false);
        }

        Block b = BlockUtilities.GetBlockAt(parentMap, x, y, z);

        if (b == null || b.isNullBlock || b.actAsEmptyBlock)
        {
            return(true);
        }

        return(false);
    }
コード例 #25
0
    //We'll construct the map here
    void ConstructLevel()
    {
        bool[,] map = GetLevelMap(levelWidth, levelHeight);

        //We'll go ahead and create our map now
        createdMap = BlockUtilities.CreateBlockMap(mapName, tileSize, chunkWidth, chunkHeight, growthAxis);

        //We're just going to iterate through the level we got back from the
        //function (trusting that it's correctly sized)
        for (int x = 0; x < levelWidth; x++)
        {
            for (int y = 0; y < levelHeight; y++)
            {
                if (map[x, y])
                {
                    Block b = GameObject.Instantiate(blockPrefab) as Block;

                    //We'll add our instantiated block here
                    //And we will not refresh just yet -
                    //it's better to refresh and clean at the end
                    BlockUtilities.AddBlockToMap(createdMap, b, false, 0, false, x, y, 0, false, false);
                }
                else
                {
                    if (useEmptyBlocks)
                    {
                        BlockUtilities.AddBlockToMap(createdMap, null, false, 0, false, x, y, 0, false, true);
                    }
                }
            }
        }

        //And now we refresh our map
        BlockUtilities.RefreshMap(createdMap, randomiseInitialMap);

        //Done!
        //Enjoy!
    }
コード例 #26
0
ファイル: PathingEntity.cs プロジェクト: chapayGhub/GGJ13
    public bool CanWalkTo(int x, int y, int z)
    {
        if (!BlockUtilities.IsWithinMapBounds(parentMap, x, y, z))
        {
            //Debug.Log("Cannot walk to "+ x + "," + y + "," + z+": bounds");
            return(false);
        }

        if (!controller.CanMoveTo(x, y, z))
        {
            //Debug.Log("Cannot walk to "+ x + "," + y + "," + z+": controller");
            return(false);
        }

        Block b = BlockUtilities.GetBlockAt(parentMap, x, y, z);

        if (b == null || b.isNullBlock || b.actAsEmptyBlock)
        {
            //Debug.Log("Can walk to "+ x + "," + y + "," + z+": not null");
            return(true);
        }

        return(false);
    }
コード例 #27
0
    public void ProcessPatrolNode()
    {
        sourcePosition = eTransform.localPosition;

        if (IsStuck())
        {
            OnCannotMove(x, y, z);
            return;
        }

        if (patrolAxis == PatrolAxis.Horizontal)
        {
            targetCoords   = new Vector3(x + currentDirection, y, z);
            targetPosition = BlockUtilities.GetMathematicalPosition(parentMap, x + currentDirection, y, z);
        }
        else if (patrolAxis == PatrolAxis.Vertical)
        {
            targetCoords   = new Vector3(x, y + currentDirection, z);
            targetPosition = BlockUtilities.GetMathematicalPosition(parentMap, x, y + currentDirection, z);
        }

        if (!CanMoveTo((int)targetCoords.x, (int)targetCoords.y, (int)targetCoords.z))
        {
            ReachEndOfPatrol(x, y, z);

            return;
        }
        controller.ReserveBlock(entityType, targetCoords);

        //Now decide where we're facing
        int x_dir = x - (int)targetCoords.x;
        int y_dir = (int)targetCoords.y - y;

        if (x_dir > 0)
        {
            eTransform.up      = upDirection;
            eTransform.forward = rightDirection;
        }
        else if (x_dir < 0)
        {
            eTransform.up      = upDirection;
            eTransform.forward = leftDirection;
        }
        else if (y_dir > 0)
        {
            if (parentMap.growthAxis == BlockMap.GrowthAxis.Forward)
            {
                eTransform.forward = frontDirection;
            }
            else
            {
                eTransform.forward = downDirection;
                Vector3 rot = eTransform.localRotation.eulerAngles;
                rot.y = 0.0f;
                eTransform.localRotation = Quaternion.Euler(rot);
            }
        }
        else if (y_dir < 0)
        {
            if (parentMap.growthAxis == BlockMap.GrowthAxis.Forward)
            {
                eTransform.forward = backDirection;
            }
            else
            {
                eTransform.forward = upDirection;
            }
        }

        SetIsMoving(true);
    }
コード例 #28
0
ファイル: PathingEntity.cs プロジェクト: chapayGhub/GGJ13
 void InitializePosition()
 {
     eTransform.localPosition = BlockUtilities.GetMathematicalPosition(parentMap, x, y, z);
 }
コード例 #29
0
    //Instantiate our block! Wrap the AssetPool functions nicely
    void InstantiateBlock(Vector3 coords)
    {
        int x = (int)coords.x;
        int y = (int)coords.y;
        int z = (int)coords.z;

        StreamingMapNode n = GetNodeAt(x, y, z);

        Block b  = null;
        int   bv = 0;

        if (n != null)
        {
            b  = n.blockPrefab;
            bv = n.variantIndex;
        }

        Block toAdd = null;

        if (b != null)
        {
            GameObject o = AssetPool.Instantiate(b.gameObject) as GameObject;

#if UNITY_4_0
            o.SetActive(true);
#else
//			o.SetActiveRecursively (true);
#endif

            toAdd = o.GetComponent <Block>();

            OrientedBlock ob = toAdd as OrientedBlock;

            if (ob != null)
            {
                ob.PreRandomiseBlockOrientations();
            }
        }

        if (n != null && n.HasVariant())
        {
            BlockUtilities.AddBlockToMap(blockMap, toAdd, false, bv, true, x, y, z, false, false);
        }
        else
        {
            BlockUtilities.AddBlockToMap(blockMap, toAdd, true, bv, true, x, y, z, false, false);
        }

        if (n != null)
        {
            if (!n.HasVariant())
            {
                Vector3 focus = new Vector3(focus_x, focus_y, focus_z);

                if (!IsOnOuterRim(focus, coords))
                {
                    //Let's save the variant so that we always get a consistent map
                    //It saves the programmer having to randomise this themselves
                    OrientedBlock ob = BlockUtilities.GetBlockAt(blockMap, x, y, z) as OrientedBlock;

                    if (ob != null)
                    {
                        n.variantIndex = ob.GetCurrentVariant();
                    }
                }
            }
        }
    }
コード例 #30
0
ファイル: PathingEntity.cs プロジェクト: chapayGhub/GGJ13
    public void ProcessPathing()
    {
        //Debug.Log(name + " Processing pathing at: " + x + "," + y + "," + z);

        if (currentPath.Count <= 0)
        {
            //Debug.Log ("End path");
            OnReachPathEnd(x, y, z);

            return;
        }

        if (currentPath.Count > 0)
        {
            Vector3 targetNode = currentPath[0];

            currentPath.RemoveAt(0);

            if (!CanWalkTo((int)targetNode.x, (int)targetNode.y, z))
            {
                currentPath.Clear();

                Idle();

                return;
            }

            targetCoords   = new Vector3(targetNode.x, targetNode.y, z);
            targetPosition = BlockUtilities.GetMathematicalPosition(parentMap, (int)targetNode.x, (int)targetNode.y, z);

            controller.ReserveBlock(entityType, targetCoords);

            startPosition = eTransform.localPosition;

            //Debug.Log(name + " Moving to: " + targetCoords.ToString());

            currentLerpAmount = 0.0f;

            isMoving = true;

            //Now decide where we're facing
            int x_dir = x - (int)targetCoords.x;
            int y_dir = (int)targetCoords.y - y;

            if (x_dir > 0)
            {
                eTransform.up      = upDirection;
                eTransform.forward = rightDirection;
            }
            else if (x_dir < 0)
            {
                eTransform.up      = upDirection;
                eTransform.forward = leftDirection;
            }
            else if (y_dir > 0)
            {
                if (parentMap.growthAxis == BlockMap.GrowthAxis.Forward)
                {
                    eTransform.forward = frontDirection;
                }
                else
                {
                    eTransform.forward = downDirection;
                    Vector3 rot = eTransform.localRotation.eulerAngles;
                    rot.y = 0.0f;
                    eTransform.localRotation = Quaternion.Euler(rot);
                }
            }
            else if (y_dir < 0)
            {
                if (parentMap.growthAxis == BlockMap.GrowthAxis.Forward)
                {
                    eTransform.forward = backDirection;
                }
                else
                {
                    eTransform.forward = upDirection;
                }
            }
        }
        else
        {
            Idle();
        }
    }