Ejemplo n.º 1
0
 public void Execute(List <Entity> entities)
 {
     foreach (var entity in entities)
     {
         var transform = entity.view.Value.transform;
         transform.rotation = Quaternion.LookRotation(LocalDirections.ToDirection(entity.rotation.Value).ToV3(), Vector3.up);
     }
 }
Ejemplo n.º 2
0
    public Vector3 AxisPlane()
    {
        LocalDirections ld = new LocalDirections(this.transform);

        axisPlane   = ld.N + ld.E;
        axisPlane.x = Mathf.Abs(axisPlane.x);
        axisPlane.y = Mathf.Abs(axisPlane.y);
        axisPlane.z = Mathf.Abs(axisPlane.z);
        return(axisPlane);
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        LocalDirections ld = new LocalDirections(this.transform);

        Debug.DrawRay(ld.trans.position, ld.N * 20, Color.yellow);
        Debug.DrawRay(ld.trans.position, ld.NE * 20, Color.yellow);
        Debug.DrawRay(ld.trans.position, ld.E * 20, Color.yellow);
        Debug.DrawRay(ld.trans.position, ld.SE * 20, Color.yellow);
        Debug.DrawRay(ld.trans.position, ld.S * 20, Color.yellow);
        Debug.DrawRay(ld.trans.position, ld.SW * 20, Color.yellow);
        Debug.DrawRay(ld.trans.position, ld.W * 20, Color.yellow);
        Debug.DrawRay(ld.trans.position, ld.NW * 20, Color.yellow);

        //Debug.Log("Transform: " + transform.forward);
    }
Ejemplo n.º 4
0
    Vector3 GetDirection(LocalDirections axis)
    {
        switch (axis)
        {
        case LocalDirections.XAxis:
            return(Vector3.right);

        case LocalDirections.YAxis:
            return(Vector3.up);

        case LocalDirections.ZAxis:
            return(Vector3.forward);

        default:
            return(Vector3.zero);
        }
    }
Ejemplo n.º 5
0
    public void UpdateAxis()
    {
        Debug.Log("Updating Axis");

        axisPlane = AxisPlane();

        cubes.Clear();

        RaycastHit      hit;
        LocalDirections ld = new LocalDirections(this.transform);

        foreach (Vector3 dir in ld.AllDirections())
        {
            if (Physics.Raycast(ld.trans.position, dir, out hit, 20f))
            {
                Cube cube;
                if (hit.transform.gameObject.TryGetComponent <Cube>(out cube))
                {
                    if (!cubes.Contains(hit.transform.gameObject))
                    {
                        cubes.Add(hit.transform.gameObject);
                    }

                    cube.AddAxis(this);
                }
                else
                {
                    Debug.Log("Object missing Cube Script");
                }
            }
            else
            {
                Debug.Log("Miss");
            }
        }
    }
Ejemplo n.º 6
0
        bool MoveGrowSnake(LocalDirections direction)
        {
            //snake slowly dies of hunger each turn
            hunger--;

            Vector2 pos;
            switch (direction)
            {
                case LocalDirections.L:
                    facing = Leftify(facing);
                    break;
                case LocalDirections.R:
                    facing = Rightify(facing);
                    break;
            }

            pos = Vector2.Add(snake[0], facing);
            Vector2 last = snake[snake.Count - 1];

            for (int i = snake.Count - 1; i > 0 ; i--)
            {
                if (i == snake.Count -1)
                    board[(int)snake[i].X, (int)snake[i].Y] = Entity.none;
                board[(int)snake[i-1].X, (int)snake[i-1].Y] = Entity.snake;
                snake[i] = snake[i - 1];
            }

            if (board[(int)pos.X, (int)pos.Y] == Entity.apple || snake_length_count > 1)
            {
                snake.Add(last);
                board[(int)last.X, (int)last.Y] = Entity.snake;

                if (board[(int)pos.X, (int)pos.Y] == Entity.apple)
                {
                    AddApple();
                    score += 100;
                    hunger = ttl;
                }

                if (snake_length_count > 1)
                    snake_length_count--;
            }

            snake[0] = pos;

            if ((board[(int)pos.X, (int)pos.Y] == Entity.snake) || (board[(int)pos.X, (int)pos.Y] == Entity.wall) || hunger == 0)
            {
                board[(int)pos.X, (int)pos.Y] = Entity.dead;
                return false;
            }
            else
            {
                board[(int)pos.X, (int)pos.Y] = Entity.snake;
                return true;
            }
        }