Example #1
0
 // Does nothing if there is no voxel at the given pos or if we're removing the origin block
 public void RemoveVoxel(Vector3Int pos)
 {
     if (_data.ContainsKey(pos) && pos != Vector3Int.Zero)
     {
         _data.Remove(pos);
     }
 }
Example #2
0
    public void FindEndPosition(Vector3Int endPosition, Vector3Int direction, int multiplier)
    {
        positions.Add(endPosition);
        //Debug.Log(endPosition);
        int jumpHeight = ((position.y - endPosition.y)*multiplier)+1;
        if (jumpHeight > 0) {
            Vector3Int aux = new Vector3Int (endPosition.ToVector3 + direction.ToVector3);
            aux.y += jumpHeight;
            aux = CubeHelper.GetTopPosition (aux.ToVector3);

            if (aux.y > endPosition.y) {
                if (aux.y < (endPosition.y + jumpHeight)) {
                    EndPosition = aux;
                }
            } else if (aux.y < endPosition.y) {
                position=endPosition;
                EndPosition = aux;
                if (endPosition.y > 1 && !CubeHelper.IsFree(new Vector3Int(aux.ToVector3 + Vector3.down)) && Level.Singleton.getEntity (aux.ToVector3 + Vector3.down) is RubberCube) {
                    FindEndPosition (aux, direction, 2);
                } else {
                    FindEndPosition (aux, direction, 1);
                }
            }else{
                EndPosition = endPosition;
            }
        }else{
            EndPosition = endPosition;
        }
    }
Example #3
0
 public static VoxelCommand Remove(Vector3Int pos)
 {
     VoxelCommand cmd = new VoxelCommand ();
     cmd._type = Type.Remove;
     cmd._pos = pos;
     return cmd;
 }
    public override void MoveTo(Vector3Int nextPosition)
    {
        //if (!Level.Singleton.ContainsElement (nextPosition)) {
            Level.Singleton.RemoveEntity (new Vector3Int (transform.position));
            Level.Singleton.AddEntity (this, nextPosition);
            //transform.position = nextPosition.ToVector3
        if(positions.Count>1){
            positions.Add(nextPosition);

            List<Vector3> nextPositions = new List<Vector3>();
            //Debug.Log(positions.Count);
            foreach (Vector3Int vector  in positions)
            {
                if(vector.y>0){
                    Debug.Log(vector);
                    nextPositions.Add(vector.ToVector3);
                }
            }
            CubeAnimations.AnimateBounce (gameObject, Vector3.down, nextPositions.ToArray());
            //Debug.Log(positions[0]);
            positions.RemoveAt(0);
        }else{
            positions = new List<Vector3Int>();
            CubeAnimations.AnimateMove (gameObject, Vector3.down, nextPosition.ToVector3);
        }
        //	CubeAnimations.AnimateMove (gameObject, Vector3.down, nextPosition.ToVector3);
        //}
    }
    public bool SlideTo(bool first)
    {
        Vector3Int next = new Vector3Int(EndPosition.x+Direction.x,EndPosition.y+Direction.y,EndPosition.z+Direction.z);
        if(CubeHelper.IsFree(next) && Cube.transform.position+Direction.ToVector3+Vector3.up!=  EndPosition.ToVector3){
            Level.Singleton.notifySwitches(EndPosition);
        }
        if (EndPosition.y == new Vector3Int (Cube.transform.position).y+1){
            return true;
        }

        if(!finished && CubeHelper.IsFree(next) && next.x <= 10 && next.x >= 0 && next.z <= 10 && next.z >= 0){
            EndPosition = next;
            return SlideTo(false);
        }else if(next.x > 10 || next.x < 0 || next.z > 10 || next.z < 0){
                //Cube.FallOutOfBounds(next.ToVector3);
                EndPosition = next;
                return true;

        }
        if(Level.Singleton.getEntity(next.ToVector3) is RockCube ){
            IceCube ic = (IceCube)Cube;
            ic.Break();
            return true;
        }
        while(CubeHelper.IsFree(new Vector3Int(EndPosition.ToVector3 + Vector3.down)) && EndPosition.y > 1){
            Level.Singleton.notifySwitches(EndPosition);
            EndPosition = new Vector3Int(EndPosition.ToVector3 + Vector3.down);
        }
        return true;
    }
Example #6
0
 public Voxel(Vector3Int pos, Color color)
 {
     Pos = pos;
     _r = color.r;
     _g = color.g;
     _b = color.b;
     _a = color.a;
 }
Example #7
0
 public Bounce(Cube receiver, Vector3Int endPosition, Vector3Int direction)
     : base(receiver, endPosition)
 {
     positions = new List<Vector3Int>();
     position = new Vector3Int (Cube.transform.position);
     Cube = receiver;
     if (endPosition.y > 1 && Level.Singleton.getEntity (endPosition.ToVector3 + Vector3.down) is RubberCube) {
         FindEndPosition (endPosition, direction, 2);
     } else {
         FindEndPosition (endPosition, direction, 1);
     }
 }
    /// <summary>
    /// Checks if the position given is available based on the jump power, Returns null if its not available
    /// </summary>
    public static bool CheckAvailablePosition(Vector3 position, out Vector3Int finalPosition, int height)
    {
        if (Level.Singleton.IsInDimension (position)) {

            finalPosition = GetTopPosition (position);
            return (finalPosition.y - Mathf.RoundToInt (position.y) <= height);

        } else {
            finalPosition = null;
            return false;
        }
    }
Example #9
0
        /**
         *
         */
        public override bool GetTileData(Vector3Int location, ITileMap tileMap, ref TileData tileData)
        {
            base.GetTileData(location, tileMap, ref tileData);

            int mask = GetMask(location, tileMap, ref tileData);
            int index = GetIndex(mask);

            tileData.sprite = GetTileSprite(index);
            tileData.gameobject = GetTileGameObject(index);

            return true;
        }
    public override void MoveTo(Vector3Int nextPosition)
    {
        Vector3Int below = new Vector3Int(nextPosition.x,nextPosition.y,nextPosition.z);
        below.y--;
        if(stuck){
            stuck = false;
        }
        if(CubeHelper.IsFree(below)&& below.y>0){
            stuck = true;
        }

        base.MoveTo (nextPosition);
    }
Example #11
0
 public void RemoveVoxel(Vector3Int pos)
 {
     if (_voxelData.HasVoxelAtPos(pos))
     {
         Voxel voxel = new Voxel();
         voxel = _voxelData.VoxelAtPos(pos);
         _voxelData.RemoveVoxel(pos);
         _voxelRenderer.RenderMesh(_voxelData);
         _voxelAnimation.RemoveVoxelAnimation(true, voxel, () =>
         {
             // None needed
         });
     }
 }
