Example #1
0
    private void talk_to_character()
    {
        Vector2 pos  = new Vector2(0, 0);
        Vector2 size = new Vector2(0, 0);

        player.get_map_character_position(ref pos, ref size);

        sees_player = false;
        Vector2 seeing_point = new Vector2(x, y + 2 * RADIUS_Y);          // looking up

        if (spritesheet_square_y == 1)
        {
            seeing_point = new Vector2(x, y - 2 * RADIUS_Y);                                    // looking down
        }
        if (spritesheet_square_y == 2)
        {
            seeing_point = new Vector2(x - 2 * RADIUS_X, y);                                    // looking left
        }
        if (spritesheet_square_y == 3)
        {
            seeing_point = new Vector2(x + 2 * RADIUS_X, y);                // looking right
        }
        if (spritesheet_square_y == 0 || spritesheet_square_y == 1)         // looking up or down
        {
            if (pos.x + size.x > seeing_point.x - 0.5f &&
                pos.x - size.x < seeing_point.x + 0.5f &&
                pos.y + size.y > seeing_point.y &&
                pos.y - size.y < seeing_point.y)
            {
                sees_player = true;
            }
        }
        if (spritesheet_square_y == 2 || spritesheet_square_y == 3)         // looking left or right
        {
            if (pos.x + size.x > seeing_point.x &&
                pos.x - size.x < seeing_point.x &&
                pos.y + size.y > seeing_point.y - 0.5f &&
                pos.y - size.y < seeing_point.y + 0.5f)
            {
                sees_player = true;
            }
        }



        talk_timer += Time.deltaTime;
        if (sees_player && talk_id == -1 && talk_timer > 0.1f)
        {
            Debug.Log("REPLIIKKI!!! character pos=" + pos + "   size=" + size + "  sees=" + sees_player);

            if (sentence == 0)
            {
                talk_id = MAP_MESSAGES.SHOW_MESSAGE("HEI OLEN KYLAN", "AINOA IDIOOTTI.", "TAI ONHAN TOI", "NORSUKIN AIKA TYHMEA.");
            }
            if (sentence == 1)
            {
                talk_id = MAP_MESSAGES.SHOW_MESSAGE("POIS EESTA !!!!!!", "!!!!!!!!!!!");
            }
            if (sentence == 2)
            {
                talk_id = MAP_MESSAGES.SHOW_MESSAGE("GOOD AFTERNOON. I AM", "PLEASE TO MEET YOU", "STRANGE GREEN MAN.");
            }
            if (sentence == 3)
            {
                talk_id = MAP_MESSAGES.SHOW_MESSAGE("OSAAN SANOA", "MONTA ERI ASIAA", "KOSKA OLEN AIKA", "SMART.");
            }

            sentence++;
            if (sentence > 3)
            {
                sentence = 0;
            }
            talk_timer = 0.0f;
            spritesheet_animation_timer = 0.0f;
        }
        if (!sees_player && talk_id != -1 && talk_timer > 0.5f)
        {
            MAP_MESSAGES.HIDE_MESSAGE(talk_id);
            talk_id    = -1;
            talk_timer = 0.0f;
        }
    }