예제 #1
0
    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());
    }
 private bool isAvailable(Vector3 direction)
 {
     if (PositionOutOfLimits(direction))
     {
         return(false);
     }
     return(CubeHelper.IsFree(new Vector3Int(Position + direction)));
 }
예제 #3
0
 public void Duplicate(Vector3 newPosition)
 {
     if (duplicateTimes > 0 && CubeHelper.IsFree(transform.position + Vector3.up))
     {
         GameObject newClone = (GameObject)Instantiate(clone, newPosition, transform.rotation);
         CubeAnimations.AnimateDuplication(newClone);
         EndExecution();
         duplicateTimes--;
     }
 }
예제 #4
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);
     }
 }
예제 #5
0
    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);
    }
예제 #6
0
    private Vector3[] GetAvaiblePositionsRelatedTo(Vector3 direction)
    {
        List <Vector3> availablePositions = new List <Vector3>();

        if (IsWalkable(CubeHelper.GetEntityInPosition(transform.position + direction)))
        {
            Vector3 restComponents = Vector3.one - new Vector3(direction.normalized.x, direction.normalized.y, direction.normalized.z);
            if (restComponents.x == 1)
            {
                if (CubeHelper.IsFree(transform.position + direction + Vector3.right))
                {
                    availablePositions.Add(transform.position + direction + Vector3.right);
                }
                if (CubeHelper.IsFree(transform.position + direction + Vector3.left))
                {
                    availablePositions.Add(transform.position + direction + Vector3.left);
                }
            }
            if (restComponents.y == 1)
            {
                if (CubeHelper.IsFree(transform.position + direction + Vector3.up))
                {
                    availablePositions.Add(transform.position + direction + Vector3.up);
                }
                if (CubeHelper.IsFree(transform.position + direction + Vector3.down))
                {
                    availablePositions.Add(transform.position + direction + Vector3.down);
                }
            }
            if (restComponents.z == 1)
            {
                if (CubeHelper.IsFree(transform.position + direction + Vector3.forward))
                {
                    availablePositions.Add(transform.position + direction + Vector3.forward);
                }
                if (CubeHelper.IsFree(transform.position + direction + Vector3.back))
                {
                    availablePositions.Add(transform.position + direction + Vector3.back);
                }
            }
        }
        return(availablePositions.ToArray());
    }
예제 #7
0
    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);
    }
예제 #8
0
 public void CloudFall()
 {
     if (transform.position.y > 1 && Level.Singleton.getEntity(transform.position + Vector3.down) is CloudCube)
     {
         CloudCube cl = (CloudCube)Level.Singleton.getEntity(transform.position + Vector3.down);
         if (!CubeHelper.IsFree(new Vector3Int(cl.transform.position + Vector3.down)) || cl.transform.position.y == 1)
         {
             Level.Singleton.RemoveEntity(cl.transform.position);
             Level.Singleton.RemoveEntity(cl.transform.position + Vector3.up);
             Level.Singleton.AddEntity(cl, cl.transform.position + Vector3.up);
             Level.Singleton.AddEntity(this, cl.transform.position);
             Vector3 aux = cl.transform.position;
             this.cl = cl;
             CubeAnimations.AnimateMove(gameObject, Vector3.down, aux);
             cl.renderer.enabled = false;
             //CubeControllerInput cc = cl.gameObject.GetComponent<CubeControllerInput> ();
             //cc.NotifyMoveTO (new Move (cl, new Vector3Int( cl.transform.position + Vector3.up)));
             //TODO cambiar transform por animacion
             //CubeAnimations.AnimateMove (cl.gameObject, Vector3.down, aux + Vector3.up);
             //this.transform.position = aux;
             cl.transform.position = aux + Vector3.up;
         }
         else if (CubeHelper.IsFree(new Vector3Int(cl.transform.position + Vector3.down)))
         {
             Level.Singleton.RemoveEntity(transform.position);
             this.cl             = cl;
             cl.renderer.enabled = false;
             Debug.Log(transform.position + Vector3.down + Vector3.down);
             //transform.position = cl.transform.position + Vector3.down;
             Level.Singleton.AddEntity(this, transform.position + Vector3.down + Vector3.down);
             //CubeAnimations.AnimateMove (gameObject, Vector3.down, cl.transform.position + Vector3.down);
             Gravity(new Vector3Int(transform.position + Vector3.down + Vector3.down));
             //CloudFall();
         }
     }
 }
예제 #9
0
    void Update()
    {
        ray = new Ray(transform.position, transform.forward);
        if (!isAlive || lasersHitting > 0)
        {
            float distance = Mathf.Abs(Level.Dimension - transform.position.x);
            distance = Mathf.Abs(Vector3.Dot(transform.position, transform.forward) - Level.Dimension);
            if (distance > 10)
            {
                distance -= (Level.Dimension);
            }

            RaycastHit[] hits = Physics.RaycastAll(ray, distance);

            RaycastHit hit       = new RaycastHit();
            bool       isRealHit = false;
            if (hits.Length > 0 && hits[0].transform.tag != "Selector")
            {
                hit       = hits[0];
                isRealHit = true;
            }
            else
            {
                if (hits.Length > 1 && hits[1].transform.tag != "Selector")
                {
                    hit       = hits[1];
                    isRealHit = true;
                }
            }

            /*Debug.Log(isAlive);
             * foreach(RaycastHit h in hits){
             *  Debug.Log(CubeHelper.GetEntityInPosition(h.transform.position));
             * }*/

            if (isRealHit)
            {
                hitPosition = hit.transform.position;
                renderer.SetPosition(1, hitPosition);
                if (!CubeHelper.IsFree(hitPosition) && CubeHelper.GetEntityInPosition(hitPosition) is ILaserReactive)
                {
                    ILaserReactive newHit = (ILaserReactive)CubeHelper.GetEntityInPosition(hitPosition);
                    if (!newHit.Equals(reactabletHit))
                    {
                        newHit.HitByLaser(this.transform.position);
                        reactabletHit = newHit;
                    }
                }
                else
                {
                    if (reactabletHit != null)
                    {
                        reactabletHit.StopHit(this.transform.position);
                        reactabletHit = null;
                    }
                }
            }
            else
            {
                if (reactabletHit != null)
                {
                    reactabletHit.StopHit(this.transform.position);
                    reactabletHit = null;
                }
                renderer.SetPosition(1, transform.position + transform.forward * distance);
            }
        }
        else
        {
            renderer.SetPosition(1, this.transform.position);
        }
    }
예제 #10
0
 public override bool CheckPressed()
 {
     return(!CubeHelper.IsFree(transform.position + Vector3.up));
 }