Example #12
0
        /**
         *
         */
        public override void RefreshTile(Vector3Int location, ITileMap tileMap)
        {
            for (int y = -1; y <= 1; y++)
            {
                for (int x = -1; x <= 1; x++)
                {
                    Vector3Int position = new Vector3Int(location.x + x, location.y + y, location.z);

                    if (TileValue(tileMap, position))
                    {
                        tileMap.RefreshTile(position);
                    }
                }
            }
        }
 public override void NotifyPressed(Vector3Int position)
 {
     Pressed = !Pressed;
     Renderer r = gameObject.transform.GetChild(0).renderer;
     Material[] m = new Material[2];
     if(pressed){
         m[0] = r.material;
         m[1] = pressedMaterial;
         Level.Singleton.SensorActivated();
     }else{
         m[0] = r.material;
         m[1] = unpressedMaterial;
         Level.Singleton.SensorDeactivated();
     }
     r.materials = m;
 }
    void RandomTileMap()
    {
        TileMap map = GetComponent<TileMap>();

        int sizeX = 32;
        int sizeY = 16;

        for (int x = 0; x < sizeX; x++)
        {
            for (int y = 0; y < sizeY; y++)
            {
                var tilePos = new Vector3Int(x, y, 0);
                map.SetTile(tilePos, tiles[Random.Range(0, tiles.Length)]);
            }
        }
    }
    public override Command[] GetOptions()
    {
        if(transform.forward != Vector3.down && (!Level.Singleton.ContainsElement(transform.position+Vector3.down) || !Level.Singleton.getEntity(transform.position+Vector3.down) is BasicSensor)){
            setMood(Mood.Happy);
        }
        List<Command> commands = new List<Command>();
        if(!stuck || !CubeHelper.IsFree(new Vector3Int(transform.position+Vector3.down))){
            commands = CubeHelper.GetListOptions(base.GetOptions());
            Vector3Int pos;
            if (CubeHelper.CheckAvailablePosition(transform.position + Vector3.forward,out pos,GetJumpHeight())){
                if(new Vector3Int(transform.position).y-pos.y>1){
                 	pos = new Vector3Int(transform.position+Vector3.forward);
                    pos.y--;
                    commands.Add(new Move(this,pos));
                }
            }
            if (CubeHelper.CheckAvailablePosition(transform.position + Vector3.back,out pos,GetJumpHeight())){
                if(new Vector3Int(transform.position).y-pos.y>1){
                 	pos = new Vector3Int(transform.position+Vector3.back);
                    pos.y--;
                    commands.Add(new Move(this,pos));
                }
            }
            if (CubeHelper.CheckAvailablePosition(transform.position + Vector3.right,out pos,GetJumpHeight())){
                if(new Vector3Int(transform.position).y-pos.y>1){
                 	pos = new Vector3Int(transform.position+Vector3.right);
                    pos.y--;
                    commands.Add(new Move(this,pos));
                }
            }
            if (CubeHelper.CheckAvailablePosition(transform.position + Vector3.left,out pos,GetJumpHeight())){
                if(new Vector3Int(transform.position).y-pos.y>1){
                 	pos = new Vector3Int(transform.position+Vector3.left);
                    pos.y--;
                    commands.Add(new Move(this,pos));
                }
            }

        }else{
            Vector3Int pos;
            if(CubeHelper.CheckAvailablePosition(transform.position + Vector3.down,out pos,GetJumpHeight())){
                commands.Add(new Move(this,pos));
            }
        }
        return commands.ToArray();
    }
Example #16
0
 public override void MoveTo(Vector3Int nextPosition)
 {
     if(!hookMove){
         base.MoveTo (nextPosition);
     }else{
         if(Level.Singleton.getEntity(nextPosition.ToVector3+direction) is Cube){
             Cube c = (Cube)Level.Singleton.getEntity(nextPosition.ToVector3+direction);
             Level.Singleton.RemoveEntity(new Vector3Int(c.transform.position));
             Level.Singleton.AddEntity(this, nextPosition);
             CubeAnimations.AnimetSwing(gameObject,nextPosition.ToVector3);
             hookMove = false;
         }else{
             Level.Singleton.RemoveEntity(new Vector3Int(transform.position));
             Level.Singleton.AddEntity(this, nextPosition);
             CubeAnimations.AnimetSwing(gameObject,nextPosition.ToVector3);
             //transform.position = nextPosition.ToVector3;
             hookMove = false;
         }
     }
 }
Example #17
0
 /// <summary>
 /// Checks the last position in the specify direction.
 /// </summary>
 /// <returns>
 /// True if there is a last position and it isnt the.
 /// </returns>
 /// <param name='direction'>
 /// If set to <c>true</c> direction.
 /// </param>
 /// <param name='finalPosition'>
 /// If set to <c>true</c> final position.
 /// </param>
 /// 
 ///
 /// <summary>
 /// Checks the last position in the specify direction.
 /// </summary>
 /// <returns>
 ///  True if there is a last position and it isnt next to psition.
 /// </returns>
 /// <param name='position'>
 /// position to serch from
 /// </param>
 /// <param name='direction'>
 /// directin to serch
 /// </param>
 /// <param name='finalPosition'>
 /// out the las position. Vector3Int.zero return == false
 /// </param>
 /// 
 public static bool CheckLastPosition(Vector3Int position ,Vector3Int direction, out Vector3Int finalPosition)
 {
     Vector3Int aux = new Vector3Int(position.ToVector3);
     aux = aux.Add(direction.ToVector3);
     aux = aux.Add(direction.ToVector3);
     Vector3Int c;
     for(int i = 0; i < 11; i++){
         if(Level.Singleton.ContainsElement(aux)||aux.y==0){
             if(i>0 || aux.y==0){
                 finalPosition = aux.Add(new Vector3(direction.x*-1,direction.y*-1,direction.z*-1));
                 return true;
             }else{
                 finalPosition = new Vector3Int(Vector3.zero);
                 return false;
             }
         }
         aux = aux.Add(direction.ToVector3);
     }
     finalPosition = new Vector3Int(Vector3.zero);
     return false;
 }
Example #18
0
    public override Command[] GetOptions()
    {
        Vector3Int upPosition = new Vector3Int (transform.position + Vector3.up);
        List<Command> options = new List<Command>();
        if(CubeHelper.IsFree (upPosition) ){
            options = CubeHelper.GetListOptions(base.GetOptions());
        }
        Vector3Int pos;
        if(CubeHelper.CheckLastPosition(new Vector3Int(transform.position), new Vector3Int(Vector3.forward),out pos)){
            options.Add(new Swing(this,pos));
            direction = Vector3.forward;
        }
        if(CubeHelper.CheckLastPosition(new Vector3Int(transform.position), new Vector3Int(Vector3.back),out pos)){
            options.Add(new Swing(this,pos));
            direction = Vector3.back;
        }
        if(CubeHelper.CheckLastPosition(new Vector3Int(transform.position), new Vector3Int(Vector3.right),out pos)){
            options.Add(new Swing(this,pos));
            direction = Vector3.right;
        }
        if(CubeHelper.CheckLastPosition(new Vector3Int(transform.position), new Vector3Int(Vector3.left),out pos)){
            options.Add(new Swing(this,pos));
            direction = Vector3.left;
        }
        if(CubeHelper.CheckLastPosition(new Vector3Int(transform.position), new Vector3Int(Vector3.up),out pos)){
            options.Add(new Swing(this,pos));
            direction = Vector3.up;
        }
        if(transform.position.y>1){
            if(CubeHelper.CheckLastPosition(new Vector3Int(transform.position), new Vector3Int(Vector3.down),out pos)){
                options.Add(new Swing(this,pos));
                direction = Vector3.down;
            }
        }

        return options.ToArray();
    }
 public override void NotifyPressed(Vector3Int position)
 {
     Application.LoadLevel("Credits");
 }
