Ejemplo n.º 1
0
    public override void OnUpdate(float time_delta_fraction)
    {
        rb.velocity = direction * g.speed_max;

        var v = 0.1f * time_delta_fraction * rb.velocity.magnitude / g.speed_max;

        current_frame_index += v;
        while (current_frame_index > animation.Length)
        {
            current_frame_index -= animation.Length;
        }
        renderer.sprite = animation[(int)current_frame_index];
        nextCell        = new Vector3((int)g.transform.position.x + (direction.x), (int)g.transform.position.y + (direction.y), 0);
        if (Tile.Unwalkable(nextCell) || Utils.CollidingWithAnyWall(nextCell))
        {
            state_machine.ChangeState(new StateGoriyaWalk(g, g.GetComponent <SpriteRenderer>()));
        }

        cooldownTimer -= Time.deltaTime;
        if (cooldownTimer <= 0)
        {
            state_machine.ChangeState(new StateGoriyaThrowBoomerang(g));
            cooldownTimer = (Random.value * g.maxWalkTime) + g.minWalkTime;
        }
    }
Ejemplo n.º 2
0
    public StateGoriyaWalk(Goriya _g, SpriteRenderer _renderer) {
        g = _g;
        renderer = _renderer;
        rb = g.GetComponent<Rigidbody>();

        g.GoToMiddleOfTile();
        cooldownTimer = (Random.value * g.maxWalkTime) + g.minWalkTime;

        do {
            direction = Utils.RandomDirection4();
            nextCell = new Vector3((int)g.transform.position.x + (direction.x), (int)g.transform.position.y + (direction.y), 0);
        } while (Tile.Unwalkable(nextCell) || Utils.CollidingWithAnyWall(nextCell));

        if(direction.x == 1) {
            g.current_direction = Direction.EAST;
            animation = g.walkRight;
        }
        else if(direction.x == -1) {
            g.current_direction = Direction.WEST;
            animation = g.walkLeft;
        }
        else if(direction.y == 1) {
            g.current_direction = Direction.NORTH;
            animation = g.walkUp;
        }
        else if(direction.y == -1) {
            g.current_direction = Direction.SOUTH;
            animation = g.walkDown;
        }
    }
Ejemplo n.º 3
0
    public StateGoriyaThrowBoomerang(Goriya _g)
    {
        g = _g;
        g.GetComponent <Rigidbody>().velocity = Vector3.zero;

        weapon_instance = MonoBehaviour.Instantiate(g.goriyaBoomerangPrefab, g.transform.position, Quaternion.identity) as GameObject;
        weapon_instance.GetComponent <GoriyaBoomerang>().g = g;

        Vector3 direction_offset     = Vector3.zero;
        Vector3 direction_eulerangle = Vector3.zero;

        if (g.current_direction == Direction.NORTH)
        {
            direction_offset     = new Vector3(0, 1, 0);
            direction_eulerangle = new Vector3(0, 0, 90);
        }
        else if (g.current_direction == Direction.EAST)
        {
            direction_offset     = new Vector3(1, 0, 0);
            direction_eulerangle = new Vector3(0, 0, 0);
        }
        else if (g.current_direction == Direction.SOUTH)
        {
            direction_offset     = new Vector3(0, -1, 0);
            direction_eulerangle = new Vector3(0, 0, 270);
        }
        else if (g.current_direction == Direction.WEST)
        {
            direction_offset     = new Vector3(-1, 0, 0);
            direction_eulerangle = new Vector3(0, 0, 180);
        }

        weapon_instance.transform.position += direction_offset;
        Quaternion new_weapon_rotation = new Quaternion();

        new_weapon_rotation.eulerAngles    = direction_eulerangle;
        weapon_instance.transform.rotation = new_weapon_rotation;
        weapon_instance.GetComponent <BoxCollider>().transform.rotation = new_weapon_rotation;
    }
Ejemplo n.º 4
0
    public StateGoriyaWalk(Goriya _g, SpriteRenderer _renderer)
    {
        g        = _g;
        renderer = _renderer;
        rb       = g.GetComponent <Rigidbody>();

        g.GoToMiddleOfTile();
        cooldownTimer = (Random.value * g.maxWalkTime) + g.minWalkTime;

        do
        {
            direction = Utils.RandomDirection4();
            nextCell  = new Vector3((int)g.transform.position.x + (direction.x), (int)g.transform.position.y + (direction.y), 0);
        } while (Tile.Unwalkable(nextCell) || Utils.CollidingWithAnyWall(nextCell));

        if (direction.x == 1)
        {
            g.current_direction = Direction.EAST;
            animation           = g.walkRight;
        }
        else if (direction.x == -1)
        {
            g.current_direction = Direction.WEST;
            animation           = g.walkLeft;
        }
        else if (direction.y == 1)
        {
            g.current_direction = Direction.NORTH;
            animation           = g.walkUp;
        }
        else if (direction.y == -1)
        {
            g.current_direction = Direction.SOUTH;
            animation           = g.walkDown;
        }
    }
Ejemplo n.º 5
0
    public StateGoriyaThrowBoomerang(Goriya _g) {
        g = _g;
        g.GetComponent<Rigidbody>().velocity = Vector3.zero;

        weapon_instance = MonoBehaviour.Instantiate(g.goriyaBoomerangPrefab, g.transform.position, Quaternion.identity) as GameObject;
        weapon_instance.GetComponent<GoriyaBoomerang>().g = g;

        Vector3 direction_offset = Vector3.zero;
        Vector3 direction_eulerangle = Vector3.zero;

        if (g.current_direction == Direction.NORTH) {
            direction_offset = new Vector3(0, 1, 0);
            direction_eulerangle = new Vector3(0, 0, 90);
        } else if (g.current_direction == Direction.EAST) {
            direction_offset = new Vector3(1, 0, 0);
            direction_eulerangle = new Vector3(0, 0, 0);
        } else if (g.current_direction == Direction.SOUTH) {
            direction_offset = new Vector3(0, -1, 0);
            direction_eulerangle = new Vector3(0, 0, 270);
        } else if (g.current_direction == Direction.WEST) {
            direction_offset = new Vector3(-1, 0, 0);
            direction_eulerangle = new Vector3(0, 0, 180);
        }

        weapon_instance.transform.position += direction_offset;
        Quaternion new_weapon_rotation = new Quaternion();
        new_weapon_rotation.eulerAngles = direction_eulerangle;
        weapon_instance.transform.rotation = new_weapon_rotation;
        weapon_instance.GetComponent<BoxCollider>().transform.rotation = new_weapon_rotation;
    }