Example #20
0
 public static Vector3Int Modulo(this Vector3Int v, int m)
     => new Vector3Int(v.x % m, v.y % m, v.z % m);
Example #21
0
 public static BoundsInt Encapsulate(this BoundsInt bounds, Vector3Int pos)
 {
     var min = Vector3Int.Min(bounds.min, pos);
     var max = Vector3Int.Max(bounds.max, pos + Vector3Int.one);
     return new BoundsInt(min, max - min);
 }
Example #22
0
 public override void OnEndExecution()
 {
     if(breakIce &&  endPosition.ToVector3 == new Vector3Int(transform.position).ToVector3){
         Level.Singleton.RemoveEntity(endPosition);
         Destroy(this.gameObject);
     }else if( endPosition.z != transform.position.z || endPosition.x != transform.position.x){
         CubeAnimations.AnimateSlide(gameObject, new Vector3Int(endPosition.x,Mathf.RoundToInt(transform.position.y),endPosition.z).ToVector3);
     }else if(  endPosition.y < transform.position.y){
         CubeAnimations.AnimateMove (gameObject, Vector3.down, endPosition.ToVector3);
     }
     Vector3Int next = new Vector3Int(transform.position);
     if(!breakIce && next.x > 10 || next.x < 0 || next.z > 10 || next.z < 0){
         Level.Singleton.RemoveEntity(new Vector3Int(transform.position));
         Destroy(gameObject);
     }
     if(transform.forward == Vector3.down && SpriteSheet.CurrentSequence!=(int)Mood.EyesClosed){
         SetMood(Mood.EyesClosed);
     }
 }
Example #23
0
    private bool IsDifferent(Vector3Int position, TileType tileType, string tileName)
    {
        LayerTile layerTile = TileManager.GetTile(tileType, tileName);

        return(metaTileMap.GetTile(position, layerTile.LayerType) != layerTile);
    }
Example #24
0
 public LayerTile GetLayerTile(Vector3Int cellPosition, LayerType layerType)
 {
     return(metaTileMap.GetTile(cellPosition, layerType));
 }
Example #25
0
        public void CalculateEnemyPath()
        {
            enemyPath = new List <Spot>();
            roadPath  = new List <Spot>();

            Vector3Int playerTilePos = PlayerMgr.Instance.GetTilePosOfPlayer();
            Vector3Int enemyTilePos  = GetTilePosOfEnemy();

            //If enemy not in player's node
            if (!enemyData.inPlayersNode && enemyData.nbMoves != 0)
            {
                int nbTiles = nbTilesPerMove * enemyData.nbMoves;

                // If this enemy was not centered, remove one tile to be centered on target node
                if (GetNodeOfEnemy().GetComponent <NodeScript>().node.enemyOnCenter != this)
                {
                    nbTiles--;
                }

                //Path creation
                roadPath = MapManager.Instance.astar.CreatePath(MapManager.Instance.grid,
                                                                new Vector2Int(enemyTilePos.x, enemyTilePos.z),
                                                                new Vector2Int(playerTilePos.x, playerTilePos.z),
                                                                nbTiles);

                if (roadPath == null)
                {
                    return;
                }

                bool isPlayerOnPath     = false;
                bool isOtherEnemyOnPath = false;

                roadPath.Reverse(); //Reverse the list to begin at the closest

                foreach (Spot tile in roadPath)
                {
                    //We keep all the tiles except the one with the player on it (if player on path obviously)
                    if (playerTilePos.x == tile.X && playerTilePos.z == tile.Y)
                    {
                        isPlayerOnPath          = true;
                        enemyData.inPlayersNode = true; //Enemy set as "in player's node"
                    }

                    // We check if there is an other enemy on path
                    foreach (EnemyScript enemy in EnemyMgr.Instance.GetAllEnemies())
                    {
                        //Node position of enemy
                        Vector3Int enemyNodePos = EnemyMgr.Instance.GetEnemyTilePos(enemy.transform);

                        //Check only other enemies than the one we are moving
                        if (enemy != this)
                        {
                            //If there is an enemy on tile
                            if (enemyNodePos.x == tile.X && enemyNodePos.z == tile.Y)
                            {
                                isOtherEnemyOnPath = true;
                            }
                        }
                    }

                    if (!isPlayerOnPath && !isOtherEnemyOnPath)
                    {
                        enemyPath.Add(tile);
                    }
                }

                if (enemyPath.Count == 0)
                {
                    return;
                }

                Node nextNode = MapManager.Instance.GetNodeFromPos(new Vector3Int(enemyPath[enemyPath.Count - 1].X, 0, enemyPath[enemyPath.Count - 1].Y)).GetComponent <NodeScript>().node;

                // If to much enemies on next node or path to short, cancel move
                if (nextNode.enemiesOnNode.Count >= 3 || enemyPath.Count < 3)
                {
                    tileIndex               = 0;
                    canMove                 = false; //Allow the movement mechanic
                    isMoveFinished          = true;  //Will be false until enemy move is not finished
                    enemyData.inPlayersNode = false;
                    return;
                }

                // The current node lost this enemy in its list
                Node lastNode = GetNodeOfEnemy().GetComponent <NodeScript>().node;
                lastNode.enemiesOnNode.Remove(this);

                // If it was the enemy on center, check if we can recenter an enemy on it
                if (lastNode.enemyOnCenter == this)
                {
                    lastNode.enemyOnCenter = null;

                    EnemyMgr.Instance.RecenterAnEnemyOnNode(lastNode);
                }

                //If enemy is Curse-Occhio, we add fog on last node
                if (enemyData.isCursed)
                {
                    FogMgr.Instance.AddFogOnNode(GetNodeOfEnemy());
                }


                // The next node get this enemy in its list
                nextNode.enemiesOnNode.Add(this);

                // Set enemy on center of next node to this enemy if there is nobody on it
                if (nextNode.enemyOnCenter == null && nextNode != PlayerMgr.Instance.GetNodeOfPlayer().GetComponent <NodeScript>().node)
                {
                    nextNode.enemyOnCenter = this;
                }

                // Rare possibility : When an enemy has to move 2 nodes, check with nb of tiles in path if an enemy not centered is on path
                // In that case, his next node will be the node before the targeted, so remove the last tile to stop on center of real next node
                if (enemyData.nbMoves == 2 && enemyPath.Count == 5)
                {
                    enemyPath.RemoveAt(enemyPath.Count - 1);
                    print(name + " was not centered so remove one tile of path");
                }

                enemyPath.RemoveAt(0); //Remove the first which is the tile the enemy is on

                tileIndex      = 0;
                canMove        = true;  //Allow the movement mechanic
                isMoveFinished = false; //Will be false until enemy move is not finished
            }
            else
            {
                isMoveFinished = true;
            }

            //SFX fog clear
            MusicManager.Instance.PlayEnemyMoving();
        }
    public override void Pick(GridLayout gridLayout, GameObject brushTarget, BoundsInt position, Vector3Int pivot)
    {
        // Want to make sure people can only pick one prefab at a time
        //BoundsInt bounds = new BoundsInt(min, randomBrush.size);
        //if(position.allPositionsWithin.MoveNext() == position.allPositionsWithin.)
        //{
        //    Debug.LogWarning("You can only pick one tile at a time with sortedTileBrush!");
        //    return;
        //}

        Vector3Int brushPosition = new Vector3Int(position.position.x, position.position.y, 0);
        Tilemap    map           = brushTarget.GetComponent <Tilemap>();
        PrefabTile tile          = map.GetTile <PrefabTile>(brushPosition);

        if (tile)
        {
            tilePrefab = tile.tilePrefab;
        }
        else
        {
            Debug.Log("Brush position: " + brushPosition);
        }
    }
 Vector3Int TextureToWorld(Vector3Int texpos)
 {
     return(new Vector3Int(texpos.x - tintTexture.width / 2, texpos.y - tintTexture.height / 2, 0));
 }
 Vector3Int WorldToTexture(Vector3Int world)
 {
     return(new Vector3Int(world.x + tintTexture.width / 2, world.y + tintTexture.height / 2, 0));
 }
    public void MarchWithoutInterpolation(Vector3Int pOffset, MarchingMaster pMarchingMaster)
    {
        m_lTriangles = new List <Triangle>();

        for (int z = 0; z < 17; z++)
        {
            for (int y = 0; y < 17; y++)
            {
                for (int x = 0; x < 17; x++)
                {
                    // Construct a cube from this point outwards
                    // Stores the position and density of each of the eight points
                    float[,] wireCube = new float[8, 4];

                    // Fills the cube with data
                    wireCube[0, 0] = x + 0; wireCube[0, 1] = y + 0; wireCube[0, 2] = z + 0; wireCube[0, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 0, y + pOffset.y + 0, z + pOffset.z + 0];
                    wireCube[1, 0] = x + 1; wireCube[1, 1] = y + 0; wireCube[1, 2] = z + 0; wireCube[1, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 1, y + pOffset.y + 0, z + pOffset.z + 0];
                    wireCube[2, 0] = x + 1; wireCube[2, 1] = y + 0; wireCube[2, 2] = z + 1; wireCube[2, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 1, y + pOffset.y + 0, z + pOffset.z + 1];
                    wireCube[3, 0] = x + 0; wireCube[3, 1] = y + 0; wireCube[3, 2] = z + 1; wireCube[3, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 0, y + pOffset.y + 0, z + pOffset.z + 1];
                    wireCube[4, 0] = x + 0; wireCube[4, 1] = y + 1; wireCube[4, 2] = z + 0; wireCube[4, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 0, y + pOffset.y + 1, z + pOffset.z + 0];
                    wireCube[5, 0] = x + 1; wireCube[5, 1] = y + 1; wireCube[5, 2] = z + 0; wireCube[5, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 1, y + pOffset.y + 1, z + pOffset.z + 0];
                    wireCube[6, 0] = x + 1; wireCube[6, 1] = y + 1; wireCube[6, 2] = z + 1; wireCube[6, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 1, y + pOffset.y + 1, z + pOffset.z + 1];
                    wireCube[7, 0] = x + 0; wireCube[7, 1] = y + 1; wireCube[7, 2] = z + 1; wireCube[7, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 0, y + pOffset.y + 1, z + pOffset.z + 1];

                    // Determines the unique index for each cube
                    byte cubeIndex = 0;
                    if (wireCube[0, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 1;                                                     // Point 0 is below the isosurface
                    }
                    if (wireCube[1, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 2;                                                     // Point 1 is below the isosurface
                    }
                    if (wireCube[2, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 4;                                                     // Point 2 is below the isosurface
                    }
                    if (wireCube[3, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 8;                                                     // Point 3 is below the isosurface
                    }
                    if (wireCube[4, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 16;                                                   // Point 4 is below the isosurface
                    }
                    if (wireCube[5, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 32;                                                   // Point 5 is below the isosurface
                    }
                    if (wireCube[6, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 64;                                                   // Point 6 is below the isosurface
                    }
                    if (wireCube[7, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 128;                                                 // Point 7 is below the isosurface
                    }
                    // Create triangles for current cube configuration without interpolation
                    for (int i = 0; m_mtMarchTable.triTable[cubeIndex, i] != -1; i += 3)
                    {
                        Triangle tri;

                        // Gets the edge number based on what triangle should be constructed
                        int a = m_mtMarchTable.triTable[cubeIndex, i + 1];
                        int b = m_mtMarchTable.triTable[cubeIndex, i];
                        int c = m_mtMarchTable.triTable[cubeIndex, i + 2];

                        // Converts the edge numbers to positions then pushes to triangle
                        Vector3 aOffSet;
                        Vector3 bOffSet;
                        Vector3 cOffSet;

                        // Brute forcing a
                        switch (a)
                        {
                        case 0: aOffSet = new Vector3(0.5f, 0, 0); break;

                        case 1: aOffSet = new Vector3(1, 0, 0.5f); break;

                        case 2: aOffSet = new Vector3(0.5f, 0, 1); break;

                        case 3: aOffSet = new Vector3(0, 0, 0.5f); break;

                        case 4: aOffSet = new Vector3(0.5f, 1, 0); break;

                        case 5: aOffSet = new Vector3(1, 1, 0.5f); break;

                        case 6: aOffSet = new Vector3(0.5f, 1, 1); break;

                        case 7: aOffSet = new Vector3(0, 1, 0.5f); break;

                        case 8: aOffSet = new Vector3(0, 0.5f, 0); break;

                        case 9: aOffSet = new Vector3(1, 0.5f, 0); break;

                        case 10: aOffSet = new Vector3(1, 0.5f, 1); break;

                        case 11: aOffSet = new Vector3(0, 0.5f, 1); break;

                        default: aOffSet = new Vector3(0, 0, 0); break;
                        }

                        // Brute forcing b
                        switch (b)
                        {
                        case 0: bOffSet = new Vector3(0.5f, 0, 0); break;

                        case 1: bOffSet = new Vector3(1, 0, 0.5f); break;

                        case 2: bOffSet = new Vector3(0.5f, 0, 1); break;

                        case 3: bOffSet = new Vector3(0, 0, 0.5f); break;

                        case 4: bOffSet = new Vector3(0.5f, 1, 0); break;

                        case 5: bOffSet = new Vector3(1, 1, 0.5f); break;

                        case 6: bOffSet = new Vector3(0.5f, 1, 1); break;

                        case 7: bOffSet = new Vector3(0, 1, 0.5f); break;

                        case 8: bOffSet = new Vector3(0, 0.5f, 0); break;

                        case 9: bOffSet = new Vector3(1, 0.5f, 0); break;

                        case 10: bOffSet = new Vector3(1, 0.5f, 1); break;

                        case 11: bOffSet = new Vector3(0, 0.5f, 1); break;

                        default: bOffSet = new Vector3(0, 0, 0); break;
                        }

                        // Brute forcing c
                        switch (c)
                        {
                        case 0: cOffSet = new Vector3(0.5f, 0, 0); break;

                        case 1: cOffSet = new Vector3(1, 0, 0.5f); break;

                        case 2: cOffSet = new Vector3(0.5f, 0, 1); break;

                        case 3: cOffSet = new Vector3(0, 0, 0.5f); break;

                        case 4: cOffSet = new Vector3(0.5f, 1, 0); break;

                        case 5: cOffSet = new Vector3(1, 1, 0.5f); break;

                        case 6: cOffSet = new Vector3(0.5f, 1, 1); break;

                        case 7: cOffSet = new Vector3(0, 1, 0.5f); break;

                        case 8: cOffSet = new Vector3(0, 0.5f, 0); break;

                        case 9: cOffSet = new Vector3(1, 0.5f, 0); break;

                        case 10: cOffSet = new Vector3(1, 0.5f, 1); break;

                        case 11: cOffSet = new Vector3(0, 0.5f, 1); break;

                        default: cOffSet = new Vector3(0, 0, 0); break;
                        }

                        tri.vertexA = new Vector3(wireCube[0, 0], wireCube[0, 1], wireCube[0, 2]) + aOffSet;
                        tri.vertexB = new Vector3(wireCube[0, 0], wireCube[0, 1], wireCube[0, 2]) + bOffSet;
                        tri.vertexC = new Vector3(wireCube[0, 0], wireCube[0, 1], wireCube[0, 2]) + cOffSet;

                        m_lTriangles.Add(tri);
                    }
                }
            }
        }
    }
    public void MarchWithInterpolation(Vector3Int pOffset, MarchingMaster pMarchingMaster)
    {
        m_lTriangles = new List <Triangle>();

        for (int z = 0; z < 17; z++)
        {
            for (int y = 0; y < 17; y++)
            {
                for (int x = 0; x < 17; x++)
                {
                    // Construct a cube from this point outwards
                    // Stores the position and density of each of the eight points
                    float[,] wireCube = new float[8, 4];

                    // Fills the cube with data
                    wireCube[0, 0] = x + 0; wireCube[0, 1] = y + 0; wireCube[0, 2] = z + 0; wireCube[0, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 0, y + pOffset.y + 0, z + pOffset.z + 0];
                    wireCube[1, 0] = x + 1; wireCube[1, 1] = y + 0; wireCube[1, 2] = z + 0; wireCube[1, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 1, y + pOffset.y + 0, z + pOffset.z + 0];
                    wireCube[2, 0] = x + 1; wireCube[2, 1] = y + 0; wireCube[2, 2] = z + 1; wireCube[2, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 1, y + pOffset.y + 0, z + pOffset.z + 1];
                    wireCube[3, 0] = x + 0; wireCube[3, 1] = y + 0; wireCube[3, 2] = z + 1; wireCube[3, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 0, y + pOffset.y + 0, z + pOffset.z + 1];
                    wireCube[4, 0] = x + 0; wireCube[4, 1] = y + 1; wireCube[4, 2] = z + 0; wireCube[4, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 0, y + pOffset.y + 1, z + pOffset.z + 0];
                    wireCube[5, 0] = x + 1; wireCube[5, 1] = y + 1; wireCube[5, 2] = z + 0; wireCube[5, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 1, y + pOffset.y + 1, z + pOffset.z + 0];
                    wireCube[6, 0] = x + 1; wireCube[6, 1] = y + 1; wireCube[6, 2] = z + 1; wireCube[6, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 1, y + pOffset.y + 1, z + pOffset.z + 1];
                    wireCube[7, 0] = x + 0; wireCube[7, 1] = y + 1; wireCube[7, 2] = z + 1; wireCube[7, 3] = pMarchingMaster.m_fVolumeData[x + pOffset.x + 0, y + pOffset.y + 1, z + pOffset.z + 1];

                    // Determines the unique index for each cube
                    byte cubeIndex = 0;
                    if (wireCube[0, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 1;                                                     // Point 0 is below the isosurface
                    }
                    if (wireCube[1, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 2;                                                     // Point 1 is below the isosurface
                    }
                    if (wireCube[2, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 4;                                                     // Point 2 is below the isosurface
                    }
                    if (wireCube[3, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 8;                                                     // Point 3 is below the isosurface
                    }
                    if (wireCube[4, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 16;                                                   // Point 4 is below the isosurface
                    }
                    if (wireCube[5, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 32;                                                   // Point 5 is below the isosurface
                    }
                    if (wireCube[6, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 64;                                                   // Point 6 is below the isosurface
                    }
                    if (wireCube[7, 3] < pMarchingMaster.m_fSurface)
                    {
                        cubeIndex |= 128;                                                 // Point 7 is below the isosurface
                    }
                    // Create triangles for current cube configuration with interpolation
                    for (int i = 0; m_mtMarchTable.triTable[cubeIndex, i] != -1; i += 3)
                    {
                        int a1 = m_mtMarchTable.cornerIndexAFromEdge[m_mtMarchTable.triTable[cubeIndex, i + 1]];
                        int a2 = m_mtMarchTable.cornerIndexBFromEdge[m_mtMarchTable.triTable[cubeIndex, i + 1]];

                        int b1 = m_mtMarchTable.cornerIndexAFromEdge[m_mtMarchTable.triTable[cubeIndex, i]];
                        int b2 = m_mtMarchTable.cornerIndexBFromEdge[m_mtMarchTable.triTable[cubeIndex, i]];

                        int c1 = m_mtMarchTable.cornerIndexAFromEdge[m_mtMarchTable.triTable[cubeIndex, i + 2]];
                        int c2 = m_mtMarchTable.cornerIndexBFromEdge[m_mtMarchTable.triTable[cubeIndex, i + 2]];

                        // Interpolates the verts
                        Triangle tri;
                        tri.vertexA = InterpolateVerts(new Vector4(wireCube[a1, 0], wireCube[a1, 1], wireCube[a1, 2], wireCube[a1, 3]),
                                                       new Vector4(wireCube[a2, 0], wireCube[a2, 1], wireCube[a2, 2], wireCube[a2, 3]), pMarchingMaster.m_fSurface);
                        tri.vertexB = InterpolateVerts(new Vector4(wireCube[b1, 0], wireCube[b1, 1], wireCube[b1, 2], wireCube[b1, 3]),
                                                       new Vector4(wireCube[b2, 0], wireCube[b2, 1], wireCube[b2, 2], wireCube[b2, 3]), pMarchingMaster.m_fSurface);
                        tri.vertexC = InterpolateVerts(new Vector4(wireCube[c1, 0], wireCube[c1, 1], wireCube[c1, 2], wireCube[c1, 3]),
                                                       new Vector4(wireCube[c2, 0], wireCube[c2, 1], wireCube[c2, 2], wireCube[c2, 3]), pMarchingMaster.m_fSurface);
                        m_lTriangles.Add(tri);
                    }
                }
            }
        }
    }
Example #31
0
 /**
  * Set new enemy's node position
  */
 public void SetNodeOfEnemy(Vector3Int nodePos)
 {
     transform.position = nodePos;
 }
Example #32
0
    /// <summary>
    /// Returns the next position available based on the position given. It looks vertically
    /// </summary>
    /// <returns>
    /// The top position.
    /// </returns>
    /// <param name='position'>
    /// Position.
    /// </param>
    public static Vector3Int GetTopPosition(Vector3 position)
    {
        Vector3Int finalPosition = new Vector3Int (position);
        Level level = Level.Singleton;
        bool occupied = Level.Singleton.ContainsElement (finalPosition);

        if (occupied) {
            while (occupied) {
                finalPosition.y++;
                occupied = level.ContainsElement (finalPosition);
            }
        } else {

            while (!occupied) {
                finalPosition.y--;
                occupied = level.ContainsElement (finalPosition);

                if (finalPosition.y < 0.5) {//TODO:Change floor check
                    break;
                }
            }
            finalPosition.y++;
        }

        return finalPosition;
    }
Example #33
0
    /// <summary>
    /// Changes the tiles sprite to the correct sprites based on the situation
    /// </summary>
    /// <param name="location">The location of this sprite</param>
    /// <param name="tilemap">A reference to the tilemap, that this tile belongs to</param>
    /// <param name="tileData">A reference to the actual object, that this tile belongs to</param>
    public override void GetTileData(Vector3Int location, ITilemap tilemap, ref TileData tileData)
    {
        string composition = string.Empty; //Makes an empty string as compostion, we need this so that we change the sprite

        for (int x = -1; x <= 1; x++)      //Runs through all neighbours
        {
            for (int y = -1; y <= 1; y++)
            {
                if (x != 0 || y != 0) //Makes sure that we aren't checking our self
                {
                    //If the value is a wireTile
                    if (HasWater(tilemap, new Vector3Int(location.x + x, location.y + y, location.z)))
                    {
                        composition += 'W';
                    }
                    else
                    {
                        composition += 'E';
                    }
                }
            }
        }

        //Changes the sprite based on what we see.
        if (composition[1] == 'E' && composition[3] == 'E' && composition[4] == 'E' && composition[6] == 'E')
        {
            tileData.sprite = wireSprites[0];
        }
        else if (composition[1] == 'E' && composition[3] == 'W' && composition[4] == 'E' && composition[6] == 'W')
        {
            tileData.sprite = wireSprites[1];
        }
        else if (composition[1] == 'W' && composition[3] == 'W' && composition[4] == 'E' && composition[6] == 'E')
        {
            tileData.sprite = wireSprites[2];
        }
        else if (composition[1] == 'E' && composition[3] == 'W' && composition[4] == 'W' && composition[6] == 'W')
        {
            tileData.sprite = wireSprites[3];
        }
        else if (composition[1] == 'W' && composition[3] == 'W' && composition[4] == 'W' && composition[6] == 'E')
        {
            tileData.sprite = wireSprites[4];
        }
        else if (composition[1] == 'W' && composition[3] == 'W' && composition[4] == 'E' && composition[6] == 'W')
        {
            tileData.sprite = wireSprites[5];
        }
        else if (composition[1] == 'E' && composition[3] == 'E' && composition[4] == 'W' && composition[6] == 'W')
        {
            tileData.sprite = wireSprites[6];
        }
        else if (composition[1] == 'W' && composition[3] == 'E' && composition[4] == 'W' && composition[6] == 'W')
        {
            tileData.sprite = wireSprites[7];
        }
        else if (composition[1] == 'W' && composition[3] == 'E' && composition[4] == 'W' && composition[6] == 'E')
        {
            tileData.sprite = wireSprites[8];
        }
        else if (composition[1] == 'W' && composition[3] == 'E' && composition[4] == 'E' && composition[6] == 'E')
        {
            tileData.sprite = wireSprites[9];
        }
        else if (composition[1] == 'E' && composition[3] == 'E' && composition[4] == 'E' && composition[6] == 'W')
        {
            tileData.sprite = wireSprites[10];
        }
        else if (composition[1] == 'W' && composition[3] == 'E' && composition[4] == 'E' && composition[6] == 'W')
        {
            tileData.sprite = wireSprites[11];
        }
        else if (composition[1] == 'E' && composition[4] == 'W' && composition[3] == 'W' && composition[6] == 'E')
        {
            tileData.sprite = wireSprites[12];
        }
        else if (composition[1] == 'E' && composition[3] == 'E' && composition[6] == 'E' && composition[4] == 'W')
        {
            tileData.sprite = wireSprites[13];
        }
        else if (composition[1] == 'E' && composition[3] == 'W' && composition[4] == 'E' && composition[6] == 'E')
        {
            tileData.sprite = wireSprites[14];
        }
        else if (composition[1] == 'W' && composition[3] == 'W' && composition[4] == 'W' && composition[6] == 'W')
        {
            tileData.sprite = wireSprites[15];
        }
    }
Example #34
0
 private bool HasWater(ITilemap tilemap, Vector3Int position)
 {
     return(tilemap.GetTile(position) == this);
 }
Example #35
0
 public void UnderfloorUpdateTile(Vector3Int cellPosition, LayerTile layerTile)
 {
     RpcUpdateTile(cellPosition, layerTile.TileType, layerTile.name);
     AddToChangeList(cellPosition, layerTile);
 }
Example #36
0
 public Command(Cube cube, Vector3Int endPosition)
 {
     this.cube = cube;
     this.endPosition = endPosition;
 }
Example #37
0
    private void InternalRemoveTile(Vector3 position, LayerType layerType, bool removeAll)
    {
        Vector3Int p = position.RoundToInt();

        metaTileMap.RemoveTile(p, layerType, removeAll);
    }
Example #38
0
 /// <summary>
 /// Gets a block by given world position.
 /// </summary>
 /// <param name="position">Point/block position.</param>
 /// <returns>Copy of <see cref="Block"/></returns>
 /// <remarks>As <see cref="Block"/> is a struct, the returned block will be a copy of original one.</remarks>        /// <remarks>This method will not check if given point/block coordinates are in chunk-cache's bounds. If you need a reliable & safe way, use <see cref="BlockAt"/> instead.</remarks>
 public static Block FastBlockAt(Vector3Int position)
 {
     return FastBlockAt(position.X, position.Y, position.Z);
 }
Example #39
0
 private bool IsDifferent(Vector3Int position, LayerTile layerTile)
 {
     return(metaTileMap.GetTile(position, layerTile.LayerType) != layerTile);
 }
Example #40
0
 /// <summary>
 /// Make the cube, with position currentPosition, fall.
 /// </summary>
 /// <param name='currentPosition'>
 /// Last.
 /// </param>
 public virtual void Gravity(Vector3Int currentPosition)
 {
     Level.Singleton.RemoveEntity(currentPosition);
     if(CubeHelper.IsFree(new Vector3Int( currentPosition.ToVector3 +Vector3.down)) && currentPosition.y > 1){
         currentPosition.y = currentPosition.y-1;
         Level.Singleton.AddEntity (this,currentPosition);
         Gravity(currentPosition);
     }else{
         Level.Singleton.AddEntity(this,currentPosition);
         CubeAnimations.AnimateMove (gameObject, Vector3.down, currentPosition.ToVector3);
     }
 }
Example #41
0
 public static Vector3Int SignedRound(Vector3 v, Vector3Int sign)
     => new Vector3Int(SignedRound(v.x, sign.x), SignedRound(v.y, sign.y), SignedRound(v.z, sign.z));
Example #42
0
    void ApplyLevel(Level level)
    {
        // Elements
        Dictionary <GameObject, int> elementsToLink = new Dictionary <GameObject, int>();

        for (int i = 0; i < level.levelElements.Count; ++i)
        {
            ElementData ED  = level.levelElements[i];
            Vector3     pos = new Vector3(ED.posX, ED.posY, ED.posZ);
            GameObject  go  = null;

            switch (ED.type)
            {
            case (int)PuzzleElementPlaceHolder.PuzzleElementType.Puzzle:
                go = Instantiate(puzzlePH, pos, puzzlePH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.Player:
                go = Instantiate(playerPH, pos, playerPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.PlatformBox:
                go = Instantiate(platformBoxPH, pos, platformBoxPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.PlatformCircle:
                go = Instantiate(platformCirclePH, pos, platformCirclePH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.Doors:
                go = Instantiate(doorsPH, pos, doorsPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.MovingBox:
                go = Instantiate(movingBoxPH, pos, movingBoxPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.VerticalLeftDoors:
                go = Instantiate(VLDoorsPH, pos, VLDoorsPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.VerticalRightDoors:
                go = Instantiate(VRDoorsPH, pos, VRDoorsPH.transform.rotation, mainElementsEditor);
                break;
            }

            if (go)
            {
                go.GetComponent <PuzzleElementPlaceHolder>().ChangeState(PuzzleElementPlaceHolder.States.InLevel);
            }

            LinkElementPlaceholder LEP = go.GetComponent <LinkElementPlaceholder>();
            if (LEP)
            {
                var linkingObjects = PuzzleEditorController.instance.linkingObjects;
                if (!linkingObjects.ContainsKey(go))
                {
                    linkingObjects.Add(go, LEP.type);
                }

                if (ED.elementLinkedPos != -1)
                {
                    foreach (KeyValuePair <GameObject, int> previousElement in elementsToLink)
                    {
                        if (i == previousElement.Value)
                        {
                            previousElement.Key.GetComponent <LinkElementPlaceholder>().elementLinked = go;
                            LEP.elementLinked = previousElement.Key;

                            elementsToLink.Remove(previousElement.Key);
                            break;
                        }
                    }

                    if (!LEP.elementLinked)
                    {
                        elementsToLink.Add(go, ED.elementLinkedPos);
                    }
                }
            }
        }

        // Tiles
        AllTiles allTiles = PuzzleEditorController.instance.allTiles;

        PuzzleEditorController.instance.SetSize(level.size);
        SetCameraSize(level.size);

        for (int i = 0; i < level.groundTiles.Count; ++i)
        {
            TileData   TD  = level.groundTiles[i];
            Vector3Int pos = new Vector3Int(TD.posX, TD.posY, TD.posZ);
            PuzzleEditorController.instance.baseTM.SetTile(pos, GetTileFromInt(TD.id, allTiles));
        }

        for (int i = 0; i < level.collidableTiles.Count; ++i)
        {
            TileData   TD  = level.collidableTiles[i];
            Vector3Int pos = new Vector3Int(TD.posX, TD.posY, TD.posZ);
            PuzzleEditorController.instance.collidable.SetTile(pos, GetTileFromInt(TD.id, allTiles));
        }

        levelName.text        = level.name;
        levelDescription.text = level.description;
        ApplyLevelInfo(level.name, level.creatorName, level.description);
    }
Example #43
0
 public static bool Contains(this Vector3Int size, Vector3Int pos)
     => pos.x >= 0 && pos.x < size.x && pos.y >= 0 && pos.y < size.y && pos.z >= 0 && pos.z < size.z; 
Example #44
0
 public BoardMovementState(TileElement _tileElement, Vector3Int _oldPos)
 {
     tileElement = _tileElement;
     oldPos      = _oldPos;
 }
Example #45
0
 public static Vector3 ToVector3(this Vector3Int v)
     => v;
        private void AddGroundTile(int x, int y)
        {
            var position = new Vector3Int(x, y, 0);

            groundMap.SetTile(position, tileSet.LevelFloors[0]);
        }
Example #47
0
    private bool FindTopPosition(float x, float z,out Vector3Int finalpos)
    {
        if(x < 0 || x > 10 || z < 0 || z > 10 ){
            finalpos = null;
            return false;
        }

        float y = transform.position.y;
        if(!CubeHelper.IsFree(new Vector3Int(new Vector3(x,y,z)))){
            finalpos = null;
            return false;
        }
        Level instance = Level.Singleton;
        if(!CubeHelper.IsFree(new Vector3Int(new Vector3(x,y,z)+Vector3.up))&&instance.getEntity(new Vector3(x,y,z)+Vector3.up).GetComponent<MagneticTerrain>()!=null){
            finalpos = new Vector3Int(new Vector3(x,y,z));
            magneticMove = true;
            return true;
        }
        while (y > 0){
            Vector3 position = new Vector3(x,y,z);
            if((!CubeHelper.IsFree(new Vector3Int(position+Vector3.forward)) && instance.getEntity(position+Vector3.forward).GetComponent<MagneticTerrain>()!=null)||
                (!CubeHelper.IsFree(new Vector3Int(position+Vector3.back)) && instance.getEntity(position+Vector3.back).GetComponent<MagneticTerrain>()!=null)||
                (!CubeHelper.IsFree(new Vector3Int(position+Vector3.right)) && instance.getEntity(position+Vector3.right).GetComponent<MagneticTerrain>()!=null)||
                (!CubeHelper.IsFree(new Vector3Int(position+Vector3.left)) && instance.getEntity(position+Vector3.left).GetComponent<MagneticTerrain>()!=null)||
                (!CubeHelper.IsFree(new Vector3Int(position+Vector3.down)))||
                (y==1)){
                if(CubeHelper.IsFree(new Vector3Int(position+Vector3.down))&&y>1){
                    magneticMove = true;
                }
                finalpos = new Vector3Int(position);
                return true;
            }
            y--;
        }
        finalpos = null;
        return false;
    }
    public void SetGreenTileData(Vector3 position)
    {
        Vector3Int tilePos = tilemap.WorldToCell(position);

        tilemap.SetTile(tilePos, greenTile);
    }
Example #49
0
 public static bool IsFree(Vector3Int position)
 {
     return !Level.Singleton.ContainsElement(position);
 }
Example #50
0
    //TODO
    //Inserts a GameObject into the bucket(s) which its AABB overlaps. Copies of objects whose AABB overlaps more than one cell will
    //be added to all overlapping cells. This allows big objects to be spatially represented more accurately, but means the dictionary may contain
    //duplicate objects - use GetByRadiusNoDups if you are doing spatial checking on a dictionary containing objects added by AABB and do not want duplicates

    /*
     * public void AddByAABB(GameObject o)
     * {
     *
     * }
     */

    //returns a list of all objects in cells[key], or empty list if key isn't in the dictionary
    public List <GameObject> Get(Vector3Int key)
    {
        return(cells.ContainsKey(key) ? cells[key].GetObjs() : new List <GameObject>());
    }
Example #51
0
        public void ApplyEffect(GameManager gm, UnitController user, UnitController guyHit, Vector3Int targetLocation)
        {
            if (guyHit != null)
            {
                guyHit.TakeDamage(Damage, DamageType);
            }

            foreach (var se in SpecialEffects)
            {
                se.ApplyEffect(gm, user, guyHit, targetLocation);
            }
        }
Example #52
0
 public LoadingZone(Vector3Int position, string instanceJSONFileName, Vector3Int spawnLocation)
 {
     this.position             = position;
     this.instanceJSONFileName = instanceJSONFileName;
     this.spawnLocation        = spawnLocation;
 }
 public override void NotifyUnpressed(Vector3Int position)
 {
 }
Example #54
0
 internal void ApplyTileEffect(GameManager gm, UnitController user, DungeonTile tile, Vector3Int target)
 {
     //TODO: melting and shit, tile effects
 }
Example #55
0
 private IEnumerator AddVoxelAnimationCor(Vector3Int pos, Transform animTrans, Action finishCallback)
 {
     while (animTrans.localScale.x < .98f)
     {
         animTrans.GetComponent<MeshRenderer>().enabled = true;
         animTrans.GetComponent<MeshRenderer>().material.shader = Shader.Find("Voxel");
         animTrans.localScale = Vector3.Lerp(animTrans.localScale, Vector3.one, .1f);
         animTrans.GetComponent<BoxCollider>().size = new Vector3(1 / animTrans.localScale.x,
             1 / animTrans.localScale.y, 1 / animTrans.localScale.z);
         yield return null;
     }
     animTrans.GetComponent<MeshRenderer>().enabled = false;
     if (finishCallback != null)
     {
         finishCallback();
     }
 }
Example #56
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> splits)
        {
            if (!chat.Trim().ToLower().StartsWith("//wall") && !chat.Trim().ToLower().StartsWith("//walls"))
            {
                return(false);
            }

            if (!CommandHelper.CheckCommand(player))
            {
                return(true);
            }

            if (0 >= splits.Count)
            {
                Chat.Send(player, "<color=orange>Wrong Arguments</color>");
                return(true);
            }

            if (!CommandHelper.CheckLimit(player))
            {
                return(true);
            }

            if (!CommandHelper.GetBlockIndex(player, splits[1], out ushort blockIndex))
            {
                return(true);
            }

            ushort inner = BlockTypes.BuiltinBlocks.Indices.air;

            if (3 <= splits.Count)
            {
                if (!CommandHelper.GetBlockIndex(player, splits[2], out inner))
                {
                    return(true);
                }
            }

            AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

            Vector3Int start = wand.area.corner1;
            Vector3Int end   = wand.area.corner2;

            for (int x = end.x; x >= start.x; x--)
            {
                for (int y = end.y; y >= start.y; y--)
                {
                    for (int z = end.z; z >= start.z; z--)
                    {
                        if (x == start.x || x == end.x || z == start.z || z == end.z)
                        {
                            Vector3Int newPos = new Vector3Int(x, y, z);
                            if (!World.TryGetTypeAt(newPos, out ushort actualType) || actualType != blockIndex)
                            {
                                AdvancedWand.AddAction(newPos, blockIndex, player);
                            }
                        }
                        else if (inner != BlockTypes.BuiltinBlocks.Indices.air)
                        {
                            Vector3Int newPos = new Vector3Int(x, y, z);
                            if (!World.TryGetTypeAt(newPos, out ushort actualType) || actualType != blockIndex)
                            {
                                AdvancedWand.AddAction(newPos, inner, player);
                            }
                        }
                    }
                }
            }

            Chat.Send(player, string.Format("<color=lime>Wall: {0} {1}</color>", splits[1], inner));

            return(true);
        }
Example #57
0
 /// <summary>
 /// Sets a block by given world position.
 /// </summary>
 /// <param name="position">Point/block position.</param>
 /// <returns>Copy of <see cref="Block"/></returns>
 /// <param name="block">Block to set.</param>
 public static void SetBlockAt(Vector3Int position, Block block)
 {
     SetBlockAt(position.X, position.Y, position.Z, block);
 }
Example #58
0
 void Start()
 {
     position = Vector3Int.FloorToInt(transform.position);
     anim     = GetComponent <Animator>();
 }
Example #59
0
 /// <summary>
 /// Moves Cube to the direction .
 /// </summary>
 /// <param name='nextPosition'>
 /// Next position.	/// </param>
 public virtual void MoveTo(Vector3Int nextPosition)
 {
     if (!Level.Singleton.ContainsElement (nextPosition)) {
         Level.Singleton.RemoveEntity (new Vector3Int (transform.position));
         Level.Singleton.AddEntity (this, nextPosition);
         Level.Singleton.MoveCube(transform.position,nextPosition.ToVector3);
         CubeAnimations.AnimateMove (gameObject, Vector3.down, nextPosition.ToVector3);
     }
 }
Example #60
0
 public override bool IsPassableFromOutside(Vector3Int from, bool isServer, GameObject context = null)
 {
     return(IsPassable(isServer));
 }